Added Unity Configurator
This commit is contained in:
parent
c4c01bedae
commit
bd53b71cd3
88
Unity/Editor/Configurator.cs
Normal file
88
Unity/Editor/Configurator.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEditor.PackageManager;
|
||||
|
||||
namespace RoboidControl.Unity
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class ConfigurationCheck
|
||||
{
|
||||
static ConfigurationCheck()
|
||||
{
|
||||
RetrievePackageList();
|
||||
}
|
||||
|
||||
protected static ListRequest request;
|
||||
public static List<string> packageNameList;
|
||||
|
||||
public static void RetrievePackageList()
|
||||
{
|
||||
request = Client.List(); // List packages installed for the Project
|
||||
EditorApplication.update += Progress;
|
||||
}
|
||||
|
||||
public static void Progress()
|
||||
{
|
||||
if (request.IsCompleted)
|
||||
{
|
||||
if (request.Status == StatusCode.Success)
|
||||
{
|
||||
packageNameList = new List<string>();
|
||||
foreach (UnityEditor.PackageManager.PackageInfo package in request.Result)
|
||||
packageNameList.Add(package.name);
|
||||
|
||||
DidReloadScripts();
|
||||
}
|
||||
else if (request.Status >= StatusCode.Failure)
|
||||
Debug.Log(request.Error.message);
|
||||
|
||||
EditorApplication.update -= Progress;
|
||||
}
|
||||
}
|
||||
|
||||
//[DidReloadScripts]
|
||||
protected static void DidReloadScripts()
|
||||
{
|
||||
if (packageNameList == null)
|
||||
return;
|
||||
CheckExtension(
|
||||
packageNameList.Contains("com.unity.cloud.gltfast"), "GLTF");
|
||||
}
|
||||
|
||||
protected static void CheckExtension(bool enabled, string define)
|
||||
{
|
||||
if (enabled)
|
||||
GlobalDefine(define);
|
||||
else
|
||||
GlobalUndefine(define);
|
||||
}
|
||||
|
||||
public static void GlobalDefine(string name)
|
||||
{
|
||||
//Debug.Log("Define " + name);
|
||||
string scriptDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (!scriptDefines.Contains(name))
|
||||
{
|
||||
string newScriptDefines = scriptDefines + " " + name;
|
||||
if (EditorUserBuildSettings.selectedBuildTargetGroup != 0)
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newScriptDefines);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GlobalUndefine(string name)
|
||||
{
|
||||
//Debug.Log("Undefine " + name);
|
||||
string scriptDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (scriptDefines.Contains(name))
|
||||
{
|
||||
int playMakerIndex = scriptDefines.IndexOf(name);
|
||||
string newScriptDefines = scriptDefines.Remove(playMakerIndex, name.Length);
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newScriptDefines);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user