public void OnEnable() { instance = (MyMonoBehaviour)target; prefabProperty = serializedObject.FindProperty("prefab"); amountProperty = serializedObject.FindProperty("amount"); offsetProperty = serializedObject.FindProperty("offset"); }
/* Instantiates non-MonoBehaviours and utilities. */ void Awake() { if (!initializedNonMonos) { if (showDebug) Debug.Log("_____MyMonoBehaviour: Performing first-time initialization_____"); /* Utilities */ instance = this; InstantiateDatabases(); initializedNonMonos = true; if (showDebug) Debug.Log("_____MyMonoBehaviour: First-time initialization complete_____"); } }
public void NullCoalescing(MyMonoBehaviour mb) { var behaviour = mb ?? gameObject.AddComponent <MyMonoBehaviour>(); if (behaviour?.CompareTag("foo") == true) { // ... } var coolRenderer = GetComponent <Renderer>(); if (coolRenderer == transform) { } }
public void DoSomething(GameObject go) { var behaviour = new MyMonoBehaviour(); var scriptableObject = new MyScriptableObject(); }
static public GameObject Spawn(GameObject ObjectClass, MyMonoBehaviour ParentComponent, UnityAction <GameObject> Initializer = null) { Assert.IsNotNull(ParentComponent); return(Spawn(ObjectClass, ParentComponent.gameObject, Initializer)); }
// These functions allow us to spawn GameObjects using an optional delegate for initialization prior to Awake and Start being called static public T Spawn <T>(T ComponentClass, MyMonoBehaviour ParentComponent, UnityAction <T> Initializer = null) where T : MyMonoBehaviour { Assert.IsNotNull(ParentComponent); return(Spawn(ComponentClass, ParentComponent.gameObject, Initializer)); }
public void Initialization(GameObject gameObject) { this.gameObject = gameObject; rigidbody = MyMonoBehaviour.AddComponentIfNotExits_noWarning <Rigidbody>(gameObject); collider = MyMonoBehaviour.AddComponentIfNotExits_noWarning <Collider>(gameObject); }