当前位置:   article > 正文

Unity 创建EditorWindow时在同级目录下创建.asset配置文件_monoscript.fromscriptableobject

monoscript.fromscriptableobject
  1. public class Window:EditorWindow
  2. {
  3. static WindowConfig windowCfg;
  4. static string applicationPath;
  5. static string scriptFolderPath;
  6. static Window window;
  7. [MenuItem("Tools/Window")]
  8. static void ShowWindow()
  9. {
  10. window =EditorWindow.GetWindow<Window>("Window", true) as Window;
  11. MonoScript script = MonoScript.FromScriptableObject(window);
  12. string scriptPath = AssetDatabase.GetAssetPath(script);
  13. scriptFolderPath = scriptPath.Substring(0, scriptPath.Length - script.name.Length - 4);
  14. string windowCfgPath = scriptFolderPath + "/windowConfig.asset";
  15. if (!File.Exists(windowCfgPath))
  16. {
  17. windowCfg = WindowConfig.CreateInstance<WindowConfig>();
  18. AssetDatabase.CreateAsset(windowCfg, windowCfgPath);
  19. }
  20. else
  21. {
  22. windowCfg = AssetDatabase.LoadAssetAtPath<WindowConfig>(windowCfgPath);
  23. }
  24. applicationPath = Application.dataPath;
  25. window.Show();
  26. }
  27. }

Note:继承自ScriptableObject的类必须有一个与它同名的脚本,否者Unity重启之后.asset文件将会报错。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/81963
推荐阅读
相关标签
  

闽ICP备14008679号