Version: 2022.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}"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961