|
@@ -5,32 +5,17 @@ using cfg;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
using Base.Common;
|
|
using Base.Common;
|
|
|
using System.Linq;
|
|
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 class EnemyCreater : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
public static EnemyCreater instance;
|
|
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()
|
|
private void Awake()
|
|
|
{
|
|
{
|
|
@@ -43,15 +28,54 @@ public class EnemyCreater : MonoBehaviour
|
|
|
DestroyImmediate(gameObject);
|
|
DestroyImmediate(gameObject);
|
|
|
return;
|
|
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()
|
|
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生成一遍防止后面初次生成卡顿
|
|
//把所有怪物prefab生成一遍防止后面初次生成卡顿
|
|
|
//foreach (var item in createCharacter)
|
|
//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)
|
|
if (!instance)
|
|
|
{
|
|
{
|
|
|
return;
|
|
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;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- float TimeInterval = (float)(spawnTime.endTime - spawnTime.startTime) / (spawnTime.num - 1);
|
|
|
|
|
|
|
+ float TimeInterval = (float)(cfgCreateEnemy.EndTime - cfgCreateEnemy.StartTime) / (cfgCreateEnemy.Count - 1);
|
|
|
if (TimeInterval < 0)
|
|
if (TimeInterval < 0)
|
|
|
{
|
|
{
|
|
|
return;
|
|
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);
|
|
GameObject enemyObj = Util.Instantiate(enemyStr, pos, active: active);
|
|
|
- Parameter parameter = gameMapTile.parameter;
|
|
|
|
|
AttackInfo attackInfo;
|
|
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;
|
|
enemyObj.transform.position = pos;
|
|
|
return enemyObj;
|
|
return enemyObj;
|
|
@@ -226,14 +209,14 @@ public class EnemyCreater : MonoBehaviour
|
|
|
|
|
|
|
|
public void OnEnemyRecycle(Enemy enemy)
|
|
public void OnEnemyRecycle(Enemy enemy)
|
|
|
{
|
|
{
|
|
|
- if (!enemyDic.ContainsKey(enemy.id))
|
|
|
|
|
|
|
+ if (!enemyDic.ContainsKey(enemy.name))
|
|
|
{
|
|
{
|
|
|
return;
|
|
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);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|