Skip to content

Instantly share code, notes, and snippets.

@Borod4r
Created March 4, 2016 15:53
Show Gist options
  • Save Borod4r/1ce210433c49b0b652f9 to your computer and use it in GitHub Desktop.
Save Borod4r/1ce210433c49b0b652f9 to your computer and use it in GitHub Desktop.
Better Defines for Unity3D
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