-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-New optimized list system -Added prefabs support -Adding a new entry scrolls down the list -Fixed issues with the logo -Cleaner code using scopes for GUI -Types are now removed from add component menu -Header will change color depending on the platform -It is now possible to access the EQS_Data gameobject for debugging purposes -Split VRC scripts into SDK2 & SDK3 versions for clarity -Simplified the creation of types by creating a method to get the correct PC or Quest field depending on the build target -Renamed EQS_Local to EQS_Localizations -EQS_Localizations is now static to be called from anywhere within EQS -Fixed standard shader materials losing the shader reference, if the shader is missing, the platform switch will automatically fix it -Now prevents putting a type that already exists in the list -EQS will now keep going down the list during a platform switch even if an object is missing or has an error -Added Asset Pipeline V2 tip if using 2019 or newer -A lot of new components & base fields have been supported (check v1.1 release)
- Loading branch information
Jordo
authored and
Jordo
committed
Aug 14, 2021
1 parent
1487ac1
commit 35bbc29
Showing
86 changed files
with
2,448 additions
and
1,443 deletions.
There are no files selected for viewing
File renamed without changes.
276 changes: 157 additions & 119 deletions
276
VRCPrefabs/EasyQuestSwitch/EQS_Data.cs → EasyQuestSwitch/EQS_Data.cs
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 |
---|---|---|
@@ -1,119 +1,157 @@ | ||
#if UNITY_EDITOR | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
using EasyQuestSwitch.Types; | ||
using System.Reflection; | ||
using System.Linq; | ||
using System.Collections; | ||
|
||
namespace EasyQuestSwitch | ||
{ | ||
|
||
[ExecuteInEditMode] | ||
public class EQS_Data : MonoBehaviour | ||
{ | ||
|
||
[Serializable] | ||
public class Data | ||
{ | ||
public Object Target; | ||
public Type_Base Type; | ||
public bool Foldout; | ||
} | ||
|
||
public List<Data> Objects; | ||
|
||
public void ValidateData(int index) | ||
{ | ||
Data data = Objects[index]; | ||
if (data.Target != null) | ||
{ | ||
if(data.Type != null) | ||
{ | ||
// Target has been changed, remove current type and apply a new one | ||
DestroyImmediate(Objects[index].Type); | ||
Objects[index].Type = null; | ||
Objects[index].Foldout = false; | ||
} | ||
|
||
IEnumerable<Type> everyTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && t.Namespace == "EasyQuestSwitch.Types" select t; | ||
// TODO: I wrote this while I was very sleep deprived due to crunch time for Vket 4, so expect an optimisation sometime in the future | ||
for(int i = 0; i < everyTypes.Count(); i++) | ||
{ | ||
FieldInfo field = everyTypes.ElementAt(i).GetField("type", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (field == null) continue; | ||
Type fieldType = field.FieldType; | ||
/*if (data.Target.GetType().IsAssignableFrom(fieldType)) Debug.LogFormat("{0} is Assignable from {1} ? {2}", data.Target.GetType(), fieldType, data.Target.GetType().IsAssignableFrom(fieldType)); | ||
if (data.Target.GetType().IsSubclassOf(fieldType)) Debug.LogFormat("{0} is Subclass of {1} ? {2}", data.Target.GetType(), fieldType, data.Target.GetType().IsSubclassOf(fieldType));*/ | ||
if (data.Target.GetType() == fieldType) | ||
{ | ||
Objects[index].Type = (Type_Base)gameObject.AddComponent(everyTypes.ElementAt(i)); | ||
break; | ||
} | ||
} | ||
if(Objects[index].Type == null) | ||
{ | ||
for(int i = 0; i < everyTypes.Count(); i++) | ||
{ | ||
FieldInfo field = everyTypes.ElementAt(i).GetField("type", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (field == null) continue; | ||
Type fieldType = field.FieldType; | ||
if (data.Target.GetType().IsSubclassOf(fieldType)) | ||
{ | ||
Objects[index].Type = (Type_Base)gameObject.AddComponent(everyTypes.ElementAt(i)); | ||
break; | ||
} | ||
} | ||
} | ||
if(Objects[index].Type == null) | ||
{ | ||
Debug.LogError("This is an unsupported component"); | ||
Objects[index].Target = null; | ||
Objects[index].Foldout = false; | ||
return; | ||
} | ||
Objects[index].Type.Setup(Objects[index].Target); | ||
Objects[index].Foldout = true; | ||
} | ||
else if (data.Target == null && data.Type != null) | ||
{ | ||
// Target has been removed but not the corresponding type, remove the type | ||
DestroyImmediate(Objects[index].Type); | ||
Objects[index].Type = null; | ||
Objects[index].Foldout = false; | ||
} | ||
} | ||
|
||
public BuildTarget CachedBuildTarget; // Last build target used in this scene | ||
public BuildTarget NewBuildTarget; | ||
|
||
private void Update() | ||
{ | ||
NewBuildTarget = EditorUserBuildSettings.activeBuildTarget; | ||
if (CachedBuildTarget != NewBuildTarget && Objects != null) CheckTarget(NewBuildTarget); | ||
CachedBuildTarget = NewBuildTarget; | ||
} | ||
|
||
public void CheckTarget(BuildTarget newTarget) | ||
{ | ||
if(newTarget == BuildTarget.StandaloneWindows64 || newTarget == BuildTarget.StandaloneWindows || newTarget == BuildTarget.Android) | ||
{ | ||
foreach(Data d in Objects) | ||
{ | ||
if(d.Type != null) d.Type.Process(d.Target, newTarget); | ||
} | ||
Debug.LogFormat("EasyQuestSwitch applied the scene changes of build target {0}", newTarget); | ||
} | ||
else | ||
{ | ||
Debug.LogError("Switched to an unsupported build target."); | ||
} | ||
} | ||
} | ||
|
||
} | ||
#endif | ||
#if UNITY_EDITOR | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
using EasyQuestSwitch.Types; | ||
using System.Reflection; | ||
using System.Linq; | ||
using System.Collections; | ||
|
||
namespace EasyQuestSwitch | ||
{ | ||
[ExecuteInEditMode, AddComponentMenu("")] | ||
public class EQS_Data : MonoBehaviour | ||
{ | ||
|
||
[Serializable] | ||
public class Data | ||
{ | ||
public Object Target; | ||
public Type_Base Type; | ||
public bool Foldout; | ||
} | ||
|
||
public List<Data> Objects; | ||
|
||
public void ValidateData(int index) | ||
{ | ||
Data data = Objects[index]; | ||
if (data.Target != null) | ||
{ | ||
for(int i = 0; i < Objects.Count; i++) | ||
{ | ||
if (i == index) continue; | ||
if (Objects[i].Target == data.Target) | ||
{ | ||
Debug.LogError(EQS_Localization.Current.LogComponentExists); | ||
DestroyImmediate(Objects[index].Type); | ||
Objects[index].Type = null; | ||
Objects[index].Foldout = false; | ||
Objects[index].Target = null; | ||
return; | ||
} | ||
} | ||
if(data.Type != null) | ||
{ | ||
// Target has been changed, remove current type and apply a new one | ||
DestroyImmediate(Objects[index].Type); | ||
Objects[index].Type = null; | ||
Objects[index].Foldout = false; | ||
} | ||
|
||
IEnumerable<Type> everyTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && t.Namespace == "EasyQuestSwitch.Types" select t; | ||
for(int i = 0; i < everyTypes.Count(); i++) | ||
{ | ||
FieldInfo field = everyTypes.ElementAt(i).GetField("type", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (field == null) continue; | ||
Type fieldType = field.FieldType; | ||
if (data.Target.GetType() == fieldType) | ||
{ | ||
Objects[index].Type = (Type_Base)gameObject.AddComponent(everyTypes.ElementAt(i)); | ||
break; | ||
} | ||
} | ||
if(Objects[index].Type == null) | ||
{ | ||
for(int i = 0; i < everyTypes.Count(); i++) | ||
{ | ||
FieldInfo field = everyTypes.ElementAt(i).GetField("type", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (field == null) continue; | ||
Type fieldType = field.FieldType; | ||
if (data.Target.GetType().IsSubclassOf(fieldType)) | ||
{ | ||
Objects[index].Type = (Type_Base)gameObject.AddComponent(everyTypes.ElementAt(i)); | ||
break; | ||
} | ||
} | ||
} | ||
if(Objects[index].Type == null) | ||
{ | ||
Debug.LogError(EQS_Localization.Current.LogUnsupportedComponent); | ||
Objects[index].Target = null; | ||
Objects[index].Foldout = false; | ||
return; | ||
} | ||
Objects[index].Type.Setup(Objects[index].Target); | ||
Objects[index].Foldout = true; | ||
} | ||
else if (data.Target == null && data.Type != null) | ||
{ | ||
// Target has been removed but not the corresponding type, remove the type | ||
DestroyImmediate(Objects[index].Type); | ||
Objects[index].Type = null; | ||
Objects[index].Foldout = false; | ||
} | ||
} | ||
|
||
public BuildTarget CachedBuildTarget; // Last build target used in this scene | ||
public BuildTarget NewBuildTarget; | ||
|
||
// Removed feature for Vket release, will be released in v1.2 | ||
/*private void Start() | ||
{ | ||
/*if(CachedBuildTarget != NewBuildTarget && Objects != null) | ||
{ | ||
string displayDialog = string.Format(EQS_Localization.Current.PopupTargetChanged, NewBuildTarget.ToString()); | ||
if(EditorUtility.DisplayDialog("", displayDialog, EQS_Localization.Current.PopupAccept, EQS_Localization.Current.PopupDecline)) | ||
{ | ||
CheckTarget(NewBuildTarget); | ||
} | ||
} | ||
}*/ | ||
|
||
private void Update() | ||
{ | ||
NewBuildTarget = EditorUserBuildSettings.activeBuildTarget; | ||
if (CachedBuildTarget != NewBuildTarget && Objects != null) CheckTarget(NewBuildTarget); | ||
CachedBuildTarget = NewBuildTarget; | ||
} | ||
|
||
public void CheckTarget(BuildTarget newTarget) | ||
{ | ||
if(newTarget == BuildTarget.StandaloneWindows64 || newTarget == BuildTarget.Android) | ||
{ | ||
for(int i = 0; i < Objects.Count; i++) | ||
{ | ||
Data d = Objects[i]; | ||
if(d.Target == null) | ||
{ | ||
Debug.LogErrorFormat(EQS_Localization.Current.LogSwitchMissing, i); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
d.Type.Process(d.Target, newTarget); | ||
PrefabUtility.RecordPrefabInstancePropertyModifications(d.Target); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogErrorFormat(EQS_Localization.Current.LogSwitchFailure, i, d.Target.name, e.Message); | ||
} | ||
} | ||
} | ||
Debug.LogFormat(EQS_Localization.Current.LogSwitchSuccess, newTarget); | ||
} | ||
else | ||
{ | ||
Debug.LogError(EQS_Localization.Current.LogSwitchUnsupported); | ||
} | ||
} | ||
} | ||
|
||
} | ||
#endif |
File renamed without changes.
Oops, something went wrong.