/// <summary> /// 创建EnemyObject /// </summary> /// <param name="type">类型</param> /// <returns></returns> public EnemyObjectBase CreateEnemyObjectByType(eEnemyObjectType type) { EnemyObjectBase enemyObj = null; Stack <EnemyObjectBase> _stack; if (_enemyObjectsPool.TryGetValue(type, out _stack)) { if (_stack.Count > 0) { return(_stack.Pop()); } } else { _stack = new Stack <EnemyObjectBase>(); _enemyObjectsPool.Add(type, _stack); } switch (type) { case eEnemyObjectType.Fairy: enemyObj = new Fairy(); break; case eEnemyObjectType.SpinningEnemy: enemyObj = new SpinningEnemy(); break; } return(enemyObj); }
public override void Clear() { EnemyManager.GetInstance().RestoreEnemyObjectToPool(_enemyObj); _cfg = null; _enemyObj = null; _dropItemDatas = null; base.Clear(); }
public void Init(EnemyCfg cfg) { _cfg = cfg; _enemyObj = EnemyManager.GetInstance().CreateEnemyObjectByType(cfg.type); _enemyObj.SetEnemyAni(cfg.aniId); _enemyGo = _enemyObj.GetObject(); _enemyTf = _enemyGo.transform; SetCollisionParams(cfg.collisionHalfWidth, cfg.collisionHalfWidth); _dropItemDatas = null; _checkOutOfBorder = true; }
/// <summary> /// 将enemyObject缓存回对象池 /// </summary> /// <param name="enemyObject"></param> public void RestoreEnemyObjectToPool(EnemyObjectBase enemyObject) { if (enemyObject != null) { enemyObject.Clear(); Stack <EnemyObjectBase> _stack; if (_enemyObjectsPool.TryGetValue(enemyObject.GetObjectType(), out _stack)) { _stack.Push(enemyObject); } else { Logger.Log("Restore EnemyObject Fail!Reason : stack of type " + enemyObject.GetObjectType() + " is not found!"); } } }