wgl 5 месяцев назад
Родитель
Сommit
e0f479d87d

+ 8 - 14
ActionTowerDefense/Assets/Scenes/Game.unity

@@ -1519,9 +1519,9 @@ MonoBehaviour:
   soldierProbabilities:
   - soldier: 0
     probabilityID: 0
-  - soldier: 1
+  - soldier: 0
     probabilityID: 0
-  - soldier: 2
+  - soldier: 0
     probabilityID: 0
 --- !u!114 &490846388
 MonoBehaviour:
@@ -12245,7 +12245,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!224 &741372828
 RectTransform:
   m_ObjectHideFlags: 0
@@ -12296,8 +12296,8 @@ MonoBehaviour:
       m_Calls: []
   m_text: CurLevelName
   m_isRightToLeft: 0
-  m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
-  m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
+  m_fontAsset: {fileID: 11400000, guid: 39a7404a24ab897418249c0d649949a8, type: 2}
+  m_sharedMaterial: {fileID: -1504297583073342176, guid: 39a7404a24ab897418249c0d649949a8, type: 2}
   m_fontSharedMaterials: []
   m_fontMaterial: {fileID: 0}
   m_fontMaterials: []
@@ -20889,7 +20889,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: -688, y: -504}
+  m_AnchoredPosition: {x: -688, y: -463.7}
   m_SizeDelta: {x: 485.776, y: 50}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1634269188
@@ -21094,9 +21094,8 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 0b88ebc6e4d3df6439f5464df5614ec5, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  createCharacter: []
-  mapsAsset: {fileID: 11400000, guid: bbf7388a54f14f842b7aecb67d709046, type: 2}
-  levelSelect: {fileID: 1714821088}
+  createdEnemy: 
+  idRange: {x: 0, y: 0}
 --- !u!114 &1714821088
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -21111,11 +21110,6 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   curLevel: {fileID: 741372831}
   curLevelID: 2
-  levelConfig:
-  - levelName: Level_Normal_A_000_000
-  - levelName: Level_Normal_A_000_001
-  - levelName: Level_Normal_A_000_002
-  - levelName: "Level_Normal_A_000_003\u5B88\u5854"
 --- !u!114 &1714821089
 MonoBehaviour:
   m_ObjectHideFlags: 0

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -31,7 +31,7 @@ public class Enemy : MoveCharacter
     [Header("敌方单位属性")]
     [LabelText("击杀提供的经验值")]
     public int exp;
-    public int id;
+    public string name;
     public int baseSortingOrder;
     int sortingOrder = 0;
     public bool isBack = false; //往反方向走

+ 128 - 145
ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

@@ -5,32 +5,17 @@ using cfg;
 using System.Threading.Tasks;
 using Base.Common;
 using System.Linq;
