| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- #if UNITY_EDITOR
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- using System.Collections.Generic;
- public class EditorBattleMgr : SingletonMono<EditorBattleMgr>
- {
- LogicBattleField battleField = null;
- FighterManager fighterMgr = null;
- ReadyPoint actorSpawnPoint = null;
- SpawnPoint monsterSpawnPoint = null;
- bool bInitedFighter = false;
- bool bStartGame = false;
- public override void InitMgr()
- {
- base.InitMgr();
- }
- private void Start()
- {
- Constants.isOffline = true;
- EventMgr.AddEventListener<int>(ECoreEventType.EID_ConfigMgrInit, OnCfgLoaded);
- MusicMgr.Instance.InitMgr();
- ConfigMgr.CreateInstance();
- GameObject readyPointGo = GameObject.Find("ActorBornPoint");
- if(readyPointGo!=null)
- {
- actorSpawnPoint = readyPointGo.GetComponent<ReadyPoint>();
- }
- GameObject spawnPointGo = GameObject.Find("SpawnPoint");
- if(spawnPointGo!=null)
- {
- monsterSpawnPoint = spawnPointGo.GetComponent<SpawnPoint>();
- }
- }
- private void OnCfgLoaded(CoreEvent<int> ce)
- {
- if(ce.Data == 1)
- {
- StartGame();
- }
- }
- void Update()
- {
- if (!bInitedFighter)
- {
- if(bStartGame && !BattlePrepareManager.Instance.IsLoading)
- {
- Spawn();
- }
- return;
- }
- if(battleField != null)
- {
- battleField.Update(Time.deltaTime);
- }
- if (fighterMgr != null)
- {
- fighterMgr.FixedUpdateByEditor(Time.deltaTime);
- EffectManager.Instance.Update(Time.deltaTime);
- }
- }
- public void Restart()
- {
- EndGame();
- StartGame();
- }
- public void StartGame()
- {
- if(actorSpawnPoint == null)
- {
- EditorUtility.DisplayDialog("错误", "角色出生点没有,请配置!!", "确定");
- return;
- }
- if(monsterSpawnPoint == null)
- {
- EditorUtility.DisplayDialog("错误", "怪物出生点没有,请配置!", "确定");
- return;
- }
- List<ActorData> teamActors = new List<ActorData>();
- List<ActorData> enemyActors = new List<ActorData>();
- for (int idx = 0; idx < 4; idx++)
- {
- string idKey = string.Format("TrainCamp_HeroID_{0}", idx);
- string levelKey = string.Format("TrainCamp_HeroLevel_{0}", idx);
- string skillIdKey = string.Format("TrainCamp_HeroSkillId_{0}", idx);
- string skillLvKey = string.Format("TrainCamp_HeroSkillLv_{0}", idx);
- string genderKey = string.Format("TrainCamp_Gender_{0}", idx);
- string invincibleKey = string.Format("TrainCamp_Invincible_{0}", idx);
- int id = 0, lv = 0, skillId = 0, skillLv = 0;
- Role_Gender gender = Role_Gender.Male;
- bool invincible = false;
- if (PlayerPrefs.HasKey(idKey))
- id = PlayerPrefs.GetInt(idKey);
- if (PlayerPrefs.HasKey(levelKey))
- lv = PlayerPrefs.GetInt(levelKey);
- if (PlayerPrefs.HasKey(skillIdKey))
- skillId = PlayerPrefs.GetInt(skillIdKey);
- if (PlayerPrefs.HasKey(skillLvKey))
- skillLv = PlayerPrefs.GetInt(skillLvKey);
- if (PlayerPrefs.HasKey(genderKey))
- gender = (Role_Gender)PlayerPrefs.GetInt(genderKey);
- if (PlayerPrefs.HasKey(invincibleKey))
- invincible = PlayerPrefs.GetInt(invincibleKey) > 0 ? true : false;
- if (id >0 && lv > 0 && skillId > 0 && skillLv > 0)
- {
- SkillParam skill = new SkillParam();
- skill.skillId = skillId;
- skill.skillLv = skillLv;
- List<SkillParam> skills = new List<SkillParam>();
- skills.Add(skill);
- ActorData hero = null;
- if (idx == 0)
- {
- HeroActorData temp = ActorData.CreatePlayerActor(100000 + idx, id * 10 + (int)gender, lv, skills!=null?skills.ToArray():null) as HeroActorData;
- temp.SetProfessionId(id);
- hero = temp;
- }
- else
- {
- hero = ActorData.CreateFellowActor(100000 + idx, id, lv, skills!=null?skills.ToArray():null);
- }
- hero.Invincible = invincible;
- teamActors.Add(hero);
- }
- }
- for (int idx = 0; idx < 6; idx++)
- {
- string idKey = string.Format("TrainCamp_NpcID_{0}", idx);
- string levelKey = string.Format("TrainCamp_NpcLevel_{0}", idx);
- string posKey = string.Format("TrainCamp_NpcPos_{0}", idx);
- string invincibleKey = string.Format("TrainCamp_NpcInvincible_{0}", idx);
- int id = 0, level = 0, pos = 1;
- bool invincible = false;
- if (PlayerPrefs.HasKey(idKey))
- id = PlayerPrefs.GetInt(idKey);
- if (PlayerPrefs.HasKey(levelKey))
- level = PlayerPrefs.GetInt(levelKey);
- else
- level = 1;
- if (PlayerPrefs.HasKey(posKey))
- pos = PlayerPrefs.GetInt(posKey);
- if (PlayerPrefs.HasKey(invincibleKey))
- invincible = PlayerPrefs.GetInt(invincibleKey) > 0 ? true : false;
- if (id > 0 && level > 0 )
- {
- ActorData npc = ActorData.CreateNpcPlayerActor(200000+ idx, id, level);
- npc.PositionValue = pos;
- npc.Invincible = invincible;
- enemyActors.Add(npc);
- }
- }
- if (teamActors.Count == 0)
- {
- EditorUtility.DisplayDialog("错误", "我方英雄没有一个合格的测试者", "确定");
- return;
- }
- if(enemyActors.Count == 0)
- {
- EditorUtility.DisplayDialog("错误", "请正确部署最少一个怪", "确定");
- return;
- }
- bool enableLog = false;
- if(PlayerPrefs.HasKey("EnabledLog"))
- enableLog = PlayerPrefs.GetInt("EnabledLog") > 0 ? true:false;
- if(enableLog)
- {
- DebugHelper.LogLevel = LogLevel.Info;
- }
-
- fighterMgr = new FighterManager(null);
- fighterMgr.AddFighters(teamActors.ToArray(), eTeamType.Friend);
- fighterMgr.AddFighters(enemyActors.ToArray(), eTeamType.Enemy);
- fighterMgr.ParseLoad();
- BattlePrepareManager.Instance.StartLoad();
- bStartGame = true;
- }
- void Spawn()
- {
- if (bInitedFighter) return;
- if (battleField == null) {
- battleField = new LogicBattleField(null, null);
- }
-
- for (int idx = 0; idx < fighterMgr.AllFighters.Count; idx++)
- {
- Fighter f = fighterMgr.AllFighters[idx];
- f.StateData.IsInvincible = f.Actor.Invincible;
- if (f.TeamSide == eTeamType.Friend)
- {
- f.Spawn(actorSpawnPoint.GetBornPointPos(f.ProfType,f.ReadyPosOrder).heroPos, Vector3.forward, Quaternion.identity);
- }
- else
- {
- Vector3 pos = Vector3.zero;
- Transform p = monsterSpawnPoint.transform.Find("point" + f.PositionValue);
- if (p != null)
- pos = p.position;
- f.Spawn(pos, Vector3.back, Quaternion.identity);
- }
- battleField.AddFighter(f);
- }
- bInitedFighter = true;
- battleField.CurrentState = LogicBattleFieldStateType.EditorFighting;
- }
- public void EndGame()
- {
- if (fighterMgr != null)
- {
- fighterMgr.Dispose();
- fighterMgr = null;
- }
- //ScaleTimeInfo.Instance.Stop();
- EffectManager.Instance.Clear();
- if (MusicMgr.HasInstance())
- MusicMgr.Instance.CleanBeforeChangeScene();
- }
- }
- #endif
|