1.5
This commit is contained in:
parent
cb20481357
commit
94f1492535
@ -10576,7 +10576,8 @@ MonoBehaviour:
|
||||
retbutton: {fileID: 0}
|
||||
ClosureObj: {fileID: 0}
|
||||
BloodText: {fileID: 1288391609}
|
||||
KIllNumber: {fileID: 1595305660}
|
||||
KIllNumberText: {fileID: 1595305660}
|
||||
maxEnemynumber: 20
|
||||
allNumer: 0
|
||||
Battle_Time: {fileID: 971885053}
|
||||
Levels_number: {fileID: 744270342}
|
||||
@ -11580,8 +11581,9 @@ MonoBehaviour:
|
||||
GenerateParentNode: {fileID: 1884241085}
|
||||
GenerationInterval: 15
|
||||
GenerationIntervalOfOne: 3
|
||||
GenerateQuantityMax: 5
|
||||
GenerateQuantityMax: 20
|
||||
GenerateQuantity: 5
|
||||
deadNumber: 0
|
||||
--- !u!1 &1893328339
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -27,7 +27,7 @@ public class ObJPool<T>
|
||||
if (SurvivalPool.Contains(obj))
|
||||
{
|
||||
SurvivalPool.Remove(obj);
|
||||
DeathPool.Add(obj);
|
||||
DeathPool.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,19 +59,25 @@ public class SpawnPool : Base
|
||||
[Header("每一波生成数量")]
|
||||
public float GenerateQuantity;
|
||||
|
||||
private float lastGenerationTime = 0f; // 记录上一波生成的时间
|
||||
private float lastSingleGenerationTime = 0f; // 记录生成单个敌人之间的时间
|
||||
private int generatedCount = 0; // 记录已生成敌人的数量
|
||||
private int currentWave = 0; // 当前波数
|
||||
private bool isGenerating = false; // 标记是否在生成敌人
|
||||
private bool isWaveComplete = false; // 标记当前波是否完成
|
||||
[HideInInspector]
|
||||
public int deadNumber = 0;
|
||||
|
||||
|
||||
// 状态变量
|
||||
private bool IsStartGet = false; // 是否开始生成
|
||||
private bool IsWave = true; // 当前是否在生成波
|
||||
private float timerOfOne = 0f; // 记录每个敌人生成的时间
|
||||
private float timerOfOneWave = 0f; // 记录波与波之间的时间
|
||||
private int generatedCount = 0; // 总已生成敌人数量
|
||||
private int waveGeneratedCount = 0; // 当前波已生成敌人数量
|
||||
private int currentWave = 0; // 当前波数
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
intance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay += this.StartSpawning;
|
||||
@ -79,23 +85,41 @@ public class SpawnPool : Base
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isGenerating)
|
||||
if (IsStartGet)
|
||||
{
|
||||
if (isWaveComplete)
|
||||
if (IsWave)
|
||||
{
|
||||
// 如果当前波已完成,等待下一波
|
||||
if (Time.time - lastGenerationTime >= GenerationInterval)
|
||||
timerOfOne += Time.deltaTime;
|
||||
if (timerOfOne >= GenerationIntervalOfOne && waveGeneratedCount < GenerateQuantity)
|
||||
{
|
||||
StartNextWave(); // 启动下一波生成
|
||||
GenerateEnemy(); // 生成敌人
|
||||
timerOfOne = 0f; // 重置计时器
|
||||
waveGeneratedCount++; // 增加当前波的生成数量
|
||||
|
||||
// 如果当前波的敌人数量已达上限,则标记波结束
|
||||
if (waveGeneratedCount >= GenerateQuantity)
|
||||
{
|
||||
IsWave = false; // 当前波生成完毕,切换到等待下一波
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 判断是否到了生成一波敌人的时间
|
||||
if (Time.time - lastSingleGenerationTime >= GenerationIntervalOfOne && generatedCount < GenerateQuantity)
|
||||
timerOfOneWave += Time.deltaTime;
|
||||
if (timerOfOneWave >= GenerationInterval)
|
||||
{
|
||||
GenerateEnemy(); // 生成单个敌人
|
||||
lastSingleGenerationTime = Time.time; // 更新生成单个敌人的时间
|
||||
// 当前波生成完毕,等待下一波
|
||||
currentWave++;
|
||||
if (generatedCount < GenerateQuantityMax)
|
||||
{
|
||||
waveGeneratedCount = 0;
|
||||
timerOfOneWave = 0f; // 重置波间隔计时器
|
||||
IsWave = true; // 启动新的一波
|
||||
}
|
||||
else
|
||||
{
|
||||
IsStartGet = false; // 所有敌人生成完毕,停止生成
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,66 +127,51 @@ public class SpawnPool : Base
|
||||
|
||||
void StartSpawning()
|
||||
{
|
||||
// 重置生成计数,开始生成敌人
|
||||
generatedCount = 0;
|
||||
// 初始化状态,开始生成
|
||||
IsStartGet = true;
|
||||
waveGeneratedCount = 0;
|
||||
currentWave = 0;
|
||||
lastGenerationTime = Time.time; // 记录开始生成的时间
|
||||
isGenerating = true; // 启动生成敌人
|
||||
isWaveComplete = false; // 当前波尚未完成
|
||||
}
|
||||
|
||||
void StartNextWave()
|
||||
{
|
||||
currentWave++; // 增加波数
|
||||
if (generatedCount < GenerateQuantityMax) // 如果生成的敌人数量未达到最大值
|
||||
{
|
||||
generatedCount = 0; // 重置每波生成数量
|
||||
lastGenerationTime = Time.time; // 记录下一波开始的时间
|
||||
isWaveComplete = false; // 当前波未完成
|
||||
}
|
||||
else
|
||||
{
|
||||
isGenerating = false; // 如果已经生成完所有敌人,则停止生成
|
||||
}
|
||||
generatedCount = 0;
|
||||
timerOfOne = 0f;
|
||||
timerOfOneWave = 0f;
|
||||
}
|
||||
|
||||
void GenerateEnemy()
|
||||
{
|
||||
if (generatedCount < GenerateQuantity && generatedCount < GenerateQuantityMax)
|
||||
GameObject enemy = EnemyPool.Get(); // 获取一个敌人对象
|
||||
|
||||
// 如果池子中没有可用的对象,创建新的敌人
|
||||
if (enemy == null)
|
||||
{
|
||||
GameObject enemy = EnemyPool.Get(); // 获取一个敌人对象
|
||||
|
||||
// 如果池子中没有可用的对象,创建新的敌人
|
||||
if (enemy == null)
|
||||
if (Prefab == null)
|
||||
{
|
||||
if (Prefab == null)
|
||||
{
|
||||
Debug.LogError("Prefab is not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
enemy = Instantiate(Prefab, SpawnLocation.position, Quaternion.identity, GenerateParentNode);
|
||||
Debug.LogError("Prefab is not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置敌人的位置和其他属性
|
||||
enemy.SetActive(true); // 激活敌人对象
|
||||
enemy.transform.position = SpawnLocation.position;
|
||||
|
||||
generatedCount++; // 更新生成计数
|
||||
|
||||
// 每波生成数量达到上限时,标记当前波已完成
|
||||
if (generatedCount >= GenerateQuantity)
|
||||
{
|
||||
isWaveComplete = true; // 当前波生成完毕
|
||||
}
|
||||
enemy = Instantiate(Prefab, SpawnLocation.position, Quaternion.identity, GenerateParentNode);
|
||||
}
|
||||
|
||||
// 设置敌人的位置和其他属性
|
||||
enemy.SetActive(true); // 激活敌人对象
|
||||
enemy.transform.position = SpawnLocation.position;
|
||||
|
||||
// 更新生成计数
|
||||
generatedCount++;
|
||||
}
|
||||
|
||||
|
||||
// 当池子中敌人死亡或者被回收时,将其回收到池中
|
||||
public void ReturnEnemyToPool(GameObject enemy)
|
||||
{
|
||||
enemy.SetActive(false); // 禁用敌人对象
|
||||
EnemyPool.Return(enemy); // 将敌人回收到池中
|
||||
|
||||
deadNumber++;
|
||||
if (deadNumber>= GenerateQuantityMax)
|
||||
{
|
||||
Debug.Log("胜利");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@ -170,3 +179,6 @@ public class SpawnPool : Base
|
||||
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay -= this.StartSpawning;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -7,7 +7,21 @@ public class UIContorl : Base
|
||||
{
|
||||
public static UIContorl instance;
|
||||
public Text BloodText;
|
||||
public Text KIllNumber;
|
||||
public Text KIllNumberText;
|
||||
|
||||
public int maxEnemynumber;
|
||||
private int killnumber;
|
||||
public int Killnumber
|
||||
{
|
||||
get=> killnumber;
|
||||
set
|
||||
{
|
||||
killnumber = value;
|
||||
this.KIllNumberText.text = killnumber + "/" + maxEnemynumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int allNumer;
|
||||
public Text Battle_Time;
|
||||
public Text Levels_number;
|
||||
@ -74,6 +88,8 @@ public class UIContorl : Base
|
||||
Battle_Time.text = "00:00";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void GameVitor()
|
||||
{
|
||||
|
||||
|
@ -28,14 +28,16 @@ public class enemy : Role
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
// 将当前敌人对象放入死亡池
|
||||
SpawnPool spawnPool = SpawnPool.intance; // 获取 SpawnPool 组件
|
||||
if (spawnPool != null)
|
||||
{
|
||||
Debug.LogError(this.name+"die");
|
||||
spawnPool.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||
|
||||
|
||||
// 将当前敌人对象放入死亡池
|
||||
if (SpawnPool.intance != null)
|
||||
{
|
||||
SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||
ResetAllStatus();
|
||||
}
|
||||
|
||||
UIContorl.instance.Killnumber += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user