Unity创建asset文件的扩展编辑器


 1 using UnityEngine;
 2 using UnityEditor;
 3 using System.IO;
 4 
 5 public class CreateAsset : EditorWindow
 6 {
 7     private string mConfigName = "TestAsset";
 8     private string mAssetPath = "Assets/Config/";
 9     private string mAssetName = "MyAsset";
10 
11     [MenuItem("Tools/CreateAsset")]
12     public static void GenAsset()
13     {
14         GetWindow(typeof(CreateAsset));
15     }
16 
17     private void OnGUI()
18     {
19         mConfigName = EditorGUILayout.TextField("Asset类名:", mConfigName);
20         mAssetPath = EditorGUILayout.TextField("生成Asset路径", mAssetPath);
21         mAssetName = EditorGUILayout.TextField("生成Asset名称", mAssetName);
22         if (GUILayout.Button(new GUIContent("生成Asset")))
23         {
24             if (string.IsNullOrEmpty(mConfigName) || string.IsNullOrEmpty(mAssetPath) || string.IsNullOrEmpty(mAssetName))
25             {
26                 Debug.LogError("Err!");
27                 return;
28             }
29 
30             var newAsset = CreateInstance(mConfigName);
31             string fullPath = mAssetPath + mAssetName + ".asset";
32             AssetDatabase.CreateAsset(newAsset, fullPath);
33             Debug.Log(fullPath);
34             AssetDatabase.SaveAssets();
35             AssetDatabase.Refresh();
36             EditorUtility.FocusProjectWindow();
37             Selection.activeObject = newAsset;
38         }
39     }
40 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM