Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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