This commit is contained in:
wulongxiao 2025-01-06 12:06:49 +08:00
parent 9bff71e4bf
commit 9bd1be8b9b
10 changed files with 230 additions and 25 deletions

View File

@ -0,0 +1,100 @@
[
{
"wave": 1,
"spawnPoint": 1,
"enemies": [
{"id": "Enemy_002", "count": 1, "startTime": 0, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3}
],
"totalReward": 50
},
{
"wave": 2,
"spawnPoint": 1,
"enemies": [
{"id": "Enemy_005", "count": 1, "startTime": 0, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_005", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_005", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_005", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_005", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3}
],
"totalReward": 100
},
{
"wave": 3,
"spawnPoint": 1,
"enemies": [
{"id": "Enemy_001", "count": 1, "startTime": 0, "Reward": 3},
{"id": "Enemy_003", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_003", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_003", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3}
],
"totalReward": 150
},
{
"wave": 4,
"spawnPoint": 1,
"enemies": [
{"id": "Enemy_001", "count": 1, "startTime": 0, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_006", "count": 1, "startTime": 500, "Reward": 8},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 3000, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_009", "count": 1, "startTime": 500, "Reward": 8},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 3000, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_009", "count": 1, "startTime": 500, "Reward": 8},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_004", "count": 1, "startTime": 500, "Reward": 3}
],
"totalReward": 200
},
{
"wave": 5,
"spawnPoint": 1,
"enemies": [
{"id": "Enemy_002", "count": 1, "startTime": 0, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_008", "count": 1, "startTime": 500, "Reward": 8},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 3000, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_010", "count": 1, "startTime": 3000, "Reward": 5},
{"id": "Enemy_008", "count": 1, "startTime": 500, "Reward": 8},
{"id": "Enemy_010", "count": 1, "startTime": 500, "Reward": 5},
{"id": "Enemy_001", "count": 1, "startTime": 3000, "Reward": 3},
{"id": "Enemy_001", "count": 1, "startTime": 500, "Reward": 3},
{"id": "Enemy_002", "count": 1, "startTime": 500, "Reward": 3}
],
"totalReward": 250
}
]

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b534002cbb7fddf4bb68f34fb1357ff3
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4388,6 +4388,7 @@ GameObject:
m_Component:
- component: {fileID: 1337722729}
- component: {fileID: 1337722730}
- component: {fileID: 1337722731}
m_Layer: 0
m_Name: ReadJson
m_TagString: Untagged
@ -4427,6 +4428,19 @@ MonoBehaviour:
LevelAsset: {fileID: 4900000, guid: 89bbacca41b409b4dbf238a43bbb2e4b, type: 3}
SkillAsset: {fileID: 4900000, guid: 3d441bff04ee5a64ea8b8967bcfbc070, type: 3}
m_Level: []
--- !u!114 &1337722731
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1337722728}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f1617263e713d804995e0d3f3073e0cb, type: 3}
m_Name:
m_EditorClassIdentifier:
MapLevelJson: {fileID: 4900000, guid: b534002cbb7fddf4bb68f34fb1357ff3, type: 3}
--- !u!1 &1342038372
GameObject:
m_ObjectHideFlags: 0
@ -5892,7 +5906,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1884241084}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fdf69f16194abb24d9e887468940e1cb, type: 3}
m_Name:
@ -5921,6 +5935,9 @@ MonoBehaviour:
m_EditorClassIdentifier:
retbutton: {fileID: 0}
ClosureObj: {fileID: 0}
SpawnLocations:
- {fileID: 734893407}
enemysList: []
--- !u!1 &1910338484
GameObject:
m_ObjectHideFlags: 0
@ -5983,7 +6000,6 @@ MonoBehaviour:
monsters:
- id:
prefab: {fileID: 4703411402065954783, guid: aac4ad2c72526a54691494dd54e115a6, type: 3}
instance: {fileID: 0}
--- !u!1 &1932457212
GameObject:
m_ObjectHideFlags: 0

View File

