Created
          March 4, 2016 15:53 
        
      - 
      
- 
        Save Borod4r/1ce210433c49b0b652f9 to your computer and use it in GitHub Desktop. 
    Better Defines for Unity3D
  
        
  
    
      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 System.Collections.Generic; | |
| using UnityEditor; | |
| namespace Borodar.YesNoMath.Editor | |
| { | |
| [InitializeOnLoad] | |
| public class BetterDefines | |
| { | |
| static BetterDefines() | |
| { | |
| var isEditor = | |
| #if UNITY_EDITOR | |
| true; | |
| #else | |
| false; | |
| #endif | |
| ToggleFlag("GPGS_ENABLED", !isEditor, BuildTargetGroup.Android); | |
| ToggleFlag("GAME_CENTER_ENABLED", !isEditor, BuildTargetGroup.iOS); | |
| } | |
| //--------------------------------------------------------------------- | |
| // Helpers | |
| //--------------------------------------------------------------------- | |
| private static void ToggleFlag(string targetFlag, bool enable, params BuildTargetGroup[] supportedPlatforms) | |
| { | |
| foreach (var targetPlatform in supportedPlatforms) | |
| { | |
| var scriptDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetPlatform); | |
| var flags = new List<string>(scriptDefines.Split(';')); | |
| if (flags.Contains(targetFlag)) | |
| { | |
| if (!enable) flags.Remove(targetFlag); | |
| } | |
| else | |
| { | |
| if (enable) flags.Add(targetFlag); | |
| } | |
| var result = string.Join(";", flags.ToArray()); | |
| if (scriptDefines != result) | |
| { | |
| PlayerSettings.SetScriptingDefineSymbolsForGroup(targetPlatform, result); | |
| } | |
| } | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment