chenxin
2020-11-06 67f6f473143047b0b0c9ba51791ff5747972f076
Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
@@ -18,6 +18,8 @@
    {
        public BubbleBombAgent Agent { get; set; }
        public GameObject obj { get; set; }
        /// <summary>
        /// 需要被攻击的次数,攻击 * 次炸弹才会被销毁
        /// </summary>
@@ -73,6 +75,9 @@
        /// </summary>
        public bool IsAttack { get; set; }
        /// <summary>
        /// 延迟产生伤害时间
        /// </summary>
        public float AttackTime { get; set; }
    }
@@ -96,6 +101,17 @@
        protected List<BubbleBombConfig> bubbleBombList;
        protected System.Random random;
        /// <summary>
        /// 泡泡炸弹对象池
        /// </summary>
        protected List<GameObject> bubbleBombPool;
        protected int capacity = 10;
        private int getCount;
        private int recycleCount;
        /// <summary>
        /// 释放技能
@@ -132,13 +148,11 @@
        /// </summary>
        protected void SpawnOnTunel()
        {
            // 有可能只在某一条赛道生成,也有可能在所有赛道生成
            List<int> tunelIdList = GetTunelList();
            GameObject prefab = Resources.Load<GameObject>(prefabPath);
            for (int i = 0; i < tunelIdList.Count; ++i)
            {
                GameObject obj = Poolable.TryGetPoolable(prefab);
                GameObject obj = GetBubbleBomb();
                BubbleBombAgent bubbleBomb = obj.GetComponent<BubbleBombAgent>();
                // 分配唯一id
@@ -150,12 +164,13 @@
                // 出生位置
                Vector3 spawnPosition = EndlessLevelManager.instance.GetTunelWorldPosition(tunelIdList[i], (EndlessBossSkillTunelType)SkillData.target[1]);
                bubbleBomb.transform.position = spawnPosition;
                obj.transform.position = spawnPosition;
                bubbleBomb.PlayNormalEffect();
                AgentInsManager.instance.addAgent(bubbleBomb);
                BubbleBombConfig config = new BubbleBombConfig();
                config.Agent = bubbleBomb;
                config.obj = obj;
                config.NeedAttackCount = (int)SkillData.effect[0];
                config.StartPosition = spawnPosition;
                config.TargetPosition = EndlessLevelManager.instance.GetHomeBasePosition(tunelIdList[i]);
@@ -209,6 +224,7 @@
        {
            base.Clear();
            ClearBubbleBomb();
            ClearBubbleBombPool();
        }
        /// <summary>
@@ -222,10 +238,8 @@
                bubbleBombList[i].Agent.StopNormalEffect();
                bubbleBombList[i].Agent.StopExplodeEffect();
                if (!bubbleBombList[i].Agent.bInDeathState)
                    AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
                AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                RecycleBubbleBomb(bubbleBombList[i].obj);
            }
            bubbleBombList.Clear();
@@ -236,6 +250,65 @@
            base.Init();
            Debug.Log("--------------------- 泡泡炸弹技能初始化 ---------------------");
            bubbleBombList = new List<BubbleBombConfig>();
            bubbleBombPool = new List<GameObject>();
            GameObject prefab = Resources.Load<GameObject>(prefabPath);
            for (int i = 0; i < capacity; ++i)
            {
                GameObject obj = GameObject.Instantiate(prefab);
                obj.SetActive(false);
                bubbleBombPool.Add(obj);
            }
        }
        /// <summary>
        /// 从对象池中获取一个炸弹
        /// </summary>
        protected GameObject GetBubbleBomb()
        {
            GameObject ret;
            if (bubbleBombPool.Count > 0)
            {
                ret = bubbleBombPool[0];
                bubbleBombPool.Remove(bubbleBombPool[0]);
            }
            else
            {
                GameObject prefab = Resources.Load<GameObject>(prefabPath);
                ret = GameObject.Instantiate(prefab);
            }
            ret.SetActive(true);
            return ret;
        }
        /// <summary>
        /// 回收泡泡炸弹
        /// </summary>
        /// <param name="obj"></param>
        protected void RecycleBubbleBomb(GameObject obj)
        {
            if (obj != null)
            {
                obj.SetActive(false);
                bubbleBombPool.Add(obj);
            }
        }
        /// <summary>
        /// 清空泡泡炸弹对象池
        /// </summary>
        protected void ClearBubbleBombPool()
        {
            while (bubbleBombPool.Count > 0)
            {
                GameObject obj = bubbleBombPool[0];
                bubbleBombPool.Remove(obj);
                GameObject.Destroy(obj);
            }
        }
        protected override void AddEvent()
@@ -352,10 +425,9 @@
            for (int i = 0; i < bubbleBombList.Count; ++i)
            {
                if (bubbleBombList[i] == null) continue;
                BubbleBombConfig config = bubbleBombList[i];
                // 泡泡炸弹已经触发了攻击,延时一会过后掉爱心
                if (config.IsAttack)
                {
                    config.AttackTime -= deltaTime;
@@ -377,7 +449,8 @@
                    if (config.DestroyTime <= 0)
                    {
                        bubbleBombList[i].Agent.Reset();
                        Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
                        RecycleBubbleBomb(bubbleBombList[i].obj);
                        AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                        bubbleBombList.Remove(bubbleBombList[i]);
                        --i;
                    }
@@ -400,11 +473,11 @@
                }
                // 更新移动
                if (!config.Agent.bInDeathState && config.Agent.CanMove)
                if (config.Agent != null && !config.Agent.bInDeathState && config.Agent.CanMove)
                {
                    Vector3 pos = config.Agent.transform.position;
                    Vector3 pos = config.obj.transform.position;
                    pos.z -= deltaTime * config.MoveSpeed;
                    config.Agent.transform.position = pos;
                    config.obj.transform.position = pos;
                    if (pos.z <= config.TargetPosition.z)
                    {