修改
This commit is contained in:
parent
1141b010d8
commit
9bff71e4bf
@ -841,7 +841,7 @@ Transform:
|
||||
- {fileID: 995271151}
|
||||
- {fileID: 1932457213}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 8
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &284432671
|
||||
MonoBehaviour:
|
||||
@ -1570,7 +1570,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 7
|
||||
m_RootOrder: 8
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &459650026
|
||||
MonoBehaviour:
|
||||
@ -5919,6 +5919,71 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 97664c5246bb0d242997921b3560d036, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
retbutton: {fileID: 0}
|
||||
ClosureObj: {fileID: 0}
|
||||
--- !u!1 &1910338484
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1910338485}
|
||||
- component: {fileID: 1910338487}
|
||||
- component: {fileID: 1910338486}
|
||||
m_Layer: 0
|
||||
m_Name: Infos
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &1910338485
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1910338484}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 524.29224, y: 1319.394, z: -1.7705407}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1910338486
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1910338484}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f6c570b2c3c14994fa8337757d1d492e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
mengyaoItems: []
|
||||
instane: {fileID: 0}
|
||||
--- !u!114 &1910338487
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1910338484}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3ee6cb1a8b4020040bddd9c037e404b4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
monsters:
|
||||
- id:
|
||||
prefab: {fileID: 4703411402065954783, guid: aac4ad2c72526a54691494dd54e115a6, type: 3}
|
||||
instance: {fileID: 0}
|
||||
--- !u!1 &1932457212
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
23
meng_yao/Assets/script/A_Fight/Monster_Infos.cs
Normal file
23
meng_yao/Assets/script/A_Fight/Monster_Infos.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class monster
|
||||
{
|
||||
public string id;
|
||||
public GameObject prefab;
|
||||
|
||||
}
|
||||
|
||||
public class Monster_Infos : MonoBehaviour
|
||||
{
|
||||
public List<monster> monsters = new List<monster>();
|
||||
public Monster_Infos instance;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
}
|
||||
|
11
meng_yao/Assets/script/A_Fight/Monster_Infos.cs.meta
Normal file
11
meng_yao/Assets/script/A_Fight/Monster_Infos.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ee6cb1a8b4020040bddd9c037e404b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -4,56 +4,13 @@ using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class SpawnMonster : Base
|
||||
{
|
||||
public static SpawnMonster intance;
|
||||
|
||||
public ObJPool<GameObject> EnemyPool = new ObJPool<GameObject>();
|
||||
public List<GameObject> Enemys = new List<GameObject>();
|
||||
|
||||
[Header("生成预制体")]
|
||||
public GameObject Prefab;
|
||||
|
||||
[Header("生成位置")]
|
||||
public Transform SpawnLocation;
|
||||
|
||||
[Header("一波生成间隔")]
|
||||
public float GenerationInterval;
|
||||
|
||||
[Header("一次生成间隔")]
|
||||
public float GenerationIntervalOfOne;
|
||||
|
||||
[Header("生成总数量")]
|
||||
public float GenerateQuantityMax;
|
||||
|
||||
[Header("每一波生成数量")]
|
||||
public float GenerateQuantity;
|
||||
|
||||
[HideInInspector]
|
||||
public int deadNumber = 0;
|
||||
public int DeadNumber
|
||||
{
|
||||
get => deadNumber;
|
||||
set
|
||||
{
|
||||
deadNumber = value;
|
||||
if (deadNumber >= GenerateQuantityMax)
|
||||
{
|
||||
// gameGlobal.GameVictory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 状态变量
|
||||
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; // 当前波数
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -64,7 +21,9 @@ public class SpawnMonster : Base
|
||||
{
|
||||
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay += this.StartSpawning;
|
||||
}
|
||||
public void UpdateNodeList()
|
||||
|
||||
|
||||
/*public void UpdateNodeList()
|
||||
{
|
||||
// 获取所有带有 SortingGroup 组件的敌人对象
|
||||
List<GameObject> gameObjectsList = new List<GameObject>();
|
||||
@ -105,97 +64,25 @@ public class SpawnMonster : Base
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (IsStartGet)
|
||||
{
|
||||
if (IsWave)
|
||||
{
|
||||
timerOfOne += Time.deltaTime;
|
||||
if (timerOfOne >= GenerationIntervalOfOne && waveGeneratedCount < GenerateQuantity)
|
||||
{
|
||||
GenerateEnemy(); // 生成敌人
|
||||
timerOfOne = 0f; // 重置计时器
|
||||
waveGeneratedCount++; // 增加当前波的生成数量
|
||||
|
||||
// 如果当前波的敌人数量已达上限,则标记波结束
|
||||
if (waveGeneratedCount >= GenerateQuantity)
|
||||
{
|
||||
IsWave = false; // 当前波生成完毕,切换到等待下一波
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timerOfOneWave += Time.deltaTime;
|
||||
if (timerOfOneWave >= GenerationInterval)
|
||||
{
|
||||
// 当前波生成完毕,等待下一波
|
||||
currentWave++;
|
||||
if (generatedCount < GenerateQuantityMax)
|
||||
{
|
||||
waveGeneratedCount = 0;
|
||||
timerOfOneWave = 0f; // 重置波间隔计时器
|
||||
IsWave = true; // 启动新的一波
|
||||
}
|
||||
else
|
||||
{
|
||||
IsStartGet = false; // 所有敌人生成完毕,停止生成
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateNodeList();
|
||||
}
|
||||
|
||||
public void StartSpawning()
|
||||
{
|
||||
if (GenerateQuantity >= GenerateQuantityMax)
|
||||
{
|
||||
GenerateQuantity = GenerateQuantityMax;
|
||||
}
|
||||
// 初始化状态,开始生成
|
||||
IsStartGet = true;
|
||||
waveGeneratedCount = 0;
|
||||
currentWave = 0;
|
||||
generatedCount = 0;
|
||||
timerOfOne = 0f;
|
||||
timerOfOneWave = 0f;
|
||||
|
||||
}
|
||||
|
||||
void GenerateEnemy()
|
||||
{
|
||||
|
||||
GameObject enemy = EnemyPool.Get(); // 获取一个敌人对象
|
||||
|
||||
// 如果池子中没有可用的对象,创建新的敌人
|
||||
if (enemy == null)
|
||||
{
|
||||
if (Prefab == null)
|
||||
{
|
||||
Debug.LogError("Prefab is not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
enemy = Instantiate(Prefab);
|
||||
//EnemyPool.SurvivalPool.Add(enemy);
|
||||
Enemys.Add(enemy);
|
||||
}
|
||||
|
||||
//enemy.GetComponent<Role>().ResetAllStatus();
|
||||
// 设置敌人的位置和其他属性
|
||||
enemy.SetActive(true); // 激活敌人对象
|
||||
enemy.transform.position = SpawnLocation.position;
|
||||
|
||||
// 更新生成计数
|
||||
generatedCount++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +34,7 @@ public class ObJPool<T>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SpawnPool : Base
|
||||
{
|
||||
public static SpawnPool intance;
|
||||
|
Loading…
Reference in New Issue
Block a user