/// <summary> /// 每次调用会把可回收的对象重新存入对象池 /// </summary> public void CheckRestore() { for (int i = 0; i < checkList.Count; i++) { IAutoRestoreObject <T> check = checkList[i]; IAutoRestoreChecker autoRestoreChecker = check.Restore; if (autoRestoreChecker != null && autoRestoreChecker.Restore) { baseObjectPool.Restore(check.Get()); checkList.RemoveAt(i); i--; } } }
public void Update(float time) { if (num == 0) { return; } if (time >= nextCanCastTime) { nextCanCastTime = time + duration; num--; IAutoRestoreObject <GameObject> restoreObject = pool.Take(); GameObject go = restoreObject.Get(); go.transform.position = position; TestBullet bullet = go.GetComponent <TestBullet>(); bullet.Init(boomUnitForce, boomUnitInitLife, boomUnitVelocity, delegate(GameObject gameObject) { }, currentAngle); restoreObject.Restore = bullet; currentAngle += angle; } }
private void Update() { if (Input.GetKey(KeyCode.J) && Time.time >= nextCanCastTime) { nextCanCastTime = Time.time + castDuration; foreach (var tran in firePoint) { IAutoRestoreObject <GameObject> restoreObj = null; GameObject go = null; //从迸发特效对象池中获取 restoreObj = burstEffectPool.Take(); //获取对象实体 go = restoreObj.Get(); go.transform.position = tran.position; TimeBaseChecker checker = go.GetComponent <TimeBaseChecker>(); if (checker == null) { checker = go.AddComponent <TimeBaseChecker>(); } checker.Init(0.5f); //特效时间大概是0.3秒。我们就让他0.5秒回收吧。这个暂时不需要很精确。 restoreObj.Restore = checker; //将回收检查器用于对象 //从子弹特效对象池中取 restoreObj = pool.Take(); //获取子弹GameObject go = restoreObj.Get(); go.transform.position = tran.position; TestBullet bullet = go.GetComponent <TestBullet>(); bullet.Init(bulletForce, bulletLife, bulletVelocity, delegate(GameObject obj) { }); restoreObj.Restore = bullet; } } if (Input.GetKey(KeyCode.U) && Time.time >= nextCanCastTime) { nextCanCastTime = Time.time + castDuration; int[] angles = { -30, -20, -10, 0, 10, 20, 30 }; for (int i = 0; i < angles.Length; i++) { int angle = angles[i]; IAutoRestoreObject <GameObject> restoreObj = null; GameObject go = null; //从迸发特效对象池中获取 restoreObj = burstEffectPool.Take(); //获取对象实体 go = restoreObj.Get(); go.transform.position = _CacheTransform.position; TimeBaseChecker checker = go.GetComponent <TimeBaseChecker>(); if (checker == null) { checker = go.AddComponent <TimeBaseChecker>(); } checker.Init(0.5f); //特效时间大概是0.3秒。我们就让他0.5秒回收吧。这个暂时不需要很精确。 restoreObj.Restore = checker; //将回收检查器用于对象 //从子弹特效对象池中取 restoreObj = pool.Take(); //获取子弹GameObject go = restoreObj.Get(); go.transform.position = _CacheTransform.position; TestBullet bullet = go.GetComponent <TestBullet>(); bullet.Init(bulletForce, bulletLife, bulletVelocity, delegate(GameObject obj) { }, angle); restoreObj.Restore = bullet; } } if (Input.GetKey(KeyCode.K)) { //从子弹特效对象池中取 IAutoRestoreObject <GameObject> restoreObj = pool.Take(); //获取子弹GameObject GameObject go = restoreObj.Get(); go.transform.position = _CacheTransform.position; TestBullet bullet = go.GetComponent <TestBullet>(); bullet.Init(boomForce, boomLife, boomVelocity, CreateBoom); restoreObj.Restore = bullet; } TryMovePlane(); ProcessBooms(); }
public void Restore(IAutoRestoreObject <T> t) { baseObjectPool.Restore(t.Get()); checkList.Remove(t); }