Created
May 2, 2016 02:34
-
-
Save birdinforest/2cc54ec1c815bc205e76f033f836a352 to your computer and use it in GitHub Desktop.
Unity3D. Change global define by code.
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
private static void AddOneGlobalDefine(BuildTargetGroup group, string newDefine) { | |
string define = PlayerSettings.GetScriptingDefineSymbolsForGroup(group); | |
if(define == string.Empty) { | |
define = newDefine; | |
} else { | |
define = define + ";" + newDefine; | |
} | |
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, define); | |
Debug.Log("Current global define: " + define); | |
} | |
/// <summary> | |
/// Replaces the one globl define to another in target group. | |
/// </summary> | |
/// <returns> | |
/// "-2": one of both given string arguments is empty; | |
/// "-1": can't find parameter beReplaced. Use AddOneGloblDefine() to add a new define. | |
/// "0": the parameter replaceBy is allready in current global define list; | |
/// "1": replace done. | |
/// </returns>; | |
/// <param name="group">Group.</param> | |
/// <param name="beRepcased">The defien should be repcased.</param> | |
/// <param name="replaceBy">Replace by this string.</param> | |
private static int ReplaceOneGlobalDefineBy(BuildTargetGroup group, string beReplaced, string replaceBy) { | |
string define = PlayerSettings.GetScriptingDefineSymbolsForGroup(group); | |
if(beReplaced == string.Empty || replaceBy == string.Empty) | |
{ | |
return -2; | |
} | |
else if(define.Contains(replaceBy)) | |
{ | |
return -1; | |
} | |
else if(define == string.Empty || !define.Contains(beReplaced)) | |
{ | |
return -0; | |
} | |
else | |
{ | |
define = define.Replace(beReplaced, replaceBy); | |
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, define); | |
Debug.Log("Current global define: " + define); | |
return 1; | |
} | |
} | |
private static void RemoveOneGlobalDefine(BuildTargetGroup group, string removed) { | |
string define = PlayerSettings.GetScriptingDefineSymbolsForGroup(group); | |
if(define == string.Empty || removed == string.Empty || !define.Contains(removed)) { | |
return; | |
} else { | |
define = define.Replace(removed,""); | |
} | |
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, define); | |
Debug.Log("Current global define: " + define); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment