From fc40dea934140005aeb62ac1e4ec1e613cc44a0c Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Fri, 06 Nov 2020 20:33:04 +0800
Subject: [PATCH] 修改登录页面

---
 Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs |  105 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 87 insertions(+), 18 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs b/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
index 574bce8..c459c66 100644
--- a/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
+++ b/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
@@ -4,8 +4,6 @@
 using UnityEngine;
 using TowerDefense.Agents;
 using TowerDefense.Level;
-using DG.Tweening;
-using MoreMountains.NiceVibrations;
 
 /**
  * 泡泡炸弹
@@ -17,6 +15,8 @@
     public class BubbleBombConfig
     {
         public BubbleBombAgent Agent { get; set; }
+
+        public GameObject obj { get; set; }
 
         /// <summary>
         /// 需要被攻击的次数,攻击 * 次炸弹才会被销毁
@@ -73,6 +73,9 @@
         /// </summary>
         public bool IsAttack { get; set; }
 
+        /// <summary>
+        /// 延迟产生伤害时间
+        /// </summary>
         public float AttackTime { get; set; }
     }
 
@@ -96,6 +99,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 +146,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 +162,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 +222,7 @@
         {
             base.Clear();
             ClearBubbleBomb();
+            ClearBubbleBombPool();
         }
 
         /// <summary>
@@ -222,10 +236,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 +248,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 +423,9 @@
 
             for (int i = 0; i < bubbleBombList.Count; ++i)
             {
-                if (bubbleBombList[i] == null) continue;
-
                 BubbleBombConfig config = bubbleBombList[i];
 
+                // 泡泡炸弹已经触发了攻击,延时一会过后掉爱心
                 if (config.IsAttack)
                 {
                     config.AttackTime -= deltaTime;
@@ -363,8 +433,6 @@
                     if (config.AttackTime <= 0)
                     {
                         EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 3);
-                        ViewPortAdj.instance.cachedCamera.DOShakePosition(0.25f, 1.5f, 4);
-                        MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
                         config.IsAttack = false;
                     }
                 }
@@ -377,7 +445,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 +469,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)
                     {

--
Gitblit v1.9.1