private void PrepareBeforeInsertToAvailable(SmartPoolObjectInstance obj) { handler.PreReturnToPool(this, obj); obj.IsRented = false; #if UNITY_EDITOR obj.transform.parent = Container.transform; #endif }
void OnParticleSystemStopped() { if (poolInst == null) { poolInst = GetComponent <SmartPoolObjectInstance>(); } poolInst.ReturnToPool(); }
public override void PreReturnToPool(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { var p = obj.GetComponent <ParticleSystem>(); if (p != null) { p.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); } }
//prep object for return private SmartPoolObjectInstance PrepareForReturnToUser(SmartPoolObjectInstance obj) { if (obj != null) { obj.IsRented = true; #if UNITY_EDITOR obj.gameObject.transform.parent = null; #endif handler.PreReturnToUser(this, obj); } return(obj); }
public override void PreReturnToUser(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { var p = obj.GetComponent <ParticleSystem>(); if (p != null) { p.time = 0; if (!p.isPlaying) { p.Play(); } } }
//Get public SmartPoolObjectInstance GetInstance() { SmartPoolObjectInstance retval = null; if (availableInstances.Count == 0) { //notify of request when none avail handler.RequestWhenNoneAvail(this); } if (availableInstances.Count > 0) { retval = availableInstances.Pop(); unavailableInstances.AddLast(retval); } return(PrepareForReturnToUser(retval)); }
//Return public void ReturnToPool(SmartPoolObjectInstance obj) { var res = unavailableInstances.Remove(obj); if (res) { PrepareBeforeInsertToAvailable(obj); availableInstances.Push(obj); } //TODO these elses don't need to be in builds else { if (availableInstances.Contains(obj)) { Debug.LogWarning("Attempted to return GO that is already marked as available"); } else { Debug.LogError("Attempted to return GO that doesn't belong to this pool"); } } }
private void PrepareAfterInstantiation(SmartPoolObjectInstance obj) { obj.Pool = this; handler.PostInstantiate(this, obj); }
public override void PostInstantiate(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { }
public virtual void PreReturnToPool(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { obj.gameObject.SetActive(false); }
public virtual void PostInstantiate(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { }
public virtual void PreReturnToUser(SmartPool prefabSmartPool, SmartPoolObjectInstance obj) { obj.transform.CopyLocalsFrom(prefabSmartPool.Prefab.transform); obj.gameObject.SetActive(true); }
public virtual void DestroyGO(SmartPoolObjectInstance obj) { UnityEngine.Object.Destroy(obj.gameObject); }