Пример #1
0
        public static T GetComponentClone <T>(this T uEcomponent, Transform newParent) where T : Component
        {
            T clone = UnityEngine.Object.Instantiate(uEcomponent);

            clone.transform.SetParent(newParent, false);
            Utils.ZeroTransform(clone.transform);
            return(clone);
        }
Пример #2
0
        public static GameObject CreateGameObject(string name, Transform newParent)
        {
            GameObject newObject = new GameObject(name);

            newObject.transform.SetParent(newParent, false);
            Utils.ZeroTransform(newObject.transform);

            return(newObject);
        }
Пример #3
0
        public static GameObject CreateGameObject(string name, Transform newParent, Vector3 localPos)
        {
            GameObject newObject = new GameObject(name);

            newObject.transform.SetParent(newParent, false);
            Utils.ZeroTransform(newObject.transform);
            newObject.transform.localPosition = localPos;

            return(newObject);
        }
Пример #4
0
        public static GameObject GetPrefabClone(this GameObject prefab)
        {
            bool isActive = prefab.activeSelf;

            if (isActive)
            {
                prefab.SetActive(false);
            }

            GameObject clone = UnityEngine.Object.Instantiate(prefab);

            Utils.ZeroTransform(clone.transform);
            return(clone);
        }
Пример #5
0
        public static GameObject GetPrefabClone(this GameObject prefab, Transform newParent, bool setActive, string newName)
        {
            bool isActive = prefab.activeSelf;

            if (isActive)
            {
                prefab.SetActive(false);
            }

            GameObject clone = UnityEngine.Object.Instantiate(prefab);

            clone.SetActive(setActive);
            clone.transform.SetParent(newParent, false);
            clone.name = newName;
            Utils.ZeroTransform(clone.transform);
            prefab.SetActive(isActive);
            return(clone);
        }