using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System; using System.Linq; using UnityEditor.Build; 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 static void AddDefineSymbol(string symbol) { var targets = Enum.GetValues(typeof(BuildTargetGroup)) .Cast() .Where(x => x != BuildTargetGroup.Unknown) .Where(x => !IsObsolete(x)); foreach (var target in targets) { #if UNITY_6000_0_OR_NEWER var namedTarget = NamedBuildTarget.FromBuildTargetGroup(target); var defines = PlayerSettings.GetScriptingDefineSymbols(namedTarget).Trim(); #else var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim(); #endif var list = defines.Split(new[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); if (list.Contains(symbol)) continue; list.Add(symbol); defines = string.Join(";", list); #if UNITY_6000_0_OR_NEWER PlayerSettings.SetScriptingDefineSymbols(namedTarget, defines); #else PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines); #endif } } private static bool IsObsolete(BuildTargetGroup group) { var field = typeof(BuildTargetGroup).GetField(group.ToString()); if (field == null) return false; var attrs = field.GetCustomAttributes(typeof(ObsoleteAttribute), false); return attrs != null && attrs.Length > 0; } public static void RemoveDefineSymbol(string symbol) { var targets = Enum.GetValues(typeof(BuildTargetGroup)) .Cast() .Where(x => x != BuildTargetGroup.Unknown) .Where(x => !IsObsolete(x)); foreach (var target in targets) { #if UNITY_6000_0_OR_NEWER var namedTarget = NamedBuildTarget.FromBuildTargetGroup(target); var defines = PlayerSettings.GetScriptingDefineSymbols(namedTarget).Trim(); #else var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim(); #endif var list = defines.Split(new[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); if (list.Contains(symbol)) { list.RemoveAll(s => s == symbol); defines = string.Join(";", list); #if UNITY_6000_0_OR_NEWER PlayerSettings.SetScriptingDefineSymbols(namedTarget, defines); #else PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines); #endif } } } }