BuildConfigInspector.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using UnityEngine;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. namespace XRTool.Util
  6. {
  7. [InitializeOnLoad]
  8. [CustomEditor(typeof(BuildConfig))]
  9. public class BuildConfigInspector : Editor
  10. {
  11. //[MenuItem("GameObject/XR/XRCompents", priority = 0)]
  12. //static void CreateXRCompents()
  13. //{
  14. // CreateXRSession();
  15. // CreateXRNode();
  16. //}
  17. //[MenuItem("GameObject/XR/GameSession", priority = 0)]
  18. //static void CreateXRSession()
  19. //{
  20. // var obj = Instantiate(Resources.Load<GameSession>(typeof(GameSession).Name));
  21. // obj.name = (typeof(GameSession).Name);
  22. //}
  23. //[MenuItem("GameObject/XR/GameNode", priority = 0)]
  24. //static void CreateXRNode()
  25. //{
  26. // var obj = Instantiate(Resources.Load<GameNode>(typeof(GameNode).Name));
  27. // obj.name = (typeof(GameNode).Name);
  28. //}
  29. /// <summary>
  30. /// 打包模式
  31. /// </summary>
  32. public SerializedProperty buildType;
  33. /// <summary>
  34. /// 资源访问方式
  35. /// </summary>
  36. public SerializedProperty assetsType;
  37. /// <summary>
  38. /// 运行的平台
  39. /// </summary>
  40. public SerializedProperty buildTarget;
  41. /// <summary>
  42. /// 运行的模式
  43. /// </summary>
  44. public SerializedProperty playType;
  45. /// <summary>
  46. /// 发布的平台
  47. /// </summary>
  48. public SerializedProperty buildTargetGroup;
  49. public SerializedProperty languagePath;
  50. public SerializedProperty useHand;
  51. private void OnEnable()
  52. {
  53. buildType = serializedObject.FindProperty("buildType");
  54. assetsType = serializedObject.FindProperty("assetsType");
  55. buildTarget = serializedObject.FindProperty("buildTarget");
  56. playType = serializedObject.FindProperty("playType");
  57. buildTargetGroup = serializedObject.FindProperty("buildTargetGroup");
  58. languagePath = serializedObject.FindProperty("languagePath");
  59. useHand = serializedObject.FindProperty("useHand");
  60. BuildConfig.Instance = target as BuildConfig;
  61. //ReadGameVersion();
  62. }
  63. ///// <summary>
  64. ///// 获取APP版本号,如果不存在,则从1.0.0.0开始计时
  65. ///// </summary>
  66. //public void ReadGameVersion()
  67. //{
  68. // var conf = target as BuildConfig;
  69. // if (conf.version == null || conf.version.version == null)
  70. // {
  71. // conf.UpdateGameVersion();
  72. // }
  73. // conf.version = DataFileUtil.Instance.ReadJsonObjFormEditor("GameData/BuildConf/Version.json", conf.version);
  74. // //if (conf.version != null && conf.version.version != null)
  75. // //{
  76. // // Debug.Log("版本号" + conf.version.version.ToString());
  77. // //}
  78. // PlayerSettings.bundleVersion = conf.version.version.ToString();
  79. //}
  80. public override void OnInspectorGUI()
  81. {
  82. serializedObject.Update();
  83. var conf = target as BuildConfig;
  84. if (conf.buildTarget == BuildTarget.Android)
  85. {
  86. conf.buildTargetGroup = BuildTargetGroup.Android;
  87. }
  88. if (conf.buildTarget == BuildTarget.iOS)
  89. {
  90. conf.buildTargetGroup = BuildTargetGroup.iOS;
  91. }
  92. if (conf.buildTarget == BuildTarget.StandaloneWindows)
  93. {
  94. conf.buildTargetGroup = BuildTargetGroup.Standalone;
  95. }
  96. EditorGUILayout.PropertyField(buildType, new GUIContent("打包模式,默认debug"));
  97. EditorGUILayout.PropertyField(assetsType, new GUIContent("资源访问方式,默认editor"));
  98. EditorGUILayout.PropertyField(buildTarget, new GUIContent("运行的平台,默认pc"));
  99. EditorGUILayout.PropertyField(playType, new GUIContent("运行的模式,默认normal"));
  100. EditorGUILayout.PropertyField(languagePath, new GUIContent("语言包路径"));
  101. EditorGUILayout.PropertyField(useHand, new GUIContent("手势"));
  102. //EditorGUILayout.PropertyField(buildTargetGroup, new GUIContent("发布的平台,默认Standalone"));
  103. conf.otherSymbol = EditorGUILayout.TextField("宏", conf.otherSymbol);
  104. EditorGUILayout.LabelField("Version", PlayerSettings.bundleVersion);
  105. EditorGUILayout.LabelField("发布时间", conf.buildTime);
  106. if (GUILayout.Button("重置版本号", GUILayout.Width(200)))
  107. {
  108. conf.appVersion = BuildDeployWindow.initVersion;
  109. PlayerSettings.bundleVersion = conf.appVersion;
  110. }
  111. serializedObject.ApplyModifiedProperties();
  112. if (GUI.changed)
  113. {
  114. EditorUtility.SetDirty(target);
  115. string lastSym = PlayerSettings.GetScriptingDefineSymbolsForGroup(conf.buildTargetGroup);
  116. ///设置指令用;分割
  117. string symbol = string.Format("buildType_{0};assetsType_{1};buildPlatform_{2};playType_{3}",
  118. conf.buildType, conf.assetsType, conf.buildTarget, conf.playType).ToUpper() + ";" + conf.otherSymbol;
  119. if (symbol != lastSym)
  120. {
  121. Debug.Log(lastSym + "当前宏编译配置" + symbol);
  122. PlayerSettings.SetScriptingDefineSymbolsForGroup(conf.buildTargetGroup, symbol);
  123. }
  124. }
  125. }
  126. }
  127. }