赞
踩
- public class Window:EditorWindow
- {
- static WindowConfig windowCfg;
- static string applicationPath;
- static string scriptFolderPath;
- static Window window;
- [MenuItem("Tools/Window")]
- static void ShowWindow()
- {
- window =EditorWindow.GetWindow<Window>("Window", true) as Window;
- MonoScript script = MonoScript.FromScriptableObject(window);
- string scriptPath = AssetDatabase.GetAssetPath(script);
- scriptFolderPath = scriptPath.Substring(0, scriptPath.Length - script.name.Length - 4);
- string windowCfgPath = scriptFolderPath + "/windowConfig.asset";
- if (!File.Exists(windowCfgPath))
- {
- windowCfg = WindowConfig.CreateInstance<WindowConfig>();
- AssetDatabase.CreateAsset(windowCfg, windowCfgPath);
- }
- else
- {
- windowCfg = AssetDatabase.LoadAssetAtPath<WindowConfig>(windowCfgPath);
- }
- applicationPath = Application.dataPath;
-
- window.Show();
- }
- }
Note:继承自ScriptableObject的类必须有一个与它同名的脚本,否者Unity重启之后.asset文件将会报错。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。