public void Despawn(Production production, bool isDestroy) { ActivatedSet.Remove(production); if (isDestroy) { GameObject.Destroy(production.Obj); } else { production.Obj.SetActive(false); RecycledSet.Add(production); } }
private Production CreateNewInstance(Transform parent, float lifeTime) { GameObject obj = GameObject.Instantiate(prefab, parent); Production production = new Production(this) { Obj = obj, BornTime = GameMain.Instance.GameTime, LifeTime = lifeTime, Index = CurIndex++ }; obj.SetActive(true); ActivatedSet.Add(production); return(production); }
private Production Reuse(float lifeTime) { Production production = RecycledSet.Min; //必须先执行移除再赋值,因为移除的时候会对比Hash值,先赋值的话Hash会变 RecycledSet.Remove(production); production.BornTime = GameMain.Instance.GameTime; production.LifeTime = lifeTime; production.Obj.SetActive(true); ActivatedSet.Add(production); return(production); }