| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.SceneManagement;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- public class LogicBattleScene : BaseBattleScene
- {
- const string bossintro_camera_go = "bossIntro_cam";
- const string scene_root_name = "SceneRoot";
- #region fields
- private string switchGoName;
- private GameObject[] mRootObjs = null;
- private List<SpawnPointCfg> mBossSpawnPointList = new List<SpawnPointCfg>();
- private List<SpawnPointCfg> mSpawnPointList = new List<SpawnPointCfg>();
- private ReadyPoint mActorBornPoint;
- private LogicBattle mLogicBattle;
- private MapItemData mMapItem;
- private int mBattleIdx = -1;
- private int[] pathList = null;
- private int mCurMonsterSpawnPointIdx = 0;
- private SpawnPointCfg mCurrentMonsterSpawnPoint;
- private BossBattleEffect mBattleEffect;
- private CruiseEffect mCruiseEffect;
- private SceneSkyboxMatContainer mSceneSkyboxMatContainer;
- private Tree mTree;
- public float delTime = 2;
- public ReadyPoint ActorBornPoint
- {
- get { return mActorBornPoint; }
- }
-
- public List<SpawnPointCfg> SpawnPointList
- {
- get { return mSpawnPointList; }
- }
- public SpawnPointCfg MapMonsterSpawnPoint
- {
- get
- {
- return mCurrentMonsterSpawnPoint;
- }
- }
- public SpawnPointCfg BossSpawnPoint
- {
- get
- {
- if (mBossSpawnPointList == null || mBossSpawnPointList.Count == 0) return null;
- return mBossSpawnPointList[CurrentBattleInfo.bossBornIdx];
- }
- }
- public LogicBattle Battle { get { return mLogicBattle; } }
- public MapItemData MapData { get { return mMapItem; } }
- public LevelItem CurrentBattleInfo { get; private set; }
- public LogicBattleField CurrentBattleField { get; private set; }
- public GameMode GameMode { get { return mMapItem != null ? mMapItem.gameMode : GameMode.GameMode_Normal; } }
- public GameObject BossIntroCamGo { get; private set; }
- public GameObject SceneRootGo { get; private set; }
- public int CurrentBattleIdx { get { return mBattleIdx; } }
- public bool HasNextBattle { get { return mMapItem != null && mMapItem.battles != null && mBattleIdx + 1 < mMapItem.battles.Length; } }
- SceneObjData[] mObjDataList;
- #endregion
- public LogicBattleScene(LogicBattle battle)
- :base(battle,"")
- {
- mLogicBattle = battle;
- if (mMapItem == null)
- {
- mMapItem = new MapItemData(battle.SceneId,mLogicBattle.CurSceneItem.LevelItems);
- LoadMapSpawnPointCfg(mMapItem.levelname);
- mSceneName = mMapItem.levelname;
- }
- mBattleIdx = battle.StartInfo.StartBattleIdx - 1;
- RegisterEvents();
- }
- public void CreateReplayBattle(int battleIdx)
- {
- CurrentBattleInfo = mMapItem.battles[battleIdx];
- pathList = CurrentBattleInfo.PathList;
- if (pathList == null || pathList.Length == 0)
- {
- pathList = new int[mSpawnPointList.Count];
- for (int idx = 0; idx < pathList.Length; idx++)
- {
- pathList[idx] = idx;
- }
- }
- SelectSpawnPoint();
- CurrentBattleField = CreateBattleField(CurrentBattleInfo.LevelId);
- CurrentBattleField.FieldCenter = mCurrentMonsterSpawnPoint.PointList[1].pos;
- mLogicBattle.SetBattleField(CurrentBattleField);
- mLogicBattle.StartInfo.curLevelItem = CurrentBattleInfo;
- CurrentBattleField.killBoss = true;
- CurrentBattleField.IsPlayingRecorder = true;
- }
- public void ReopenBattle()
- {
- if (mMapItem != null &&
- mMapItem.battles != null &&
- mBattleIdx < mMapItem.battles.Length &&
- mBattleIdx >= 0)
- {
- CurrentBattleInfo = mMapItem.battles[mBattleIdx];
- pathList = CurrentBattleInfo.PathList;
- if (pathList == null || pathList.Length == 0)
- {
- pathList = new int[mSpawnPointList.Count];
- for (int idx = 0; idx < pathList.Length; idx++)
- {
- pathList[idx] = idx;
- }
- }
- SelectSpawnPoint();
- CurrentBattleField = CreateBattleField(CurrentBattleInfo.LevelId);
- CurrentBattleField.FieldCenter = mCurrentMonsterSpawnPoint.PointList[1].pos;
- mLogicBattle.SetBattleField(CurrentBattleField);
- mLogicBattle.StartInfo.curLevelItem = CurrentBattleInfo;
- }
- }
- public bool NextBattle()
- {
- mBattleIdx++;
- if (mMapItem != null &&
- mMapItem.battles != null &&
- mBattleIdx < mMapItem.battles.Length &&
- mBattleIdx >= 0)
- {
- CurrentBattleInfo = mMapItem.battles[mBattleIdx];
- pathList = CurrentBattleInfo.PathList;
- if (pathList == null || pathList.Length == 0)
- {
- pathList = new int[mSpawnPointList.Count];
- for (int idx = 0; idx < pathList.Length; idx++)
- {
- pathList[idx] = idx;
- }
- }
- SelectSpawnPoint();
- CurrentBattleField = CreateBattleField(CurrentBattleInfo.LevelId);
- CurrentBattleField.FieldCenter = mCurrentMonsterSpawnPoint.PointList[1].pos;
- mLogicBattle.SetBattleField(CurrentBattleField);
- mLogicBattle.StartInfo.curLevelItem = CurrentBattleInfo;
- return true;
- }
- else
- {
- CurrentBattleInfo = null;
- CurrentBattleField = null;
- mLogicBattle.SetBattleField(null);
- return false;
- }
- }
- public void SelectSpawnPoint()
- {
- if (mSpawnPointList == null) return;
- int idx = pathList[mCurMonsterSpawnPointIdx++];
- if (mCurMonsterSpawnPointIdx >= pathList.Length)
- mCurMonsterSpawnPointIdx = 0;
- if(idx < 0)
- {
- DebugHelper.LogError("mCurMonsterSpawnPointIdx 从pathList中获取的下表小于0"+ mCurMonsterSpawnPointIdx);
- idx = 0;
- }
- mCurrentMonsterSpawnPoint = mSpawnPointList[idx];
- }
- public void SetEffectVisible(bool bossBattle)
- {
- if(bossBattle)
- {
- if(mBattleEffect != null)
- {
- mBattleEffect.gameObject.SetActive(true);
- }
- if(mCruiseEffect != null)
- {
- mCruiseEffect.gameObject.SetActive(false);
- }
- }
- else
- {
- if (mBattleEffect != null)
- {
- mBattleEffect.gameObject.SetActive(false);
- }
- if (mCruiseEffect != null)
- {
- mCruiseEffect.gameObject.SetActive(true);
- }
- }
- }
- public void ChangeSkyboxMat(string matName)
- {
- if (mSceneSkyboxMatContainer == null) return;
- if(mSceneSkyboxMatContainer.ChangeSkyboxMat(matName))
- {
- bRestoreSkyboxDirty = true;
- }
- }
- private bool bRestoreSkyboxDirty = false;
- public void RestoreSkyboxMat()
- {
- if (mSceneSkyboxMatContainer == null) return;
- if (bRestoreSkyboxDirty)
- {
- mSceneSkyboxMatContainer.RestoreSkyboxMat();
- bRestoreSkyboxDirty = false;
- }
- }
- private void RegisterEvents()
- {
- EventMgr.AddEventListener<string>(ECoreEventType.EID_SHOW_SCENE_GO, OnShowSceneGo);
- EventMgr.AddEventListener<bool>(ECoreEventType.EID_RESTORE_SCENE, OnRestoreScene);
- EventMgr.AddEventListener<string>(ECoreEventType.EID_CHAGNE_SKYBOX_MATERIAL, OnChangeSkyboxMat);
- }
- private void UnregisterEvents()
- {
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_SHOW_SCENE_GO, OnShowSceneGo);
- EventMgr.RemoveEventListener<bool>(ECoreEventType.EID_RESTORE_SCENE, OnRestoreScene);
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_CHAGNE_SKYBOX_MATERIAL, OnChangeSkyboxMat);
- }
- private void OnChangeSkyboxMat(CoreEvent<string> ce)
- {
- ChangeSkyboxMat(ce.Data);
- }
- private void OnShowSceneGo(CoreEvent<string> ce)
- {
- switchGoName = ce.Data;
- GameObject go = mRootObjs.FindFirst(a => a.name.CompareTo(switchGoName) == 0);
- if (go != null)
- go.SetActive(true);
- if (SceneRootGo != null)
- SceneRootGo.SetActive(false);
- }
- private void OnRestoreScene(CoreEvent<bool> ce)
- {
- GameObject go = mRootObjs.FindFirst(a => a.name.CompareTo(switchGoName) == 0);
- if (go != null)
- go.SetActive(false);
- if (SceneRootGo != null)
- SceneRootGo.SetActive(true);
- }
- public override void OnSceneLoaded()
- {
- mRootObjs = mScene.GetRootGameObjects();
- for(int idx =0; idx < mRootObjs.Length;idx++)
- {
- if(mCruiseEffect == null)
- mCruiseEffect = mRootObjs[idx].GetComponentInChildren<CruiseEffect>();
- if (mBattleEffect == null)
- mBattleEffect = mRootObjs[idx].GetComponentInChildren<BossBattleEffect>();
- if (mCruiseEffect != null && mBattleEffect != null)
- break;
- }
- SceneRootGo = mRootObjs.FindFirst(a => a.name.CompareTo(scene_root_name) == 0);
- if(SceneRootGo!=null)
- {
- mSceneSkyboxMatContainer = SceneRootGo.GetComponentInChildren<SceneSkyboxMatContainer>();
- SceneRoot root = SceneRootGo.GetComponent<SceneRoot>();
- if(root != null)
- {
- mObjDataList = SceneRootGo.GetComponentsInChildren<SceneObjData>();
- if (mObjDataList != null && mObjDataList.Length > 0)
- {
- if (mTree == null)
- {
- mTree = new Tree(root.mainBound);
- for (int idx = 0; idx < mObjDataList.Length; idx++)
- {
- mTree.InsertObj(mObjDataList[idx]);
- }
- root.T = mTree;
- root.InitEnd = true;
- }
- }
- }
- }
- BossIntroCamGo = mRootObjs.FindFirst(a => a.name.CompareTo(bossintro_camera_go) == 0);
- GameObject spawnPoint = mRootObjs.FindFirst(a => a.name.CompareTo(Constants.actor_born_point) == 0);
- if (spawnPoint != null)
- {
- mActorBornPoint = spawnPoint.GetComponent<ReadyPoint>();
- }
- }
- private void LoadMapSpawnPointCfg(string sceneName)
- {
- string ta = ConfigMgr.Instance.GetXmlCfg("Born_" + sceneName);
- if (ta == null)
- {
- DebugHelper.LogError(sceneName + " 出生点文件不存在");
- return;
- }
- mSpawnPointList.Clear();
- mBossSpawnPointList.Clear();
- Mono.Xml.SecurityParser doc = new Mono.Xml.SecurityParser();
- try
- {
- doc.LoadXml(ta);
- }
- catch (System.Exception e)
- {
- DebugHelper.Assert(false, "exception = {0}", e.Message);
- return;
- }
- System.Security.SecurityElement root = doc.SelectSingleNode("SpawnPoints");
- if (root == null || root.Children == null) return;
- for (int idx = 0; idx < root.Children.Count; idx++)
- {
- var spNode = root.Children[idx] as System.Security.SecurityElement;
- SpawnPointCfg spCfg = new SpawnPointCfg();
- spCfg.LoadCfgXml(spNode);
- if (spCfg.PointType == SpawnPointType.Boss)
- {
- mBossSpawnPointList.Add(spCfg);
- }
- else
- {
- mSpawnPointList.Add(spCfg);
- }
- }
- //DebugHelper.LogError("----------------LoadMapSpawnPointCfg----------------");
- }
- private LogicBattleField CreateBattleField (int fieldId)
- {
- return new LogicBattleField (mLogicBattle, CurrentBattleInfo);
- }
- public override void SetSceneOjbVis(SceneObjData obj)
- {
- float dist = Vector3.Distance(obj.Center, mBattle.CurBattleField.TeamFighters[0].Position);
- if (dist < 60)
- {
- CommonUtil.SetGameObjectLayer(obj.gameObject, BattleCamera.defalutLayer);
- }
- else
- {
- CommonUtil.SetGameObjectLayer(obj.gameObject, BattleCamera.hideLayer);
- }
- }
- public void UpdateSceneTree(Vector3 pos)
- {
- if (mTree != null)
- {
- mTree.TriggerMove(BattleCamera.Instance.RealCamera, this);
- }
- }
- public override void Dispose()
- {
- if (IsDisposed)
- return;
- base.Dispose();
- mObjDataList = null;
- UnregisterEvents();
- mRootObjs = null;
- mMapItem = null;
- mLogicBattle = null;
- mBattleIdx = -1;
- CurrentBattleInfo = null;
- CurrentBattleField = null;
- mCurMonsterSpawnPointIdx = 0;
- mCurrentMonsterSpawnPoint = null;
- if (mActorBornPoint != null)
- {
- mActorBornPoint.Dispose();
- mActorBornPoint = null;
- }
- mSpawnPointList.Clear();
- mBossSpawnPointList.Clear();
- }
- }
|