Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
 public static void SetParent(this Transform trans, Transform parent, TransformUtil.StayOption stayOption = TransformUtil.StayOption.Local)
 {
     TransformUtil.SetParent(trans, parent, stayOption);
 }