-
-
Save TarasOsiris/343df8337fa2a7f80f59 to your computer and use it in GitHub Desktop.
Better Defines for Unity3D
This file contains 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using BetterDefines.Editor.Entity; | |
using UnityEditor; | |
namespace BetterDefines.Editor | |
{ | |
public static class BetterDefinesUtils | |
{ | |
public static void ToggleDefine(string define, 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(define)) | |
{ | |
if (!enable) | |
{ | |
flags.Remove(define); | |
} | |
} | |
else | |
{ | |
if (enable) | |
{ | |
flags.Add(define); | |
} | |
} | |
var result = string.Join(";", flags.ToArray()); | |
if (scriptDefines != result) | |
{ | |
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetPlatform, result); | |
} | |
} | |
} | |
public static void RemoveDefineFromAll(string define) | |
{ | |
ToggleDefine(define, false, GetAllAvailablePlatforms()); | |
} | |
public static void AddDefineToAll(string define) | |
{ | |
ToggleDefine(define, true, GetAllAvailablePlatforms()); | |
} | |
private static BuildTargetGroup[] GetAllAvailablePlatforms() | |
{ | |
var allPlatforms = Enum.GetValues(typeof(BuildTargetGroup)).Cast<BuildTargetGroup>().ToList(); | |
allPlatforms.Remove(BuildTargetGroup.Unknown); | |
return allPlatforms.ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment