wangguan
2020-12-11 d4eadbf1bac0dba434d4c35e60e643143e770faa
Assets/Scripts/TowerDefense/Level/EndlessWave.cs
@@ -6,6 +6,7 @@
using TowerDefense.Agents;
using TowerDefense.Agents.Data;
using TowerDefense.Nodes;
using TowerDefense.UI.HUD;
namespace TowerDefense.Level
{
@@ -62,11 +63,6 @@
        protected bool isWaveStoped = false;
        /// <summary>
        /// 暂停兵线出怪
        /// </summary>
        protected bool isWavePaused = false;
        /// <summary>
        /// 怪物刷新速度的缩放.
        /// </summary>
        protected float spawnTimeScale = 1.0f;
@@ -91,13 +87,9 @@
            isWaveStoped = false;
            spawnedEnemies = 0;
            SpawnCurrent();
            spawnTimer = new RepeatingTimer(data.Config.interval / 1000f, SpawnCurrent);
            if (!isWavePaused)
            {
                SpawnCurrent();
                StartTimer(spawnTimer);
            }
            StartTimer(spawnTimer);
        }
        /// <summary>
@@ -112,21 +104,33 @@
        public void PauseWave()
        {
            PauseTimer(spawnTimer);
            isWavePaused = true;
        }
        public void RestartWave()
        {
            StartTimer(spawnTimer);
            isWavePaused = false;
            if (spawnedEnemies == 0)
                SpawnCurrent();
            if (spawnTimer != null)
                StartTimer(spawnTimer);
        }
        protected virtual void SpawnCurrent()
        {
            if (isWaveStoped || isWavePaused) return;
            if (EndlessGameUI.instance.state == EndlessGameUI.State.GameOver)
            {
                StopWave();
                // 让所有兵线上已经生成的所有agent播放一个死亡动画然后销毁
                WaveLineAgentInsMgr[] waveLineAgentIns = AgentInsManager.instance.GetWaveLineList();
                for (int i = 0; i < waveLineAgentIns.Length; ++i)
                {
                    while (waveLineAgentIns[i].listAgent.Count > 0)
                    {
                        waveLineAgentIns[i].listAgent[0].PlayDeath();
                    }
                }
                return;
            }
            if (isWaveStoped) return;
            if (!TrySetupNextSpawn())
            {
@@ -161,9 +165,9 @@
            // 木属性小怪需要同时生成两个,先这么写吧(WTF)
            bool isDouble = enemyData.resource == 103;
            Poolable agentPoolable = Poolable.TryGetPoolable<Poolable>(AgentConfigurationList[index].agentPrefab.gameObject);
            Agent newAgent = agentPoolable.GetComponent<Agent>();
            GameObject prefab = Resources.Load<GameObject>($"Prefabs/Enemies/{enemyData.resource}");
            GameObject obj = Instantiate(prefab);
            Agent newAgent = obj.GetComponent<Agent>();
            newAgent.EnemyData = enemyData;
            newAgent.transform.position = StartingNode.transform.position;
@@ -185,15 +189,13 @@
            int gold = waveData.Config.b_coin * enemyData.coin_rate;
            newAgent.SetAgentData(hp, speed, gold);
            // todo 这里先填1级后面需要修改
            newAgent.healthBar.SetHealthLevel(1);
            // 加入Manager统一管理.
            AgentInsManager.instance.addAgent(newAgent);
            if (isDouble)
            {
                Poolable agentPoolable2 = Poolable.TryGetPoolable<Poolable>(AgentConfigurationList[index].agentPrefab.gameObject);
                Agent doubleAgent = agentPoolable2.GetComponent<Agent>();
                obj = Instantiate(prefab);
                Agent doubleAgent = obj.GetComponent<Agent>();
                doubleAgent.EnemyData = enemyData;
                doubleAgent.transform.position = StartingNode.transform.position;
@@ -207,17 +209,16 @@
                doubleAgent.Initialize();
                doubleAgent.SetAgentData(hp, speed, gold);
                doubleAgent.healthBar.SetHealthLevel(1);
                AgentInsManager.instance.addAgent(doubleAgent);
            }
        }
        /// <summary>
      /// 从Tower的AttributeId获取到怪物的数据
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      protected List<int> GetMonsterDataFromAttributeId(int id)
        /// 从Tower的AttributeId获取到怪物的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        protected List<int> GetMonsterDataFromAttributeId(int id)
        {
            geminfo tgem = new geminfo();
            if (JsonDataCenter.gemInfoDic.TryGetValue(id, out tgem))
@@ -243,7 +244,7 @@
        }
        /// <summary>
        /// 暂时先这么处理 cx test
        /// 暂时先这么处理
        /// </summary>
        /// <param name="resId">endless_enemy表的资源id</param>
        /// <returns>所有可选的agent列表的索引</returns>