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)); }
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)); }
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); }
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); } }
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); } }
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)); }
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)); }
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); }