-using System;
-
-[Serializable]
-public struct CreaterControl
-{
-    public bool isCreated;
-    public GameMapTile tile;
-    public GameMapLayer mapLayer;
-    public SpawnTime spawnTime;
-    public int waveStartTime;
-    public List<Vector3> pos;
-}
-
 
 public class EnemyCreater : MonoBehaviour
 {
     public static EnemyCreater instance;
-    public List<CreaterControl> createCharacter = new();
-    public Dictionary<int, List<Enemy>> enemyDic;
-    public Dictionary<int, List<GameObject>> buildingDic;
-    private LevelSelect.Level curLevel;
-    public GameMapsAsset mapsAsset;
-
-    //import
-    public LevelSelect levelSelect;
-
+    [SerializeField] public List<SingleCreateEnemyConfig> cfgCreateEnemy;
+    public List<bool> createdEnemy;
+    public List<List<float>> createEnemyTime = new();
+    public Dictionary<string, List<Enemy>> enemyDic;
+    public Dictionary<string, List<GameObject>> buildingDic;
+    private int curLevel;
+    public Vector2Int idRange;  //当前关卡为出怪表[x,y]行
 
     private void Awake()
     {
@@ -43,15 +28,54 @@ public class EnemyCreater : MonoBehaviour
             DestroyImmediate(gameObject);
             return;
         }
-        enemyDic = new Dictionary<int, List<Enemy>>();
-        buildingDic = new Dictionary<int, List<GameObject>>();
+        enemyDic = new Dictionary<string, List<Enemy>>();
+        buildingDic = new Dictionary<string, List<GameObject>>();
     }
 
     private void Start()
     {
-        levelSelect = GetComponent<LevelSelect>();
-        curLevel = GetComponent<LevelSelect>().levelConfig[levelSelect.curLevelID - 1];
-        LoadMapAsset(0);
+        curLevel = GetComponent<LevelSelect>().curLevelID;
+        cfgCreateEnemy = GameManager.instance.allCfgData.CfgCreateEnemy.DataList;
+        createdEnemy = new List<bool>();
+        float waveTime = 0;
+        int id = 0;
+        int mapId = 1;
+        int start = -1;
+        int end = -1;
+        bool haveStart = false;
+        for(int i = 0; i < cfgCreateEnemy.Count; i++)
+        {
+            if (cfgCreateEnemy[i].WaveID == -1)
+            {
+                if (curLevel == mapId)
+                {
+                    haveStart = true;
+                    start = i;
+                }
+                else if (curLevel + 1 == mapId)
+                {
+                    end = i - 1;
+                    break;
+                }
+                mapId++;
+                continue;
+            }
+            if (haveStart)
+            {
+                createdEnemy.Add(false);
+                if(id != cfgCreateEnemy[i].WaveID)
+                {
+                    waveTime += cfgCreateEnemy[i].WaveTime;
+                    id = cfgCreateEnemy[i].WaveID;
+                }
+                createEnemyTime.Add(new List<float> { waveTime + cfgCreateEnemy[i].StartTime, waveTime + cfgCreateEnemy[i].EndTime });
+            }
+        }
+        if(end == -1)
+        {
+            end = cfgCreateEnemy.Count - 1;
+        }
+        idRange = new Vector2Int(start, end);
 
         //把所有怪物prefab生成一遍防止后面初次生成卡顿
         //foreach (var item in createCharacter)
@@ -63,82 +87,47 @@ public class EnemyCreater : MonoBehaviour
         //}
     }
 
-
-
-    public void LoadMapAsset(int mapIdx)
+    public void OnGameTimeChange(float gameTime)
     {
-        GameMap map = mapsAsset.maps[mapIdx];
-
-        int startTime = 0;
-
-        for (int i = 0; i < map.layers.Count(); i++)
+        int waveId = -1;
+        int waveIndex = -1;
+        for (int i = idRange[0] + 1; i <= idRange[1]; i++)
         {
-            GameMapLayer layer = map.layers[i];
-            List<SpawnTime> spawnTimes = layer.spawnTimes;
-            for(int j = 0; j < spawnTimes.Count; j++)
+            int id = i - idRange[0] - 1;
+            if(waveId != cfgCreateEnemy[i].WaveID)
             {
-                SpawnTime spawnTime = layer.spawnTimes[j];
-                CreaterControl createrControl = new();
-                createrControl.isCreated = false;
-                GameMapTile t = mapsAsset.tileAsset.GetTile(spawnTime.id);
-                createrControl.tile = t;
-                createrControl.spawnTime = spawnTime;
-                createrControl.pos = new List<Vector3>();
-                for (int k = 0; k < spawnTime.pos.Count; k++)
-                {
-
-                    int posInt = spawnTime.pos[k];
-                    float posX = posInt % map.width;
-                    posX = posX + UnityEngine.Random.Range(-t.radius.x / 2, t.radius.x / 2);
-                    float posY = posInt / map.width;
-                    posY = posY + UnityEngine.Random.Range(-t.radius.y / 2, t.radius.y / 2);
-                    posY = posY < 0 ? 0 : posY;
-                    createrControl.pos.Add(new Vector3(posX, posY, 0));
-                }
-                createrControl.waveStartTime = startTime;
-                createrControl.mapLayer = layer;
-                createCharacter.Add(createrControl);
+                waveId = cfgCreateEnemy[i].WaveID;
+                waveIndex = i;
             }
-            startTime += map.layers[i].duration;
-        }
-    }
-
-    public void OnGameTimeChange(float gameTime)
-    {
-        for (int i = 0; i < createCharacter.Count; i++)
-        {
-            if (!createCharacter[i].isCreated && createCharacter[i].spawnTime.startTime + createCharacter[i].waveStartTime <= gameTime)
+            if (!createdEnemy[id] && createEnemyTime[id][0] <= gameTime)
             {
-                CreaterControl createrControl = createCharacter[i];
-                createrControl.isCreated = true;
-                createCharacter[i] = createrControl;
-
-                StartCreateEnemy(createCharacter[i]);
+                createdEnemy[id] = true;
+                StartCreateEnemy(cfgCreateEnemy[i], cfgCreateEnemy[waveIndex]);
             }
         }
+        
     }
 
-    public async void StartCreateEnemy(CreaterControl createrControl)
+    public async void StartCreateEnemy(SingleCreateEnemyConfig cfgCreateEnemy, SingleCreateEnemyConfig cfgCreateWave)
     {
-        SpawnTime spawnTime = createrControl.spawnTime;
-        for (int i = 0; i < spawnTime.num; i++)
+        for (int i = 0; i < cfgCreateEnemy.Count; i++)
         {
             if (!instance)
             {
                 return;
             }
-            GameMapLayer gameMapLayer = createrControl.mapLayer;
-            for(int j= 0; j < createrControl.pos.Count; j++)
+            for(int j= 0; j < cfgCreateEnemy.Position.Count; j+=2)
             {
-                CreateEnemy(createrControl.tile, createrControl.pos[j], gameMapLayer.Hp, gameMapLayer.moveSpeed, gameMapLayer.attack);
+                Vector3 pos = new Vector3(cfgCreateEnemy.Position[j], cfgCreateEnemy.Position[j+1],0);
+                CreateEnemy(cfgCreateEnemy, cfgCreateWave, pos, true);
 
             }
            
-            if(spawnTime.num == 1)
+            if(cfgCreateEnemy.Count == 1)
             {
                 return;
             }
-            float TimeInterval = (float)(spawnTime.endTime - spawnTime.startTime) / (spawnTime.num - 1);
+            float TimeInterval = (float)(cfgCreateEnemy.EndTime - cfgCreateEnemy.StartTime) / (cfgCreateEnemy.Count - 1);
             if (TimeInterval < 0)
             {
                 return;
@@ -148,77 +137,71 @@ public class EnemyCreater : MonoBehaviour
     }
 
 
-    public GameObject CreateEnemy(GameMapTile gameMapTile, Vector3 pos, float hpRatio, float moveSpeedRatio, float attackRatio, bool active = true)
+    public GameObject CreateEnemy(SingleCreateEnemyConfig cfgCreateEnemy, SingleCreateEnemyConfig cfgCreateWave, Vector3 pos, bool active = false)
     {
-        string enemyStr = $"Prefab/{gameMapTile.type}/{gameMapTile.ch}";
+        SingleEnemyConfig cfgEnemy = GameManager.instance.allCfgData.CfgEnemy.Get(cfgCreateEnemy.EnemyName);
+        string enemyStr = $"Prefab/{cfgEnemy.Type}/{cfgEnemy.EnemyPrefab}";
         GameObject enemyObj = Util.Instantiate(enemyStr, pos, active: active);
-        Parameter parameter = gameMapTile.parameter;
         AttackInfo attackInfo;
-        switch (gameMapTile.type)
+        if(cfgEnemy.Type == "Tower")
         {
-            case GameMapTile.Type.Tower:
-                EnemyTower enemyTower = enemyObj.GetComponent<EnemyTower>();
-                Tower tower = enemyObj.GetComponent<Tower>();
-                if (enemyTower != null)
-                {
-                    enemyTower.id = gameMapTile.id;
+            EnemyTower enemyTower = enemyObj.GetComponent<EnemyTower>();
+            Tower tower = enemyObj.GetComponent<Tower>();
+            if (enemyTower != null)
+            {
+                enemyTower.name = cfgEnemy.Name;
 
-                    enemyTower.totalHp = (int)(parameter.HP * hpRatio);
-                    enemyTower.hp = enemyTower.totalHp;
+                enemyTower.totalHp = (int)(cfgEnemy.HP * cfgCreateWave.HPRatio);
+                enemyTower.hp = enemyTower.totalHp;
 
-                    attackInfo = enemyTower.attackController.attackInfo;
-                    attackInfo.damage = (int)(parameter.Attack_march * attackRatio);
-                    enemyTower.attackController.attackInfo = attackInfo;
-                    enemyTower.Init();
-                }
-                if (tower != null)
-                {
-                    tower.id = gameMapTile.id;
+                attackInfo = enemyTower.attackController.attackInfo;
+                attackInfo.damage = (int)(cfgEnemy.AttackMarch * cfgCreateWave.AttackRatio);
+                enemyTower.attackController.attackInfo = attackInfo;
+                enemyTower.Init();
+            }
+            if (tower != null)
+            {
+                tower.name = cfgEnemy.Name;
 
-                    tower.totalHp = (int)(parameter.HP * hpRatio);
-                    tower.hp = tower.totalHp;
+                tower.totalHp = (int)(cfgEnemy.HP * cfgCreateWave.HPRatio);
+                tower.hp = tower.totalHp;
 
-                    attackInfo = tower.attackController.attackInfo;
-                    attackInfo.damage = (int)(parameter.Attack_march * attackRatio);
-                    tower.attackController.attackInfo = attackInfo;
-                    tower.Init();
-                }
-                if (!buildingDic.ContainsKey(gameMapTile.id))
-                {
-                    buildingDic.Add(gameMapTile.id, new List<GameObject>());
-                }
-                buildingDic[gameMapTile.id].Add(enemyObj);
+                attackInfo = tower.attackController.attackInfo;
+                attackInfo.damage = (int)(cfgEnemy.AttackMarch * cfgCreateWave.AttackRatio);
+                tower.attackController.attackInfo = attackInfo;
+                tower.Init();
+            }
+            if (!buildingDic.ContainsKey(cfgEnemy.Name))
+            {
+                buildingDic.Add(cfgEnemy.Name, new List<GameObject>());
+            }
+            buildingDic[cfgEnemy.Name].Add(enemyObj);
+        }
+        else if(cfgEnemy.Type == "Enemy")
+        {
+            Enemy enemy = enemyObj.GetComponent<Enemy>();
+            enemy.name = cfgEnemy.Name;
+            if (!enemyDic.ContainsKey(cfgEnemy.Name))
+            {
+                enemyDic.Add(cfgEnemy.Name, new List<Enemy>());
+            }
+            enemyDic[cfgEnemy.Name].Add(enemy);
 
-                break;
-            case GameMapTile.Type.Enemy:
-                Enemy enemy = enemyObj.GetComponent<Enemy>();
-                enemy.id = gameMapTile.id;
-                if (!enemyDic.ContainsKey(gameMapTile.id))
-                {
-                    enemyDic.Add(gameMapTile.id, new List<Enemy>());
-                }
-                enemyDic[gameMapTile.id].Add(enemy);
+            enemy.totalHp = (int)(cfgEnemy.HP * cfgCreateWave.HPRatio);
+            enemy.hp = enemy.totalHp;
+            enemy.minMoveSpeed = cfgEnemy.MinMoveSpeed * cfgCreateWave.SpeedRatio;
+            enemy.maxMoveSpeed = cfgEnemy.MaxMoveSpeed * cfgCreateWave.SpeedRatio;
 
-                enemy.totalHp = (int)(parameter.HP * hpRatio);
-                enemy.hp = enemy.totalHp;
-                enemy.minMoveSpeed = parameter.MinMoveSpeed * moveSpeedRatio;
-                enemy.maxMoveSpeed = parameter.MaxMoveSpeed * moveSpeedRatio;
-                /*
-                attackInfo = enemy.attackController.attackMethod[0].attackInfo;
-                attackInfo.damage = (int)(parameter.Attack_summon * attackRatio);
-                enemy.attackController.attackMethod[0].attackInfo = attackInfo;
-                */
-                attackInfo = enemy.attackController.attackMethod[0].attackInfo;
-                attackInfo.damage = (int)(parameter.Attack_march * attackRatio);
-                enemy.attackController.attackMethod[0].attackInfo = attackInfo;
+            attackInfo = enemy.attackController.attackMethod[0].attackInfo;
+            attackInfo.damage = (int)(cfgEnemy.AttackMarch * cfgCreateWave.AttackRatio);
+            enemy.attackController.attackMethod[0].attackInfo = attackInfo;
 
-                if (enemy.canFly)
-                {
-                    enemy.flyHeight = enemy.transform.position.y;
-                }
-                enemy.Init();
-                enemy.SetSortingOrder(enemy.baseSortingOrder + enemyDic[gameMapTile.id].Count);
-                break;
+            if (enemy.canFly)
+            {
+                enemy.flyHeight = enemy.transform.position.y;
+            }
+            enemy.Init();
+            enemy.SetSortingOrder(enemy.baseSortingOrder + enemyDic[cfgEnemy.Name].Count);
         }
         enemyObj.transform.position = pos;
         return enemyObj;
@@ -226,14 +209,14 @@ public class EnemyCreater : MonoBehaviour
 
     public void OnEnemyRecycle(Enemy enemy)
     {
-        if (!enemyDic.ContainsKey(enemy.id))
+        if (!enemyDic.ContainsKey(enemy.name))
         {
             return;
         }
-        enemyDic[enemy.id].Remove(enemy);
-        for (int i = 0; i < enemyDic[enemy.id].Count; i++)
+        enemyDic[enemy.name].Remove(enemy);
+        for (int i = 0; i < enemyDic[enemy.name].Count; i++)
         {
-            enemyDic[enemy.id][i].SetSortingOrder(enemy.baseSortingOrder + i);
+            enemyDic[enemy.name][i].SetSortingOrder(enemy.baseSortingOrder + i);
         }
     }
 

+ 1 - 1
ActionTowerDefense/Assets/Scripts/ExcelEditor.cs

@@ -7,7 +7,7 @@ using System;
 using SimpleJSON;
 
 /*ʹÓ÷½·¨
-
+    using System.IO;
     using OfficeOpenXml;
     FileInfo fileInfo = new FileInfo(filePath);
     using (ExcelPackage package = new ExcelPackage(fileInfo))

+ 23 - 14
ActionTowerDefense/Assets/Scripts/Levels/LevelSelect.cs

@@ -4,30 +4,39 @@ using UnityEngine;
 using UnityEditor;
 using UnityEngine.UI;
 using TMPro;
+using OfficeOpenXml;
+using System.IO;
 
 public class LevelSelect : MonoBehaviour
 {
     public TextMeshProUGUI curLevel;
 
-    [System.Serializable]
-    public struct Level
-    {
-        [Header("关卡名称")]
-        public string levelName;
-        //[Header("出怪表sheet几")]
-        //public int enemyExcelID;
-        //[Header("建筑生成表sheet几")]
-        //public int buildingExcelID;
-    }
+    //[System.Serializable]
+    //public struct Level
+    //{
+    //    [Header("关卡名称")]
+    //    public string levelName;
+    //    public int levelId;
+    //    //[Header("出怪表sheet几")]
+    //    //public int enemyExcelID;
+    //    //[Header("建筑生成表sheet几")]
+    //    //public int buildingExcelID;
+    //}
 
     [Header("当前关卡序号(从1开始)")]
     public int curLevelID;
 
-    [Header("所有关卡配置")]
-    public Level[] levelConfig;
+    //[Header("所有关卡配置")]
+    //public Level[] levelConfig;
 
-    private void Start()
+    private void Awake()
     {
-        curLevel.text = levelConfig[curLevelID - 1].levelName;
+        List<string> sheets = new();
+        FileInfo fileInfo = new FileInfo("Luban/Config/Datas/出怪表.xlsx");
+        using (ExcelPackage package = new ExcelPackage(fileInfo))
+        {
+            sheets = ExcelEditor.ReadExcelSheetsInfo(package);
+        }
+        curLevel.text = sheets[curLevelID - 1];
     }
 }

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Tower/EnemyTower.cs

@@ -6,7 +6,7 @@ using TMPro;
 public class EnemyTower : Character
 {
     [Header("µÐ·½Ëþ")]
-    public int id;
+    public string name;
     public float height = 8;
 
     private void Awake()

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Tower/Tower.cs

@@ -7,7 +7,7 @@ using TMPro;
 public class Tower : Character
 {
     [Header("ËþÐÅÏ¢")]
-    public int id;
+    public string name;
     public bool isLockSoul;
     public float height = 8;