コード例 #1
0
        public static GameObject InstantiateOrCreate(string prefabResPath, Transform parent = null,
                                                     TransformUtil.StayOption stayOption    = TransformUtil.StayOption.Local)
        {
            var prefabGo = Resources.Load <GameObject> (prefabResPath);

            return(InstantiateOrCreate(prefabGo, parent, stayOption));
        }
コード例 #2
0
        public static T InstantiateOrCreate <T> (GameObject prefabGo, Transform parent = null,
                                                 TransformUtil.StayOption stayOption   = TransformUtil.StayOption.Local)
            where T : Component
        {
            var go = InstantiateOrCreate(prefabGo, parent, stayOption);

            return(GetOrAddComponent <T> (go));
        }
コード例 #3
0
        public static GameObject InstantiateOrCreate(GameObject prefabGo, Transform parent = null,
                                                     TransformUtil.StayOption stayOption   = TransformUtil.StayOption.Local)
        {
            if (prefabGo != null)
            {
                return(Instantiate(prefabGo, parent, stayOption));
            }

            var go = new GameObject();

            TransformUtil.SetParent(go.transform, parent, stayOption);
            return(go);
        }
コード例 #4
0
        public static GameObject Instantiate(GameObject prefabGo, Transform parent = null,
                                             TransformUtil.StayOption stayOption   = TransformUtil.StayOption.Local)
        {
            if (prefabGo == null)
            {
                return(null);
            }

            switch (stayOption)
            {
            case TransformUtil.StayOption.Local:
                return(Object.Instantiate(prefabGo, parent, false));

            case TransformUtil.StayOption.World:
                return(Object.Instantiate(prefabGo, parent, true));

            default:             // Reset
                var go = Object.Instantiate(prefabGo, parent, false);
                TransformUtil.Reset(go.transform);
                return(go);
            }
        }
コード例 #5
0
        public static T Instantiate <T> (T prefabCom, Transform parent = null, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
            where T : Component
        {
            if (prefabCom == null)
            {
                return(null);
            }

            switch (stayOption)
            {
            case TransformUtil.StayOption.Local:
                return(Object.Instantiate(prefabCom, parent, false));

            case TransformUtil.StayOption.World:
                return(Object.Instantiate(prefabCom, parent, true));

            default:             // Reset
                var com = Object.Instantiate(prefabCom, parent, false);
                TransformUtil.Reset(com.transform);
                return(com);
            }
        }
コード例 #6
0
        public static T InstantiateOrCreate <T> (T prefabCom, Transform parent = null, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
            where T : Component
        {
            if (prefabCom != null)
            {
                return(Instantiate(prefabCom, parent, stayOption));
            }

            return(InstantiateOrCreate <T> ((GameObject)null, parent, stayOption));
        }
コード例 #7
0
        public static T Instantiate <T> (string prefabResPath, Transform parent = null, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
            where T : Component
        {
            var prefabGo = Resources.Load <GameObject> (prefabResPath);

            return(Instantiate <T> (prefabGo, parent, stayOption));
        }
コード例 #8
0
        public static T Instantiate <T> (GameObject prefabGo, Transform parent = null, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
            where T : Component
        {
            if (prefabGo == null)
            {
                return(null);
            }

            var prefabCom = prefabGo.GetComponent <T> ();

            return(Instantiate(prefabCom, parent, stayOption));
        }
コード例 #9
0
 public static void SetParent(this Transform trans, Transform parent, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
 {
     TransformUtil.SetParent(trans, parent, stayOption);
 }