Skip to content

Instantly share code, notes, and snippets.

@Geri-Borbas
Last active June 19, 2017 02:02
Show Gist options
  • Save Geri-Borbas/a92ac7993239608a3891752d2bbdba75 to your computer and use it in GitHub Desktop.
Save Geri-Borbas/a92ac7993239608a3891752d2bbdba75 to your computer and use it in GitHub Desktop.
Create Scripting Define Symbol from script for the selected Build Target in Unity.
using System;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class Define
{
const string define = "LIBRARY_IS_AVAILABLE";
static Define()
{ AddDefineIfNeeded(); }
static void AddDefineIfNeeded()
{
// Get selected target defines.
BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
// Only if not defined already.
if (defines.Contains(define))
{
Debug.LogWarning("Selected build target ("+EditorUserBuildSettings.activeBuildTarget.ToString()+") already contains <b>"+define+"</b> <i>Scripting Define Symbol</i>.");
return;
}
// Append.
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, (defines + ";" + define));
Debug.LogWarning("<b>"+define+"</b> added to <i>Scripting Define Symbols</i> for selected build target ("+EditorUserBuildSettings.activeBuildTarget.ToString()+").");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment