using UnityEngine; namespace BitStrap { public static class Create { public static GameObject Prefab(GameObject prefab, Transform parent = null) { GameObject gameObject = Object.Instantiate(prefab); if (parent != null) { gameObject.transform.SetParent(parent, false); } gameObject.transform.localPosition = prefab.transform.localPosition; gameObject.transform.localRotation = prefab.transform.localRotation; gameObject.transform.localScale = prefab.transform.localScale; return gameObject; } public static T Behaviour(Transform parent = null) where T : MonoBehaviour { GameObject gameObject = new GameObject(typeof(T).Name); if (parent != null) { gameObject.transform.SetParent(parent, false); } gameObject.transform.localPosition = Vector3.zero; gameObject.transform.localRotation = Quaternion.identity; gameObject.transform.localScale = Vector3.one; return gameObject.AddComponent(); } public static T Behaviour(T behaviourPrefab, Transform parent = null) where T : MonoBehaviour { GameObject gameObject = Object.Instantiate(behaviourPrefab.gameObject); if (parent != null) { gameObject.transform.SetParent(parent, false); } gameObject.transform.localPosition = behaviourPrefab.transform.localPosition; gameObject.transform.localRotation = behaviourPrefab.transform.localRotation; gameObject.transform.localScale = behaviourPrefab.transform.localScale; return gameObject.GetComponent(); } } }