Installed Surge, fixed compile errors, moved a bunch of external stuff into folder
This commit is contained in:
60
Assets/External/Pixelplacement/Surge/Editor/InitializationRequirements.cs
vendored
Normal file
60
Assets/External/Pixelplacement/Surge/Editor/InitializationRequirements.cs
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/// <summary>
|
||||
/// SURGE FRAMEWORK
|
||||
/// Author: Bob Berkebile
|
||||
/// Email: bobb@pixelplacement.com
|
||||
///
|
||||
/// This looks over all pieces of the framework to ensure they are properly set up - this is normally needed if a script that was already added to a GameObject suddenly extends something with a RequireComponent which is a decent bug in my opinion but this approach seems to work as a decent safety net.
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace Pixelplacement
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class InitializationRequirements
|
||||
{
|
||||
static InitializationRequirements ()
|
||||
{
|
||||
//state machines:
|
||||
StateMachine[] stateMachines = Resources.FindObjectsOfTypeAll<StateMachine> ();
|
||||
foreach (StateMachine item in stateMachines)
|
||||
{
|
||||
if (item.GetComponent<Initialization> () == null) item.gameObject.AddComponent<Initialization> ();
|
||||
}
|
||||
|
||||
//display object:
|
||||
DisplayObject[] displayObjects = Resources.FindObjectsOfTypeAll<DisplayObject> ();
|
||||
foreach (DisplayObject item in displayObjects)
|
||||
{
|
||||
if (item.GetComponent<Initialization> () == null) item.gameObject.AddComponent<Initialization> ();
|
||||
}
|
||||
|
||||
//singleton (generics require some hackery to find what we need):
|
||||
foreach (GameObject item in Resources.FindObjectsOfTypeAll<GameObject> ())
|
||||
{
|
||||
foreach (Component subItem in item.GetComponents<Component> ())
|
||||
{
|
||||
//bypass this component if its currently unavailable due to a broken or missing script:
|
||||
if (subItem == null) continue;
|
||||
|
||||
string baseType;
|
||||
|
||||
#if NETFX_CORE
|
||||
baseType = subItem.GetType ().GetTypeInfo ().BaseType.ToString ();
|
||||
#else
|
||||
baseType = subItem.GetType ().BaseType.ToString ();
|
||||
#endif
|
||||
|
||||
if (baseType.Contains ("Singleton") && baseType.Contains ("Pixelplacement"))
|
||||
{
|
||||
if (item.GetComponent<Initialization> () == null) item.gameObject.AddComponent<Initialization> ();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user