diff --git a/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt b/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt new file mode 100644 index 00000000..f8449555 --- /dev/null +++ b/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt @@ -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 + } +] diff --git a/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt.meta b/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt.meta new file mode 100644 index 00000000..3c4a8ccb --- /dev/null +++ b/meng_yao/Assets/Config/MapLevel_MonsterInfo_1.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b534002cbb7fddf4bb68f34fb1357ff3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/meng_yao/Assets/Scenes/New/Scene_map_1.unity b/meng_yao/Assets/Scenes/New/Scene_map_1.unity index 1e6ca7db..805dfe1f 100644 --- a/meng_yao/Assets/Scenes/New/Scene_map_1.unity +++ b/meng_yao/Assets/Scenes/New/Scene_map_1.unity @@ -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 diff --git a/meng_yao/Assets/script/A_Fight/InitEnenyData.cs b/meng_yao/Assets/script/A_Fight/InitEnenyData.cs index 1fb68b10..99b4146c 100644 --- a/meng_yao/Assets/script/A_Fight/InitEnenyData.cs +++ b/meng_yao/Assets/script/A_Fight/InitEnenyData.cs @@ -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]; } } diff --git a/meng_yao/Assets/script/A_Fight/MY_Infos.cs b/meng_yao/Assets/script/A_Fight/MY_Infos.cs index 6e0cabbc..54ce35f1 100644 --- a/meng_yao/Assets/script/A_Fight/MY_Infos.cs +++ b/meng_yao/Assets/script/A_Fight/MY_Infos.cs @@ -16,6 +16,7 @@ public class MY_Infos : MonoBehaviour public List mengyaoItems=new List(); public MY_Infos instane; + void Awake() { instane = this; diff --git a/meng_yao/Assets/script/A_Fight/Monster_Infos.cs b/meng_yao/Assets/script/A_Fight/Monster_Infos.cs index 8c730b2f..fb67c3b5 100644 --- a/meng_yao/Assets/script/A_Fight/Monster_Infos.cs +++ b/meng_yao/Assets/script/A_Fight/Monster_Infos.cs @@ -13,11 +13,29 @@ public class monster public class Monster_Infos : MonoBehaviour { public List monsters = new List(); - public Monster_Infos instance; + public static Monster_Infos instance; void Awake() { instance = this; } + + + /// + /// 根据id得到预制体,如果找不到对应id,默认返回第一个怪物 + /// + /// + /// + public GameObject GetMonster(string id) + { + foreach (monster value in monsters) + { + if (value.id==id) + { + return value.prefab; + } + } + return monsters[0].prefab; + } } diff --git a/meng_yao/Assets/script/A_Fight/SpawnMonster.cs b/meng_yao/Assets/script/A_Fight/SpawnMonster.cs index 97b2abab..d3d60ec7 100644 --- a/meng_yao/Assets/script/A_Fight/SpawnMonster.cs +++ b/meng_yao/Assets/script/A_Fight/SpawnMonster.cs @@ -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 SpawnLocations; + + [Header("临时索引")] + private int index=1; + + public List enemysList=new List(); private void Awake() { @@ -20,6 +24,8 @@ public class SpawnMonster : Base void Start() { Base.GlobalObj.GetComponent().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().index = value.spawnPoint-1; + go.GetComponent().gold = enemy.Reward; + + enemysList.Add(go); + } + } + } } - void GenerateEnemy() - { - - - } - - + + // public void private void OnDisable() diff --git a/meng_yao/Assets/script/A_Fight/enemy.cs b/meng_yao/Assets/script/A_Fight/enemy.cs index 70248277..aba2af02 100644 --- a/meng_yao/Assets/script/A_Fight/enemy.cs +++ b/meng_yao/Assets/script/A_Fight/enemy.cs @@ -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)); } } diff --git a/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs b/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs new file mode 100644 index 00000000..3891cb17 --- /dev/null +++ b/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MapLevelJsonRead : JsonReadBase +{ + public static MapLevelJsonRead instance; + public List waves; + public TextAsset MapLevelJson; + + void Awake() + { + instance=this; + waves = base.LoadJson(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 enemies; // 敌人列表 + public int totalReward; // 总奖励 +} + diff --git a/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs.meta b/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs.meta new file mode 100644 index 00000000..5e45791c --- /dev/null +++ b/meng_yao/Assets/script/A_Fight/json/MapLevelJsonRead.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1617263e713d804995e0d3f3073e0cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: