duck

Unity Compiler Define Symbol Custom Menu Example

Jan 30th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4.  
  5. public class CompilerDefineMenuExample {
  6.  
  7.     const string defineString = "COMPILER_DEFINE_EXAMPLE";
  8.    
  9.     [MenuItem("Compiler Define Example/Enable")]
  10.     static void Enable()
  11.     {
  12.         SetEnabled(true);
  13.     }
  14.    
  15.     [MenuItem("Compiler Define Example/Enable", true)]
  16.     static bool EnableValidate()
  17.     {
  18.         var defines = GetDefinesList();
  19.         return !defines.Contains(defineString);
  20.     }
  21.    
  22.     [MenuItem("Compiler Define Example/Disable")]
  23.     static void Disable()
  24.     {
  25.         SetEnabled(false);
  26.     }
  27.     [MenuItem("Compiler Define Example/Disable", true)]
  28.     static bool DisableValidate()
  29.     {
  30.         var defines = GetDefinesList();
  31.         return defines.Contains(defineString);
  32.     }
  33.    
  34.     static void SetEnabled(bool enable)
  35.     {
  36.         var defines = GetDefinesList();
  37.         if (enable)
  38.         {
  39.             defines.Add(defineString);
  40.             PlayerSettings.SetScriptingDefineSymbolsForGroup( BuildTargetGroup.Standalone, string.Join(";",defines.ToArray()) );
  41.  
  42.         } else  {
  43.             defines.Remove(defineString);
  44.             PlayerSettings.SetScriptingDefineSymbolsForGroup( BuildTargetGroup.Standalone, string.Join(";",defines.ToArray()) );
  45.         }
  46.  
  47.     }
  48.  
  49.     static List<string> GetDefinesList()
  50.     {
  51.         return new List<string>( PlayerSettings.GetScriptingDefineSymbolsForGroup( BuildTargetGroup.Standalone ).Split(';'));
  52.     }
  53.    
  54. }
Add Comment
Please, Sign In to add comment