/// <summary> /// 深拷贝 /// </summary> /// <returns></returns> public MonsterDataInfo Clone() { MonsterDataInfo monsterDataInfo = new MonsterDataInfo(); monsterDataInfo.ID = ID; monsterDataInfo.MonsterType = MonsterType; monsterDataInfo.Center = Center; monsterDataInfo.Range = Range; monsterDataInfo.AIType = AIType; monsterDataInfo.ItemDropTypes = ItemDropTypes; monsterDataInfo.ItemDropRates = ItemDropRates; monsterDataInfo.Experience = Experience; monsterDataInfo.Briefly = Briefly; monsterDataInfo.Explane = Explane; monsterDataInfo.monsterPrefabName = monsterPrefabName; monsterDataInfo.MonsterPrefab = MonsterPrefab; monsterDataInfo.TaskToShowList = new List <KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> >(TaskToShowList.ToArray()); monsterDataInfo.TaskToHideList = new List <KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> >(TaskToHideList.ToArray()); if (MonsterBaseAttribute != null) { monsterDataInfo.MonsterBaseAttribute = MonsterBaseAttribute.Clone(); } if (AIData != null) { monsterDataInfo.AIData = AIData.Clone(); } monsterDataInfo.Init(); return(monsterDataInfo); }
private void Start() { Self = gameObject; MonsterData = _TestMonsterData; try { AIAction = (AIAction)Activator.CreateInstance(Type.GetType(AIActionClass)); AIAction.Init(this); } catch (Exception ex) { Debug.Log(ex); } try { AILogic = (AILogic)Activator.CreateInstance(Type.GetType(AILogicClass)); AILogic.Init(this); } catch (Exception ex) { Debug.Log(ex); } try { AIAnimator = (AIAnimator)Activator.CreateInstance(Type.GetType(AIAnimatorClass)); AIAnimator.Init(this); } catch (Exception ex) { Debug.Log(ex); } }
public Enemy(int configId, int lv, int ai, int index) { Id = configId; MonsterDataInfo monsterTableDataInfo = (MonsterDataInfo)ConfigDataMgr.Instance.GetDataInfo <MonsterTableData>(Id); Data = new EnemyData(monsterTableDataInfo, lv, ai); InstanceId = Id * 100 + index; }
public EnemyData(MonsterDataInfo dataInfo, int lv, int ai) { Id = dataInfo.Id; Name = dataInfo.Name; Description = dataInfo.Description; Lv = new ENum <int>(lv); Sex = dataInfo.Sex; Hp = new ENum <int>(dataInfo.Hp); HpMax = new ENum <int>(dataInfo.Hp); Mp = new ENum <int>(dataInfo.Mp); MpMax = new ENum <int>(dataInfo.Mp); Def = new ENum <int>(dataInfo.Def); Att = new ENum <int>(dataInfo.Att); Icon = dataInfo.Icon; Cg = dataInfo.Cg; Ai = new ENum <int>(ai); DropIds = new List <ENum <int> >(); foreach (int dropId in dataInfo.DropIds) { DropIds.Add(new ENum <int>(dropId)); } }
void OnGUI() { if (monsterDataInfoCollections == null || monsterTypeToFieldNameDic == null || monsterAITypeToFieldNameDic == null) { return; } //获取当前场景对象 MonsterDataInfoCollection monsterDataInfoCollection = monsterDataInfoCollections.FirstOrDefault(temp => string.Equals(temp.sceneName, selectScene)); EditorGUILayout.BeginHorizontal(); #region 保存 场景 等按钮 EditorGUILayout.BeginVertical(GUILayout.Width(200)); if (GUILayout.Button("保存", GUILayout.Width(100))) { string valueText = SerializeNow(monsterDataInfoCollections); File.WriteAllText(dataDirectoryPath + "/Monster.txt", valueText, Encoding.UTF8); EditorUtility.DisplayDialog("提示!", "保存成功", "确认"); } if (monsterDataInfoCollection == null && GUILayout.Button("添加本场景", GUILayout.Width(100))) { monsterDataInfoCollection = new MonsterDataInfoCollection() { sceneName = selectScene }; MonsterDataInfoCollection[] tempArray = new MonsterDataInfoCollection[monsterDataInfoCollections.Length + 1]; Array.Copy(monsterDataInfoCollections, tempArray, monsterDataInfoCollections.Length); tempArray[tempArray.Length - 1] = monsterDataInfoCollection; monsterDataInfoCollections = tempArray; } saveSceneScrollPostion = EditorGUILayout.BeginScrollView(saveSceneScrollPostion); #region 显示所有的场景按钮 bool changedScene = false; List <MonsterDataInfoCollection> monsterDataInfoCollectionList = new List <MonsterDataInfoCollection>(monsterDataInfoCollections); for (int i = 0; i < monsterDataInfoCollections.Length; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("删除", GUILayout.Width(35))) { if (EditorUtility.DisplayDialog("警告!", "请再次确认是否删除该场景的怪物配置信息?", "确认删除", "取消删除")) { monsterDataInfoCollectionList.Remove(monsterDataInfoCollections[i]); changedScene = true; } } if (monsterDataInfoCollections[i] == monsterDataInfoCollection) { EditorGUILayout.Toggle(true, GUILayout.Width(20)); } GUILayout.Button(monsterDataInfoCollections[i].sceneName); EditorGUILayout.EndHorizontal(); } if (changedScene) { monsterDataInfoCollections = monsterDataInfoCollectionList.ToArray(); if (!monsterDataInfoCollectionList.Contains(monsterDataInfoCollection)) { monsterDataInfoCollection = null; selectMonsterID = -1; } } #endregion EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); #endregion #region 择删除添加怪物id EditorGUILayout.BeginVertical(GUILayout.Width(175)); if (monsterDataInfoCollection != null) { if (GUILayout.Button("添加新策略", GUILayout.Width(75))) { int id = 0; if (monsterDataInfoCollection.MonsterDataInofs.Count > 0) { id = monsterDataInfoCollection.MonsterDataInofs.Max(temp => temp.ID) + 1; } monsterDataInfoCollection.MonsterDataInofs.Add(new MonsterDataInfo() { ID = id, Briefly = "空" }); } monsterIDScrollPostion = EditorGUILayout.BeginScrollView(monsterIDScrollPostion, GUILayout.Width(170)); List <MonsterDataInfo> tempMonsterDataInfos = new List <MonsterDataInfo>(monsterDataInfoCollection.MonsterDataInofs); foreach (MonsterDataInfo monsterDataInfo in tempMonsterDataInfos) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("删除", GUILayout.Width(35))) { if (EditorUtility.DisplayDialog("警告!", "请再次确认是否删除怪物配置信息?", "确认删除", "取消删除")) { monsterDataInfoCollection.MonsterDataInofs.Remove(monsterDataInfo); } } if (monsterDataInfo.ID == selectMonsterID) { EditorGUILayout.Toggle(true, GUILayout.Width(20)); } if (GUILayout.Button(monsterDataInfo.Briefly)) { selectMonsterID = monsterDataInfo.ID; //在这里重新赋值区域位置 if (rangeObj != null) { rangeObj.transform.position = monsterDataInfo.Center; rangeObj.transform.localScale = new Vector3(monsterDataInfo.Range * 2, monsterDataInfo.Range * 2, monsterDataInfo.Range * 2); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); #endregion //集合不等于0 选择的id大于等于0 并且存在该id if (monsterDataInfoCollection != null && selectMonsterID >= 0 && monsterDataInfoCollection.MonsterDataInofs.Count(temp => temp.ID == selectMonsterID) > 0) { MonsterDataInfo monsterDataInfo = monsterDataInfoCollection.MonsterDataInofs.FirstOrDefault(temp => temp.ID == selectMonsterID); #region 怪物的基本信息 EditorGUILayout.BeginVertical(GUILayout.Width(350)); baseDataScrollPostion = EditorGUILayout.BeginScrollView(baseDataScrollPostion); monsterDataInfo.Briefly = EditorGUILayout.TextField("配置:", monsterDataInfo.Briefly); monsterDataInfo.Explane = EditorGUILayout.TextField("说明:", monsterDataInfo.Explane, GUILayout.Width(300), GUILayout.Height(150)); string[] monsterTypeExplans = monsterTypeToFieldNameDic.Values.ToArray(); int[] monsterTypeValues = monsterTypeToFieldNameDic.Keys.Select(temp => (int)temp).ToArray(); int monsterTypeValue = EditorGUILayout.IntPopup("怪物类型:", (int)monsterDataInfo.MonsterType, monsterTypeExplans, monsterTypeValues); monsterDataInfo.MonsterType = (EnumMonsterType)monsterTypeValue; if (rangeObj != null) { rangeObj.transform.forward = Vector3.forward; monsterDataInfo.Center = rangeObj.transform.position; Vector3 scale = rangeObj.transform.localScale; float minRange = scale.x; minRange = scale.y < minRange ? scale.y : minRange; minRange = scale.z < minRange ? scale.z : minRange; monsterDataInfo.Range = minRange / 2; } monsterDataInfo.Center = EditorGUILayout.Vector3Field("区域中心:", monsterDataInfo.Center); monsterDataInfo.Range = EditorGUILayout.FloatField("区域范围:", monsterDataInfo.Range); if (rangeObj != null) { rangeObj.transform.position = monsterDataInfo.Center; rangeObj.transform.localScale = new Vector3(monsterDataInfo.Range * 2, monsterDataInfo.Range * 2, monsterDataInfo.Range * 2); } monsterDataInfo.Offset = EditorGUILayout.FloatField("高度偏差值:", monsterDataInfo.Offset); monsterDataInfo.Experience = EditorGUILayout.IntField("经验值:", monsterDataInfo.Experience); GameObject monsterPrefab = EditorGUILayout.ObjectField("怪物预设体:", monsterDataInfo.MonsterPrefab, typeof(GameObject), false) as GameObject; if (monsterPrefab == null) { monsterDataInfo.monsterPrefabName = ""; } else if (!string.Equals(monsterPrefab.name, monsterDataInfo.monsterPrefabName)) { string monsterPrefabName = monsterPrefab.name; if (monsterPrefabDic.ContainsKey(monsterPrefabName)) { monsterDataInfo.monsterPrefabName = monsterPrefabName; } } //设置属性 EditorGUILayout.BeginHorizontal(); if (monsterDataInfo.MonsterBaseAttribute == null) { monsterDataInfo.MonsterBaseAttribute = new AttributeStateAdditional(); } if (GUILayout.Button("设置属性")) { AttributeStateAdditionalEditor attributeStateAdditionalEditor = EditorWindow.GetWindow <AttributeStateAdditionalEditor>(); attributeStateAdditionalEditor.Show(); attributeStateAdditionalEditor.Target = monsterDataInfo.MonsterBaseAttribute; } if (GUILayout.Button("复制", GUILayout.Width(35))) { AttributeStateAdditional_Copy = monsterDataInfo.MonsterBaseAttribute.Clone(); } if (AttributeStateAdditional_Copy != null && GUILayout.Button("粘贴", GUILayout.Width(35)) && EditorUtility.DisplayDialog("请再次确认!", "是否覆盖当前数据?", "是", "否")) { monsterDataInfo.MonsterBaseAttribute = AttributeStateAdditional_Copy.Clone(); } EditorGUILayout.EndHorizontal(); //设置种族 List <RoleOfRace> roleOfRaceValues = roleOfRaceToFieldNameDic.Select(temp => temp.Key).ToList(); string[] roleOfRaceExplans = roleOfRaceToFieldNameDic.Select(temp => temp.Value).ToArray(); int roleOfRaceIndex = roleOfRaceValues.IndexOf(monsterDataInfo.roleOfRace); roleOfRaceIndex = EditorGUILayout.Popup("种族:", roleOfRaceIndex, roleOfRaceExplans); if (roleOfRaceIndex > -1) { monsterDataInfo.roleOfRace = roleOfRaceValues[roleOfRaceIndex]; } //设置显示和隐藏条件 List <TaskMap.Enums.EnumTaskProgress> taskProgressValues = taskProgressToFieldNameDic.Select(temp => temp.Key).ToList(); string[] taskProgressExplans = taskProgressToFieldNameDic.Select(temp => temp.Value).ToArray(); Action <List <KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> > > ShowHideTaskAction = (targetList) => { for (int i = 0; i < targetList.Count; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("×", GUILayout.Width(20)) && EditorUtility.DisplayDialog("请再次确认!", "是否删除该条件?", "确认删除", "取消")) { targetList.RemoveAt(i); EditorGUILayout.EndHorizontal(); break; } KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> tempValue = targetList[i]; EditorGUILayout.LabelField("任务ID:", GUILayout.Width(40)); int tempKey = EditorGUILayout.IntField(tempValue.Key, GUILayout.Width(30)); EditorGUILayout.LabelField("任务状态:", GUILayout.Width(50)); int index = taskProgressValues.IndexOf(tempValue.Value); index = EditorGUILayout.Popup(index, taskProgressExplans, GUILayout.Width(50)); TaskMap.Enums.EnumTaskProgress tempTaskProgress = tempValue.Value; if (index >= 0) { tempTaskProgress = taskProgressValues[index]; } targetList[i] = new KeyValuePair <int, TaskMap.Enums.EnumTaskProgress>(tempKey, tempTaskProgress); EditorGUILayout.EndHorizontal(); } }; //显示条件 if (monsterDataInfo.TaskToShowList == null) { monsterDataInfo.TaskToShowList = new List <KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> >(); } if (GUILayout.Button("添加显示条件")) { monsterDataInfo.TaskToShowList.Add(new KeyValuePair <int, TaskMap.Enums.EnumTaskProgress>()); } ShowHideTaskAction(monsterDataInfo.TaskToShowList); //隐藏条件 if (monsterDataInfo.TaskToHideList == null) { monsterDataInfo.TaskToHideList = new List <KeyValuePair <int, TaskMap.Enums.EnumTaskProgress> >(); } if (GUILayout.Button("添加隐藏条件")) { monsterDataInfo.TaskToHideList.Add(new KeyValuePair <int, TaskMap.Enums.EnumTaskProgress>()); } ShowHideTaskAction(monsterDataInfo.TaskToHideList); //物品掉落 if (monsterDataInfo.ItemDropRates == null) { monsterDataInfo.ItemDropRates = new float[0]; } if (monsterDataInfo.ItemDropTypes == null) { monsterDataInfo.ItemDropTypes = new EnumGoodsType[0]; } int dropCount = monsterDataInfo.ItemDropRates.Length > monsterDataInfo.ItemDropTypes.Length ? monsterDataInfo.ItemDropTypes.Length : monsterDataInfo.ItemDropRates.Length; int nowDropCount = EditorGUILayout.IntField("掉落物品种类数量(类型->概率):", dropCount); if (dropCount != nowDropCount) { monsterDataInfo.ItemDropRates = ChangedArrayLength(monsterDataInfo.ItemDropRates, nowDropCount); monsterDataInfo.ItemDropTypes = ChangedArrayLength(monsterDataInfo.ItemDropTypes, nowDropCount); } string[] goodsTypeExplans = goodsTypeToFieldNameDic.Values.ToArray(); int[] goodsTypeValues = goodsTypeToFieldNameDic.Keys.Select(temp => (int)temp).ToArray(); for (int i = 0; i < nowDropCount; i++) { EditorGUILayout.BeginHorizontal(); int goodsTypeValue = EditorGUILayout.IntPopup("物品类型", (int)monsterDataInfo.ItemDropTypes[i], goodsTypeExplans, goodsTypeValues); monsterDataInfo.ItemDropTypes[i] = (EnumGoodsType)goodsTypeValue; float rate = EditorGUILayout.FloatField(monsterDataInfo.ItemDropRates[i]); rate = Mathf.Clamp(rate, 0, 1); monsterDataInfo.ItemDropRates[i] = rate; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); #endregion #region 怪物的AI信息 EditorGUILayout.BeginVertical(GUILayout.Width(350)); string[] monsterAITypeExplans = monsterAITypeToFieldNameDic.Values.ToArray(); int[] monsterAITypeValues = monsterAITypeToFieldNameDic.Keys.Select(temp => (int)temp).ToArray(); int monsterAITypeValue = EditorGUILayout.IntPopup("怪物AI类型:", (int)monsterDataInfo.AIType, monsterAITypeExplans, monsterAITypeValues); if ((int)monsterDataInfo.AIType != monsterAITypeValue || monsterDataInfo.AIData == null) { monsterDataInfo.AIType = (EnumMonsterAIType)monsterAITypeValue; MonsterAIDataStruct monsterAIDataStruct = monsterDataInfo.AIData; try { monsterDataInfo.AIData = (MonsterAIDataStruct)Activator.CreateInstance(typeof(MonsterAIDataStruct).Assembly.GetType("MonsterAIData_" + monsterDataInfo.AIType.ToString())); } catch { } if (monsterAIDataStruct != null && monsterDataInfo.AIData != null) { monsterDataInfo.AIData.FollowDistance = monsterAIDataStruct.FollowDistance; monsterDataInfo.AIData.UpdateTime = monsterAIDataStruct.UpdateTime; } } aiDataScrollPostion = EditorGUILayout.BeginScrollView(aiDataScrollPostion); if (monsterDataInfo.AIData != null) { monsterDataInfo.AIData.UpdateTime = EditorGUILayout.FloatField("怪物刷新时间:", monsterDataInfo.AIData.UpdateTime); monsterDataInfo.AIData.FollowDistance = EditorGUILayout.FloatField("跟随的最远距离:", monsterDataInfo.AIData.FollowDistance); //反射出不同类型的数据 Type thisAIDataType = typeof(MonsterAIDataStruct).Assembly.GetType("MonsterAIData_" + monsterDataInfo.AIType.ToString()); FieldInfo[] fieldInfos = thisAIDataType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (FieldInfo fieldInfo in fieldInfos) { FieldExplanAttribute fieldExplan = fieldInfo.GetCustomAttributes(typeof(FieldExplanAttribute), false).OfType <FieldExplanAttribute>().FirstOrDefault(); if (fieldExplan != null) { if (fieldInfo.FieldType.Equals(typeof(float))) { float value = EditorGUILayout.FloatField(fieldExplan.GetExplan(), (float)fieldInfo.GetValue(monsterDataInfo.AIData)); fieldInfo.SetValue(monsterDataInfo.AIData, value); } else if (fieldInfo.FieldType.Equals(typeof(int))) { int value = EditorGUILayout.IntField(fieldExplan.GetExplan(), (int)fieldInfo.GetValue(monsterDataInfo.AIData)); fieldInfo.SetValue(monsterDataInfo.AIData, value); } else if (fieldInfo.FieldType.Equals(typeof(bool))) { bool value = EditorGUILayout.Toggle(fieldExplan.GetExplan(), (bool)fieldInfo.GetValue(monsterDataInfo.AIData)); fieldInfo.SetValue(monsterDataInfo.AIData, value); } //还有其他的在后面添加..... } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); #endregion } EditorGUILayout.EndHorizontal(); }
/// <summary> /// 检测怪物数据的状态 /// 和玩家位置进行对比,用于创建移动或设置怪物AI /// </summary> private void CheckMonsterDataInfoState() { if (monsterDataInfos == null || thisSceneCanCheckMonsterObjDic == null || allMonsterObjDic == null || thisSceneCanCheckMonsterObjList == null) { return; } IPlayerState iPlayerState = GameState.Instance.GetEntity <IPlayerState>(); if (iPlayerState.PlayerObj == null) { return; } //判断大区域 bool objListChanged = false;//对象集合是否发生了变化 //检测触发区域是否会发生变化 foreach (MonsterDataInfo monsterDataInfo in monsterDataInfos) { float distance = Vector2.Distance( new Vector2(monsterDataInfo.Center.x, monsterDataInfo.Center.z) , new Vector2(iPlayerState.PlayerObj.transform.position.x, iPlayerState.PlayerObj.transform.position.z)); if (distance > monsterDataInfo.Range + MaxRangeLeaveDistance) { if (thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { thisSceneCanCheckMonsterObjDic.Remove(monsterDataInfo); objListChanged = true; } } else if (distance <= monsterDataInfo.Range) { //获取当前任务状态是否可以显示 bool taskPass = monsterDataInfo.CanShowThis(temp => { TaskMap.RunTimeTaskInfo tempTaskInfoStruct = runtimeTaskData.GetTasksWithID(temp, false); if (tempTaskInfoStruct == null) { return(TaskMap.Enums.EnumTaskProgress.NoTake); } return(tempTaskInfoStruct.TaskProgress); }); if (taskPass)//可以显示 { if (!thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { if (!allMonsterObjDic.ContainsKey(monsterDataInfo)) { allMonsterObjDic.Add(monsterDataInfo, new List <GameObject>()); } thisSceneCanCheckMonsterObjDic.Add(monsterDataInfo, allMonsterObjDic[monsterDataInfo]); objListChanged = true; } } else//不可以显示 { if (thisSceneCanCheckMonsterObjDic.ContainsKey(monsterDataInfo)) { thisSceneCanCheckMonsterObjDic.Remove(monsterDataInfo); objListChanged = true; } } } } //移除所有对象字典空元素 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in allMonsterObjDic) { tempData.Value.RemoveAll(temp => temp == null); } //检测触发区域内的对象生成情况 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in thisSceneCanCheckMonsterObjDic) { MonsterDataInfo monsterDataInfo = tempData.Key; switch (monsterDataInfo.AIType) { case EnumMonsterAIType.Trigger: //触发型(更新时间到了并且在触发区域被且没有任何怪物时生成) MonsterAIData_Trigger monsterAIData_Trigger = monsterDataInfo.AIData as MonsterAIData_Trigger; if (monsterAIData_Trigger != null && tempData.Value.Count == 0 && monsterAIData_Trigger.NowUpdateTime <= 0) { float distance = Vector2.Distance( new Vector2(monsterDataInfo.Center.x, monsterDataInfo.Center.z) , new Vector2(iPlayerState.PlayerObj.transform.position.x, iPlayerState.PlayerObj.transform.position.z)); if (distance < monsterAIData_Trigger.TriggerRange && monsterDataInfo.MonsterPrefab != null) { monsterAIData_Trigger.NowUpdateTime = monsterAIData_Trigger.UpdateTime; //生成怪物 for (int i = 0; i < monsterAIData_Trigger.Count; i++) { Vector3 createPos = new Vector3( UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_Trigger.CreateRange, monsterDataInfo.Center.x + monsterAIData_Trigger.CreateRange), monsterDataInfo.Center.y, UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_Trigger.CreateRange, monsterDataInfo.Center.z + monsterAIData_Trigger.CreateRange)); GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab, createPos, Quaternion.identity); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) //createObj.transform.position = new Vector3( // UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_Trigger.TriggerRange, monsterDataInfo.Center.x + monsterAIData_Trigger.TriggerRange), // monsterDataInfo.Center.y, // UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_Trigger.TriggerRange, monsterDataInfo.Center.z + monsterAIData_Trigger.TriggerRange)); } objListChanged = true; } } break; case EnumMonsterAIType.GoOnPatrol: //巡逻型(更新时间到了并且怪物集合数量少与最大数量时生成) MonsterAIData_GoOnPatrol monsterAIData_GoOnPatrol = monsterDataInfo.AIData as MonsterAIData_GoOnPatrol; if (monsterAIData_GoOnPatrol != null && tempData.Value.Count < monsterAIData_GoOnPatrol.Count && monsterAIData_GoOnPatrol.NowUpdateTime <= 0) { monsterAIData_GoOnPatrol.NowUpdateTime = monsterAIData_GoOnPatrol.UpdateTime; //生成怪物 int createCount = monsterAIData_GoOnPatrol.Count - tempData.Value.Count; for (int i = 0; i < createCount; i++) { Vector3 createPos = new Vector3( UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.x + monsterAIData_GoOnPatrol.CreateRange), monsterDataInfo.Center.y, UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.z + monsterAIData_GoOnPatrol.CreateRange)); GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab, createPos, Quaternion.identity); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) //createObj.transform.position = new Vector3( // UnityEngine.Random.Range(monsterDataInfo.Center.x - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.x + monsterAIData_GoOnPatrol.CreateRange), // monsterDataInfo.Center.y, // UnityEngine.Random.Range(monsterDataInfo.Center.z - monsterAIData_GoOnPatrol.CreateRange, monsterDataInfo.Center.z + monsterAIData_GoOnPatrol.CreateRange)); } objListChanged = true; } break; case EnumMonsterAIType.Boss: //boss型(更新时间到了并且怪物没有生成是生成) MonsterAIData_Boss monsterAIData_Boss = monsterDataInfo.AIData as MonsterAIData_Boss; if (monsterAIData_Boss != null && tempData.Value.Count == 0 && monsterAIData_Boss.NowUpdateTime <= 0) { monsterAIData_Boss.NowUpdateTime = monsterAIData_Boss.UpdateTime; //生成怪物 GameObject createObj = GameObject.Instantiate <GameObject>(monsterDataInfo.MonsterPrefab); MonsterControl monsterControl = createObj.AddComponent <MonsterControl>(); monsterControl.SameGroupObjList = tempData.Value; monsterControl.monsterDataInfo = tempData.Key; tempData.Value.Add(createObj); //设置位置(MonsterControl内部会进行y轴的设置) createObj.transform.position = new Vector3( monsterDataInfo.Center.x, monsterDataInfo.Center.y, monsterDataInfo.Center.z); objListChanged = true; } break; } } //刷新时间 foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in allMonsterObjDic) { switch (tempData.Key.AIType) { case EnumMonsterAIType.Trigger: if (tempData.Value.Count == 0 && tempData.Key.AIData != null) { tempData.Key.AIData.NowUpdateTime -= UpdateTime; } break; case EnumMonsterAIType.GoOnPatrol: MonsterAIData_GoOnPatrol monsterAIData_GoOnPatrol = tempData.Key.AIData as MonsterAIData_GoOnPatrol; if (monsterAIData_GoOnPatrol != null && tempData.Value.Count < monsterAIData_GoOnPatrol.Count) { monsterAIData_GoOnPatrol.NowUpdateTime -= UpdateTime; } break; case EnumMonsterAIType.Boss: if (tempData.Value.Count == 0 && tempData.Key.AIData != null) { tempData.Key.AIData.NowUpdateTime -= UpdateTime; } break; } } //重新构建检测集合 if (objListChanged) { thisSceneCanCheckMonsterObjList.Clear(); foreach (KeyValuePair <MonsterDataInfo, List <GameObject> > tempData in thisSceneCanCheckMonsterObjDic) { thisSceneCanCheckMonsterObjList.AddRange(tempData.Value); } } //移除检测集合的空元素 thisSceneCanCheckMonsterObjList.RemoveAll(temp => temp == null); }