123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using System;
- using System.Linq;
- public class EnviroBaseInspector : Editor
- {
- public SerializedObject serializedObj;
- public GUIStyle boxStyle;
- public GUIStyle boxStyleModified;
- public GUIStyle wrapStyle;
- public GUIStyle headerStyle;
- public GUIStyle headerStyleMid;
- public GUIStyle headerFoldout;
- public GUIStyle popUpStyle;
- public GUIStyle integrationBox;
- public GUIStyle helpButton;
- public bool showHelpBox;
- public Color baseModuleColor = new Color(0.0f,0.0f,0.5f,1f);
- public Color categoryModuleColor = new Color(0.5f,0.5f,0.0f,1f);
- public Color thirdPartyModuleColor = new Color(0.0f,0.5f,0.5f,1f);
- public void SetupGUIStyles ()
- {
- if (boxStyle == null)
- {
- boxStyle = new GUIStyle(GUI.skin.box);
- boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
- boxStyle.fontStyle = FontStyle.Bold;
- boxStyle.alignment = TextAnchor.UpperLeft;
- }
- if (boxStyleModified == null)
- {
- boxStyleModified = new GUIStyle(EditorStyles.helpBox);
- boxStyleModified.normal.textColor = GUI.skin.label.normal.textColor;
- boxStyleModified.fontStyle = FontStyle.Bold;
- boxStyleModified.fontSize = 11;
- boxStyleModified.alignment = TextAnchor.UpperLeft;
- }
- if (integrationBox == null)
- {
- integrationBox = new GUIStyle(EditorStyles.helpBox);
- integrationBox.fontStyle = FontStyle.Bold;
- integrationBox.fontSize = 11;
- }
- if (wrapStyle == null)
- {
- wrapStyle = new GUIStyle(GUI.skin.label);
- wrapStyle.fontStyle = FontStyle.Normal;
- wrapStyle.wordWrap = true;
- }
- if (headerStyle == null)
- {
- headerStyle = new GUIStyle(GUI.skin.label);
- headerStyle.fontStyle = FontStyle.Bold;
- headerStyle.alignment = TextAnchor.UpperLeft;
- }
- if (headerStyleMid == null)
- {
- headerStyleMid = new GUIStyle(GUI.skin.label);
- headerStyleMid.fontStyle = FontStyle.Bold;
- headerStyleMid.alignment = TextAnchor.MiddleCenter;
- }
- if (headerFoldout == null)
- {
- headerFoldout = new GUIStyle(EditorStyles.foldout);
- headerFoldout.fontStyle = FontStyle.Bold;
- }
- if (popUpStyle == null)
- {
- popUpStyle = new GUIStyle(EditorStyles.popup);
- popUpStyle.alignment = TextAnchor.MiddleCenter;
- popUpStyle.fixedHeight = 20f;
- popUpStyle.fontStyle = FontStyle.Bold;
- }
- if (helpButton == null)
- {
- helpButton = new GUIStyle(EditorStyles.miniButtonRight);
- //helpButton.alignment = TextAnchor.UpperRight;
- helpButton.margin = new RectOffset(100,0,0,0);
- }
- }
- public void RenderHelpBoxButton()
- {
- //Help Box Button
- EditorGUILayout.BeginHorizontal();
- GUILayout.FlexibleSpace();
- if(GUILayout.Button("?", EditorStyles.miniButton,GUILayout.Width(20), GUILayout.Height(20)))
- {
- if(showHelpBox)
- showHelpBox = false;
- else
- showHelpBox = true;
- }
- EditorGUILayout.EndHorizontal();
- //End Help Box Button
- }
- public void RenderHelpBox(string content)
- {
- // GUILayout.BeginVertical("",EditorStyles.helpBox);
- GUILayout.Label(content,EditorStyles.helpBox);
- }
- public void RenderIntegrationTextBox(string content)
- {
- // GUILayout.BeginVertical("",EditorStyles.helpBox);
- GUILayout.Label(content,integrationBox);
- }
- public void RenderDisableInputBox()
- {
- if(Enviro.EnviroManager.instance != null)
- {
- if (Enviro.EnviroManager.instance.Weather != null && Enviro.EnviroManager.instance.Quality != null)
- {
- //both
- GUILayout.Label("Some settings are controlled from weather and quality modules!",EditorStyles.helpBox);
- }
- else if(Enviro.EnviroManager.instance.Weather != null && Enviro.EnviroManager.instance.Quality == null)
- {
- //Weather Only
- GUILayout.Label("Some settings are controlled from weather modules!",EditorStyles.helpBox);
- }
- else if(Enviro.EnviroManager.instance.Weather == null && Enviro.EnviroManager.instance.Quality != null)
- {
- // Quality Only
- GUILayout.Label("Some settings are controlled from quality modules!",EditorStyles.helpBox);
- }
- else
- {
- //Show Nothing
- }
-
- }
- }
- public void ApplyChanges ()
- {
- if (EditorGUI.EndChangeCheck ()) {
- serializedObj.ApplyModifiedProperties ();
- }
- }
- public void AddDefineSymbol(string symbol)
- {
- var targets = Enum.GetValues(typeof(BuildTargetGroup))
- .Cast<BuildTargetGroup>()
- .Where(x => x != BuildTargetGroup.Unknown)
- .Where(x => !IsObsolete(x));
- foreach (var target in targets)
- {
- var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
- var list = defines.Split(';', ' ')
- .Where(x => !string.IsNullOrEmpty(x))
- .ToList();
- if (list.Contains(symbol))
- continue;
- list.Add(symbol);
- defines = list.Aggregate((a, b) => a + ";" + b);
- PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
- }
- }
- bool IsObsolete(BuildTargetGroup group)
- {
- var attrs = typeof(BuildTargetGroup)
- .GetField(group.ToString())
- .GetCustomAttributes(typeof(ObsoleteAttribute), false);
- return attrs != null && attrs.Length > 0;
- }
- public void RemoveDefineSymbol(string symbol)
- {
- string symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
- var targets = Enum.GetValues(typeof(BuildTargetGroup))
- .Cast<BuildTargetGroup>()
- .Where(x => x != BuildTargetGroup.Unknown)
- .Where(x => !IsObsolete(x));
- foreach (var target in targets)
- {
- var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
- if (defines.Contains(symbol))
- {
- defines = defines.Replace(symbol + "; ", "");
- defines = defines.Replace(symbol, "");
- PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
- }
- }
- }
- }
|