-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-558] feat: refactored symbol edit logic and added symbol remove …
…logic (#133) - remove define symbols when core is removed via package manager - refactor define symbol edit logic into separate class
- Loading branch information
1 parent
3fc5d86
commit f43e3ee
Showing
4 changed files
with
102 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
using UnityEditor; | ||
using UnityEditor.Compilation; | ||
|
||
namespace ReadyPlayerMe.Core.Editor | ||
{ | ||
public static class DefineSymbolHelper | ||
{ | ||
private const string GLTFAST_SYMBOL = "GLTFAST"; | ||
private const string READY_PLAYER_ME_SYMBOL = "READY_PLAYER_ME"; | ||
|
||
private static void ModifyScriptingDefineSymbolInAllBuildTargetGroups(string defineSymbol, bool addSymbol) | ||
{ | ||
foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget))) | ||
{ | ||
BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); | ||
|
||
if (group == BuildTargetGroup.Unknown) | ||
{ | ||
continue; | ||
} | ||
|
||
List<string> defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(group).Split(';').Select(d => d.Trim()).ToList(); | ||
|
||
if (addSymbol && !defineSymbols.Contains(defineSymbol)) | ||
{ | ||
defineSymbols.Add(defineSymbol); | ||
} | ||
else if (!addSymbol && defineSymbols.Contains(defineSymbol)) | ||
{ | ||
defineSymbols.Remove(defineSymbol); | ||
} | ||
else | ||
{ | ||
continue; | ||
} | ||
|
||
try | ||
{ | ||
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, string.Join(";", defineSymbols.ToArray())); | ||
} | ||
catch (Exception e) | ||
{ | ||
var actionWord = addSymbol ? "set" : "remove"; | ||
Debug.LogWarning($"Could not {actionWord} {defineSymbol} defines for build target: {target} group: {group} {e}"); | ||
} | ||
} | ||
|
||
if (addSymbol) | ||
{ | ||
CompilationPipeline.RequestScriptCompilation(); | ||
} | ||
} | ||
|
||
public static void AddSymbols() | ||
{ | ||
ModifyScriptingDefineSymbolInAllBuildTargetGroups(GLTFAST_SYMBOL, true); | ||
ModifyScriptingDefineSymbolInAllBuildTargetGroups(READY_PLAYER_ME_SYMBOL, true); | ||
CompilationPipeline.RequestScriptCompilation(); | ||
} | ||
|
||
public static void RemoveSymbols() | ||
{ | ||
ModifyScriptingDefineSymbolInAllBuildTargetGroups(GLTFAST_SYMBOL, false); | ||
ModifyScriptingDefineSymbolInAllBuildTargetGroups(READY_PLAYER_ME_SYMBOL, false); | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.