Cute_demon_attacks/meng_yao/Assets/script/A_Fight/SpawnMonster.cs

132 lines
3.0 KiB
C#
Raw Normal View History

2025-01-06 09:36:25 +08:00
using System.Collections.Generic;
using UnityEngine;
2025-01-06 12:06:49 +08:00
using System.Collections;
using System.Threading.Tasks;
2025-01-06 09:36:25 +08:00
2025-01-06 10:13:44 +08:00
public class SpawnMonster : Base
{
public static SpawnMonster intance;
2025-01-06 09:36:25 +08:00
2025-01-06 12:06:49 +08:00
[Header("<22><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>")]
public List<Transform> SpawnLocations;
[Header("<22><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>")]
private int index=1;
2025-01-06 15:16:39 +08:00
public int Index
{
get => index;
set
{
index=value;
StartSpawning();
}
}
2025-01-06 12:06:49 +08:00
public List<GameObject> enemysList=new List<GameObject>();
2025-01-06 09:36:25 +08:00
private void Awake()
{
intance = this;
}
void Start()
{
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay += this.StartSpawning;
2025-01-06 12:06:49 +08:00
StartSpawning();
2025-01-06 09:36:25 +08:00
}
2025-01-06 10:13:44 +08:00
/*public void UpdateNodeList()
2025-01-06 09:36:25 +08:00
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>д<EFBFBD><D0B4><EFBFBD> SortingGroup <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>˶<EFBFBD><CBB6><EFBFBD>
List<GameObject> gameObjectsList = new List<GameObject>();
foreach (GameObject go in Enemys)
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD> SortingGroup <20><><EFBFBD><EFBFBD>
if (go != null)
{
SortingGroup sortingGroup = go.GetComponent<SortingGroup>();
if (sortingGroup != null && go.activeSelf)
{
// <20><><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD><D0B1><EFBFBD>
gameObjectsList.Add(go);
}
}
}
// <20><><EFBFBD><EFBFBD> y <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gameObjectsList.Sort((a, b) => a.transform.position.y.CompareTo(b.transform.position.y));
// <20><><EFBFBD><EFBFBD> SortingGroup <20><><EFBFBD><EFBFBD> Canvas <20><> sortingOrder
for (int i = 0; i < gameObjectsList.Count; i++)
{
SortingGroup sortingGroup = gameObjectsList[i].GetComponent<SortingGroup>();
if (sortingGroup != null)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>
int order = gameObjectsList.Count - i + 2;
sortingGroup.sortingOrder = order;
// <20><>ȡ<EFBFBD><C8A1> Canvas <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sortingOrder
Canvas canvas = gameObjectsList[i].GetComponentInChildren<Canvas>();
if (canvas != null)
{
canvas.sortingOrder = order;
}
}
}
2025-01-06 10:13:44 +08:00
}*/
2025-01-06 09:36:25 +08:00
void Update()
{
2025-01-06 12:06:49 +08:00
// UpdateNodeList();
2025-01-06 09:36:25 +08:00
}
2025-01-06 10:13:44 +08:00
2025-01-06 12:06:49 +08:00
public async void StartSpawning()
2025-01-06 09:36:25 +08:00
{
2025-01-06 12:06:49 +08:00
foreach (Wave value in MapLevelJsonRead.instance.waves)
{
if (value.wave == index)
{
foreach (var enemy in value.enemies)
{
2025-01-06 09:36:25 +08:00
2025-01-06 12:06:49 +08:00
await Task.Delay(enemy.startTime * 3);
2025-01-06 09:36:25 +08:00
2025-01-06 12:06:49 +08:00
GameObject go = GameObject.Instantiate(Monster_Infos.instance.GetMonster(enemy.id), SpawnLocations[value.spawnPoint - 1].position, Quaternion.identity);
2025-01-06 09:36:25 +08:00
2025-01-06 12:06:49 +08:00
go.GetComponent<enemy>().index = value.spawnPoint-1;
go.GetComponent<Role>().gold = enemy.Reward;
enemysList.Add(go);
}
}
}
}
2025-01-06 09:36:25 +08:00
2025-01-06 12:06:49 +08:00
// public void
2025-01-06 09:36:25 +08:00
private void OnDisable()
{
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay -= this.StartSpawning;
}
}