示例#1
0
        public static void SetParent(Component component, Transform parent, TransStayOption stayOption = TransStayOption.Non)
        {
            if (component == null)
            {
                return;
            }

            Transform trans = component.transform;

            switch (stayOption)
            {
            case TransStayOption.Local:
                trans.SetParent(parent, false);
                break;

            case TransStayOption.World:
                trans.SetParent(parent);
                break;

            default:
                trans.SetParent(parent, false);
                trans.localPosition = Vector3.zero;
                trans.localRotation = Quaternion.identity;
                trans.localScale    = Vector3.one;
                break;
            }
        }
示例#2
0
        public static void SetParent(GameObject go, Transform parent, TransStayOption stayOption = TransStayOption.Non)
        {
            if (go == null)
            {
                return;
            }

            SetParent(go.transform, parent, stayOption);
        }
示例#3
0
        public static T Instantiate <T> (string path, Transform parent = null, TransStayOption stayOption = TransStayOption.Non) where T : Component
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            GameObject prefab = ResourceManager.Load <GameObject> (path);

            return(Instantiate <T> (prefab, parent, stayOption));
        }
示例#4
0
        public static T Instantiate <T> (GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non) where T : Component
        {
            GameObject go = Instantiate(prefab, parent, stayOption);

            if (go == null)
            {
                return(null);
            }

            return(go.GetComponent <T> ());
        }
示例#5
0
        public static Component InstantiateOrCreateInChildren(System.Type type, string path, Transform parent = null, TransStayOption stayOption = TransStayOption.Non, bool includeInactive = false)
        {
            GameObject prefab = ResourceManager.Load <GameObject> (path);

            return(InstantiateOrCreateInChildren(type, prefab, parent, stayOption, includeInactive));
        }
示例#6
0
        public static Component InstantiateOrCreateInChildren(System.Type type, GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non, bool includeInactive = false)
        {
            GameObject go = InstantiateOrCreate(prefab, parent, stayOption);

            return(GetOrAddComponentInChildren(type, go, includeInactive));
        }
示例#7
0
        public static T InstantiateOrCreateInChildren <T> (string path, Transform parent = null, TransStayOption stayOption = TransStayOption.Non, bool includeInactive = false) where T : Component
        {
            GameObject prefab = ResourceManager.Load <GameObject> (path);

            return(InstantiateOrCreateInChildren <T> (prefab, parent, stayOption, includeInactive));
        }
示例#8
0
        public static T InstantiateOrCreateInChildren <T> (GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non, bool includeInactive = false) where T : Component
        {
            GameObject go = InstantiateOrCreate(prefab, parent, stayOption);

            return(GetOrAddComponentInChildren <T> (go, includeInactive));
        }
示例#9
0
        public static Component InstantiateOrCreate(System.Type type, string path, Transform parent = null, TransStayOption stayOption = TransStayOption.Non)
        {
            GameObject prefab = ResourceManager.Load <GameObject> (path);

            return(InstantiateOrCreate(type, prefab, parent, stayOption));
        }
示例#10
0
        public static Component InstantiateOrCreate(System.Type type, GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non)
        {
            GameObject go = InstantiateOrCreate(prefab, parent, stayOption);

            return(GetOrAddComponent(type, go));
        }
示例#11
0
        public static T InstantiateOrCreate <T> (GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non) where T : Component
        {
            GameObject go = InstantiateOrCreate(prefab, parent, stayOption);

            return(GetOrAddComponent <T> (go));
        }
示例#12
0
        public static GameObject InstantiateOrCreate(string path, Transform parent = null, TransStayOption stayOption = TransStayOption.Non)
        {
            GameObject prefab = ResourceManager.Load <GameObject> (path);

            return(InstantiateOrCreate(prefab, parent, stayOption));
        }
示例#13
0
        public static GameObject InstantiateOrCreate(GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non)
        {
            GameObject go = prefab != null?Object.Instantiate(prefab) : new GameObject();

            SetParent(go, parent, stayOption);
            return(go);
        }
示例#14
0
        public static GameObject Instantiate(GameObject prefab, Transform parent = null, TransStayOption stayOption = TransStayOption.Non)
        {
            if (prefab == null)
            {
                return(null);
            }

            GameObject go = Object.Instantiate(prefab);

            SetParent(go, parent, stayOption);
            return(go);
        }