This file contains hidden or 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
| using UnityEngine; | |
| public class SelfCreatingPrefab : MonoBehaviour | |
| { | |
| private int fieldA; | |
| private int fieldB; | |
| public SelfCreatingPrefab Init(int arg1, int arg2) | |
| { | |
| if (!gameObject.scene.IsValid()) |
This file contains hidden or 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
| public static T CopyComponent<T>(T component, GameObject destination) where T : Component | |
| { | |
| var type = component.GetType(); | |
| var copy = destination.AddComponent(type); | |
| var fields = type.GetRuntimeFields(); | |
| // component, gameobject, etc. will override the name and tags, we don't want that | |
| var properties = type.GetRuntimeProperties().Where(p => p.SetMethod != null && p.GetGetMethod(false) != null && | |
| p.DeclaringType != typeof(GameObject) | |
| && p.DeclaringType != typeof(Component) | |
| && p.DeclaringType != typeof(UnityEngine.Object)).ToArray(); |
This file contains hidden or 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
| using UnityEngine; | |
| /// <summary> | |
| /// provides an easy way to create singletons in unity based on monobehaviours | |
| /// </summary> | |
| /// <typeparam name="T">T must be the same type as the declaring type</typeparam> | |
| public class MBSingleton<T> : MonoBehaviour where T : MonoBehaviour | |
| { | |
| protected static T _instance; |
OlderNewer