@ -16,7 +16,7 @@ public class InitEnenyData : MonoBehaviour
}
// 返回一个随机选择的路径点集合
public waypoints GetRandomWaypoints()
public waypoints GetRandomWaypoints(int index)
{
// 检查列表是否为空,避免数组越界错误
if (mywaypoints.Count == 0)
@ -30,11 +30,7 @@ public class InitEnenyData : MonoBehaviour
{
return mywaypoints[0];
}
// 随机选择一个索引,范围是 [0, mywaypoints.Count - 1]
int randomIndex = Random.Range(0, mywaypoints.Count);
// 返回随机选择的路径点集合
return mywaypoints[randomIndex];
return mywaypoints[index];
}
}

View File

@ -16,6 +16,7 @@ public class MY_Infos : MonoBehaviour
public List<mengyaoInfo> mengyaoItems=new List<mengyaoInfo>();
public MY_Infos instane;
void Awake()
{
instane = this;

View File

@ -13,11 +13,29 @@ public class monster
public class Monster_Infos : MonoBehaviour
{
public List<monster> monsters = new List<monster>();
public Monster_Infos instance;
public static Monster_Infos instance;
void Awake()
{
instance = this;
}
/// <summary>
/// 根据id得到预制体如果找不到对应id默认返回第一个怪物
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public GameObject GetMonster(string id)
{
foreach (monster value in monsters)
{
if (value.id==id)
{
return value.prefab;
}
}
return monsters[0].prefab;
}
}

View File

@ -1,16 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using System.Collections;
using System.Threading.Tasks;
public class SpawnMonster : Base
{
public static SpawnMonster intance;
[Header("Éú³ÉλÖÃ")]
public List<Transform> SpawnLocations;
[Header("ÁÙʱË÷Òý")]
private int index=1;
public List<GameObject> enemysList=new List<GameObject>();
private void Awake()
{
@ -20,6 +24,8 @@ public class SpawnMonster : Base
void Start()
{
Base.GlobalObj.GetComponent<gameGlobal>().OnGamePlay += this.StartSpawning;
StartSpawning();
}
@ -70,22 +76,36 @@ public class SpawnMonster : Base
void Update()
{
// UpdateNodeList();
}
public void StartSpawning()
public async void StartSpawning()
{
foreach (Wave value in MapLevelJsonRead.instance.waves)
{
if (value.wave == index)
{
foreach (var enemy in value.enemies)
{
await Task.Delay(enemy.startTime * 3);
GameObject go = GameObject.Instantiate(Monster_Infos.instance.GetMonster(enemy.id), SpawnLocations[value.spawnPoint - 1].position, Quaternion.identity);
go.GetComponent<enemy>().index = value.spawnPoint-1;
go.GetComponent<Role>().gold = enemy.Reward;
enemysList.Add(go);
}
}
}
}
void GenerateEnemy()
{
}
// public void
private void OnDisable()

View File

@ -81,6 +81,9 @@ public class enemy : Role
[Header("防御类型")] public DefenseType defenseType;
[HideInInspector]
[Header("·¾¶Ë÷Òý")] public int index;
public override void Start()
{
base.Start();
@ -95,7 +98,7 @@ public class enemy : Role
}
//开始移动
Init(InitEnenyData.instance.GetRandomWaypoints());
Init(InitEnenyData.instance.GetRandomWaypoints(index));
}
}

View File

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapLevelJsonRead : JsonReadBase
{
public static MapLevelJsonRead instance;
public List<Wave> waves;
public TextAsset MapLevelJson;
void Awake()
{
instance=this;
waves = base.LoadJson<Wave>(MapLevelJson);
}
}
public struct maplevel_enemy
{
public string id; // 敌人类型
public int count; // 敌人数量
public int startTime; // 敌人生成开始时间
public int Reward; // 奖励
}
public struct Wave
{
public int wave; // 波数
public int spawnPoint; // 生成点
public List<maplevel_enemy> enemies; // 敌人列表
public int totalReward; // 总奖励
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1617263e713d804995e0d3f3073e0cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: