Version: 2021.1
言語: 日本語
public static string ValidateMoveAsset (string oldPath, string newPath);

パラメーター

oldPath アセットが現在ある場所。
newPath アセットの移動先のパス。

戻り値

string アセットが移動できる場合は空の文字列、そうでない場合、エラーメッセージが返されます。

説明

アセットファイルを、あるフォルダーから別のフォルダーに移動可能かどうかをチェックします (実際のファイル移動は行われません)。

すべてのパスは、例えば "Assets/MyTextures/hello.png" のような Project フォルダーに対する相対パスです。

See Also: AssetDatabase.MoveAsset.

using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Move With Validate")] public static void MoveWithValidate() { for (var i = 0; i < 5; i++) { var oldPath = $"Assets/Textures/Building/BuildingTexture{i}.png"; var newPath = $"Assets/Textures/Construction/BuildingTexture{i}.png"; var moveResult = AssetDatabase.ValidateMoveAsset(oldPath, newPath);

if (moveResult == "") AssetDatabase.MoveAsset(oldPath, newPath); else Debug.LogError($"Couldn't move {oldPath} because {moveResult}"); } } }