public ObjectPoolData(ObjectPoolName name, APoolable prefab, int initialCapacity, RootBase root) { this.name = name; this.prefab = prefab; this.initialCapacity = initialCapacity; this.Root = root; }
//--------------------------------------------------------------------------------------------------------------- public static AWorldUIObject Instance(ObjectPoolName PoolName, Vector3 destination) { if (PoolName == ObjectPoolName.ERROR) { return(null); } AWorldUIObject UIObj = Game.PoolManager.Pop <AWorldUIObject>(PoolName, Game.Canvas.transform); if (UIObj.IsNullOrPooled()) { Debug.LogError("Unexpected Error. Can't pop UI obj."); return(null); } if (UIObj.transform is RectTransform rt) { rt.MoveToWorldPosition(destination, Game.Canvas); } else { UIObj.transform.MoveTo(destination); Debug.LogError("Unexpected Error. Poped object is not Unity UI. Cant."); } return(UIObj); }
//--------------------------------------------------------------------------------------------------------------- /// <summary> /// Works as "Instantiate" for standard prefab, but instead moves poolable Object from the container or creates new if there is no more poolable objects left. /// You need to clean the object for future use in OnReturnedToPool OR OnPop. /// </summary> public APoolable Pop(ObjectPoolName name, Transform NewParent) { APoolable result = this.Pop(name); result.gameObject.SetActive(true); result.transform.SetParent(NewParent); return(result); }
//--------------------------------------------------------------------------------------------------------------- public static PopedUIMsg Pop(ObjectPoolName PoolName, Vector3 destination) { PopedUIMsg msg = PopedUIMsg.Instance(PoolName, destination) as PopedUIMsg; if (msg == null) { return(msg); } msg.Animate(); return(msg); }
//--------------------------------------------------------------------------------------------------------------- public T Pop <T>(ObjectPoolName name, Transform NewParent, Vector3?LocalPosition = null) where T : APoolable { T result = this.Pop <T>(name); result.gameObject.SetActive(true); result.transform.SetParent(NewParent); if (LocalPosition != null) { result.transform.localPosition = (Vector3)LocalPosition; } return(result); }
//--------------------------------------------------------------------------------------------------------------- public T Pop <T>(ObjectPoolName name) where T : APoolable { return((T)GetPool(name).Pop()); }
/// <summary> /// Does NOT set object active. /// </summary> /// <param name="name"></param> /// <returns></returns> //--------------------------------------------------------------------------------------------------------------- public APoolable Pop(ObjectPoolName name) { return(GetPool(name).Pop()); }
//--------------------------------------------------------------------------------------------------------------- public ObjectPool GetPool(ObjectPoolName name) { return(pools.Find(p => p.data.name == name)); }
//--------------------------------------------------------------------------------------------------------------- private void DestroyPool(ObjectPoolName name) { pools.FindAll(p => p.data.name == name).ForEach(p => Destroy(p.parent)); pools.RemoveAll(p => p.data.name == name); }