Skip to content

Instantly share code, notes, and snippets.

@t0chas
Created March 19, 2016 17:21
Show Gist options
  • Save t0chas/fc57dbea5fce4aaf83b9 to your computer and use it in GitHub Desktop.
Save t0chas/fc57dbea5fce4aaf83b9 to your computer and use it in GitHub Desktop.
Manage your Unity3D symbols easily within the Editor by defining menu items
using UnityEngine;
using UnityEditor;
public class CustomDefines {
[MenuItem("Global Defines/My Symbol/Enable")]
public static void EnableDebug(){
Debug.LogWarning("Enabling MY_SYMBOL");
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
string newDefine = "MY_SYMBOL";
if(!defines.Contains(newDefine)){
defines= string.Format("{0},{1}", defines, newDefine);
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
AssetDatabase.SaveAssets();
}
}
[MenuItem("Global Defines/My Symbol/Enable", true)]
public static bool EnableDebugEval(){
#if !MY_SYMBOL
return true;
#else
return false;
#endif
}
[MenuItem("Global Defines/My Symbol/Disable")]
public static void DisableDebug(){
Debug.LogWarning("Disabling MY_SYMBOL");
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
string newDefine = "MY_SYMBOL";
if(defines.Contains(newDefine)){
defines = defines.Replace(newDefine, "");
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
AssetDatabase.SaveAssets();
}
}
[MenuItem("Global Defines/My Symbol/Disable", true)]
public static bool DisableDebugEval(){
#if MY_SYMBOL
return true;
#else
return false;
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment