public static void drawAssetInfoGUI(Editor editor) { //如果目标对象不是在磁盘中的资源而是场景中的对象,就不进行任何操作 if (!EditorUtility.IsPersistent(editor.target)) { return; } //获得资源所在Mod var ModName = editor.target.GetAssetModNameEditor(); //如果没匹配到,就代表该资源不在某个Mod的Assets文件夹下,忽略 if (ModName == null || !ModsEditor.Exist(ModName)) { return; } AssetInfo ai = ModsEditor.GetAssetInfo(ModName, editor.target.name); //赋值 string newAssetName = EditorGUILayout.TextField("AssetName", ai.AssetName); if (newAssetName != ai.AssetName) { ai.AssetName = newAssetName; AssetDatabase.RenameAsset(AssetDatabase.GetAssetOrScenePath(editor.target), ai.ModName + "." + ai.AssetName); } GUILayout.Label("Tags:"); GUILayout.BeginVertical(); for (int i = 0; i < ai.Tags.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label(ai.Tags[i]); if (GUILayout.Button("Remove")) { ai.Tags.RemoveAt(i); EditorUtility.SetDirty(ModsEditor.GetAssetIndexer(ai.ModName)); AssetDatabase.SaveAssets(); } GUILayout.EndHorizontal(); } if (GUILayout.Button("Add Tag")) { AddTagWindow window = EditorWindow.GetWindow <AddTagWindow>(); window.target = ai; window.Show(); } GUILayout.EndVertical(); }
/// <summary> /// 获得资源的信息(请不要在一个不是Mod资源的对象上调用此函数) /// </summary> public static AssetInfo GetAssetInfoEditor <T>(this T asset) where T : UnityEngine.Object { return(ModsEditor.GetAssetInfo(asset.GetAssetModNameEditor(), asset.GetAssetNameEditor())); }