UIKitSetttingData.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /****************************************************************************
  2. * Copyright (c) 2017 magicbell
  3. * Copyright (c) 2018.3 ~ 2021.1 liangxie
  4. *
  5. * http://qframework.io
  6. * https://github.com/liangxiegame/QFramework
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. ****************************************************************************/
  26. using System;
  27. using System.IO;
  28. using UnityEngine;
  29. namespace QFramework
  30. {
  31. using UnityEditor;
  32. [Serializable]
  33. public class UIKitSettingData
  34. {
  35. static string mConfigSavedDir
  36. {
  37. get { return (Application.dataPath + "/QFrameworkData/").CreateDirIfNotExists() + "ProjectConfig/"; }
  38. }
  39. private const string mConfigSavedFileName = "ProjectConfig.json";
  40. public string Namespace;
  41. public string UIScriptDir = "/Scripts/UI";
  42. public string UIPrefabDir = "/Art/UIPrefab";
  43. public string DefaultViewControllerScriptDir = "/Scripts/Game";
  44. public string DefaultViewControllerPrefabDir = "/Art/Prefab";
  45. public bool IsDefaultNamespace
  46. {
  47. get { return Namespace == "QFramework.Example"; }
  48. }
  49. public static string GetScriptsPath()
  50. {
  51. return Load().UIScriptDir;
  52. }
  53. public static string GetProjectNamespace()
  54. {
  55. return Load().Namespace;
  56. }
  57. public static UIKitSettingData Load()
  58. {
  59. mConfigSavedDir.CreateDirIfNotExists();
  60. if (!File.Exists(mConfigSavedDir + mConfigSavedFileName))
  61. {
  62. using (var fileStream = File.Create(mConfigSavedDir + mConfigSavedFileName))
  63. {
  64. fileStream.Close();
  65. }
  66. }
  67. var frameworkConfigData =
  68. JsonUtility.FromJson<UIKitSettingData>(File.ReadAllText(mConfigSavedDir + mConfigSavedFileName));
  69. if (frameworkConfigData == null || string.IsNullOrEmpty(frameworkConfigData.Namespace))
  70. {
  71. frameworkConfigData = new UIKitSettingData {Namespace = "QFramework.Example"};
  72. }
  73. return frameworkConfigData;
  74. }
  75. public void Save()
  76. {
  77. File.WriteAllText(mConfigSavedDir + mConfigSavedFileName,JsonUtility.ToJson(this));
  78. AssetDatabase.Refresh();
  79. }
  80. }
  81. }