EnviroBaseInspector.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Linq;
  7. public class EnviroBaseInspector : Editor
  8. {
  9. public SerializedObject serializedObj;
  10. public GUIStyle boxStyle;
  11. public GUIStyle boxStyleModified;
  12. public GUIStyle wrapStyle;
  13. public GUIStyle headerStyle;
  14. public GUIStyle headerStyleMid;
  15. public GUIStyle headerFoldout;
  16. public GUIStyle popUpStyle;
  17. public GUIStyle integrationBox;
  18. public GUIStyle helpButton;
  19. public bool showHelpBox;
  20. public Color baseModuleColor = new Color(0.0f,0.0f,0.5f,1f);
  21. public Color categoryModuleColor = new Color(0.5f,0.5f,0.0f,1f);
  22. public Color thirdPartyModuleColor = new Color(0.0f,0.5f,0.5f,1f);
  23. public void SetupGUIStyles ()
  24. {
  25. if (boxStyle == null)
  26. {
  27. boxStyle = new GUIStyle(GUI.skin.box);
  28. boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
  29. boxStyle.fontStyle = FontStyle.Bold;
  30. boxStyle.alignment = TextAnchor.UpperLeft;
  31. }
  32. if (boxStyleModified == null)
  33. {
  34. boxStyleModified = new GUIStyle(EditorStyles.helpBox);
  35. boxStyleModified.normal.textColor = GUI.skin.label.normal.textColor;
  36. boxStyleModified.fontStyle = FontStyle.Bold;
  37. boxStyleModified.fontSize = 11;
  38. boxStyleModified.alignment = TextAnchor.UpperLeft;
  39. }
  40. if (integrationBox == null)
  41. {
  42. integrationBox = new GUIStyle(EditorStyles.helpBox);
  43. integrationBox.fontStyle = FontStyle.Bold;
  44. integrationBox.fontSize = 11;
  45. }
  46. if (wrapStyle == null)
  47. {
  48. wrapStyle = new GUIStyle(GUI.skin.label);
  49. wrapStyle.fontStyle = FontStyle.Normal;
  50. wrapStyle.wordWrap = true;
  51. }
  52. if (headerStyle == null)
  53. {
  54. headerStyle = new GUIStyle(GUI.skin.label);
  55. headerStyle.fontStyle = FontStyle.Bold;
  56. headerStyle.alignment = TextAnchor.UpperLeft;
  57. }
  58. if (headerStyleMid == null)
  59. {
  60. headerStyleMid = new GUIStyle(GUI.skin.label);
  61. headerStyleMid.fontStyle = FontStyle.Bold;
  62. headerStyleMid.alignment = TextAnchor.MiddleCenter;
  63. }
  64. if (headerFoldout == null)
  65. {
  66. headerFoldout = new GUIStyle(EditorStyles.foldout);
  67. headerFoldout.fontStyle = FontStyle.Bold;
  68. }
  69. if (popUpStyle == null)
  70. {
  71. popUpStyle = new GUIStyle(EditorStyles.popup);
  72. popUpStyle.alignment = TextAnchor.MiddleCenter;
  73. popUpStyle.fixedHeight = 20f;
  74. popUpStyle.fontStyle = FontStyle.Bold;
  75. }
  76. if (helpButton == null)
  77. {
  78. helpButton = new GUIStyle(EditorStyles.miniButtonRight);
  79. //helpButton.alignment = TextAnchor.UpperRight;
  80. helpButton.margin = new RectOffset(100,0,0,0);
  81. }
  82. }
  83. public void RenderHelpBoxButton()
  84. {
  85. //Help Box Button
  86. EditorGUILayout.BeginHorizontal();
  87. GUILayout.FlexibleSpace();
  88. if(GUILayout.Button("?", EditorStyles.miniButton,GUILayout.Width(20), GUILayout.Height(20)))
  89. {
  90. if(showHelpBox)
  91. showHelpBox = false;
  92. else
  93. showHelpBox = true;
  94. }
  95. EditorGUILayout.EndHorizontal();
  96. //End Help Box Button
  97. }
  98. public void RenderHelpBox(string content)
  99. {
  100. // GUILayout.BeginVertical("",EditorStyles.helpBox);
  101. GUILayout.Label(content,EditorStyles.helpBox);
  102. }
  103. public void RenderIntegrationTextBox(string content)
  104. {
  105. // GUILayout.BeginVertical("",EditorStyles.helpBox);
  106. GUILayout.Label(content,integrationBox);
  107. }
  108. public void RenderDisableInputBox()
  109. {
  110. if(Enviro.EnviroManager.instance != null)
  111. {
  112. if (Enviro.EnviroManager.instance.Weather != null && Enviro.EnviroManager.instance.Quality != null)
  113. {
  114. //both
  115. GUILayout.Label("Some settings are controlled from weather and quality modules!",EditorStyles.helpBox);
  116. }
  117. else if(Enviro.EnviroManager.instance.Weather != null && Enviro.EnviroManager.instance.Quality == null)
  118. {
  119. //Weather Only
  120. GUILayout.Label("Some settings are controlled from weather modules!",EditorStyles.helpBox);
  121. }
  122. else if(Enviro.EnviroManager.instance.Weather == null && Enviro.EnviroManager.instance.Quality != null)
  123. {
  124. // Quality Only
  125. GUILayout.Label("Some settings are controlled from quality modules!",EditorStyles.helpBox);
  126. }
  127. else
  128. {
  129. //Show Nothing
  130. }
  131. }
  132. }
  133. public void ApplyChanges ()
  134. {
  135. if (EditorGUI.EndChangeCheck ()) {
  136. serializedObj.ApplyModifiedProperties ();
  137. }
  138. }
  139. public void AddDefineSymbol(string symbol)
  140. {
  141. var targets = Enum.GetValues(typeof(BuildTargetGroup))
  142. .Cast<BuildTargetGroup>()
  143. .Where(x => x != BuildTargetGroup.Unknown)
  144. .Where(x => !IsObsolete(x));
  145. foreach (var target in targets)
  146. {
  147. var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
  148. var list = defines.Split(';', ' ')
  149. .Where(x => !string.IsNullOrEmpty(x))
  150. .ToList();
  151. if (list.Contains(symbol))
  152. continue;
  153. list.Add(symbol);
  154. defines = list.Aggregate((a, b) => a + ";" + b);
  155. PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
  156. }
  157. }
  158. bool IsObsolete(BuildTargetGroup group)
  159. {
  160. var attrs = typeof(BuildTargetGroup)
  161. .GetField(group.ToString())
  162. .GetCustomAttributes(typeof(ObsoleteAttribute), false);
  163. return attrs != null && attrs.Length > 0;
  164. }
  165. public void RemoveDefineSymbol(string symbol)
  166. {
  167. string symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  168. var targets = Enum.GetValues(typeof(BuildTargetGroup))
  169. .Cast<BuildTargetGroup>()
  170. .Where(x => x != BuildTargetGroup.Unknown)
  171. .Where(x => !IsObsolete(x));
  172. foreach (var target in targets)
  173. {
  174. var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
  175. if (defines.Contains(symbol))
  176. {
  177. defines = defines.Replace(symbol + "; ", "");
  178. defines = defines.Replace(symbol, "");
  179. PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
  180. }
  181. }
  182. }
  183. }