Created
January 30, 2018 10:32
-
-
Save MewSoul/53d3b7b8a3429e6eccb01b53420f387a to your computer and use it in GitHub Desktop.
Extension to easily add/remove custom defines to specific build targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
namespace Utils | |
{ | |
public class CustomDefineEditor : EditorWindow | |
{ | |
private string[] defines = | |
{ | |
"debug" | |
}; | |
private bool[] values; | |
private BuildTargetGroup selectedTargetGroup; | |
private void Awake() | |
{ | |
values = new bool[defines.Length]; | |
selectedTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; | |
LoadCustomDefines(); | |
} | |
[MenuItem("Window/CustomDefines")] | |
public static void ShowWindow() | |
{ | |
EditorWindow.GetWindow(typeof(CustomDefineEditor), false, "CustomDefines"); | |
} | |
private void OnGUI() | |
{ | |
GUILayout.Label("Target", EditorStyles.boldLabel); | |
BuildTargetGroup selection = (BuildTargetGroup)EditorGUILayout.EnumPopup("Selected target", selectedTargetGroup); | |
if (selection != selectedTargetGroup) | |
{ | |
selectedTargetGroup = selection; | |
LoadCustomDefines(); | |
} | |
GUILayout.Label("Defines", EditorStyles.boldLabel); | |
for (int i = 0; i < defines.Length; i++) | |
{ | |
string define = defines[i]; | |
values[i] = EditorGUILayout.Toggle(define, values[i]); | |
} | |
if (GUILayout.Button("Save")) | |
{ | |
SaveCustomDefines(); | |
Debug.Log("Custom defines saved!"); | |
} | |
} | |
private void SaveCustomDefines() | |
{ | |
string definesToSave = ""; | |
for (int i = 0; i < values.Length; i++) | |
{ | |
if (values[i]) | |
{ | |
definesToSave += defines[i] + ";"; | |
} | |
} | |
PlayerSettings.SetScriptingDefineSymbolsForGroup(selectedTargetGroup, definesToSave); | |
} | |
private void LoadCustomDefines() | |
{ | |
string customDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(selectedTargetGroup); | |
for (int i = 0; i < defines.Length; i++) | |
{ | |
values[i] = customDefines.Contains(defines[i]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment