| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.SceneManagement;
- public class BaseBattleScene
- {
- protected BaseBattle mBattle;
- protected string mSceneName;
- protected Scene mScene;
- protected bool mHasStartLoad = false; //是否已经开始加载
- protected bool bLoaded = false;
- public GameObject CameraContainer { get; private set; }
- public GameObject ComingCamera { get; private set; }
- public GameObject StoryCameraGo { get; private set; }
- public Transform CameraTrans { get; private set; }
- public bool IsDisposed { get; private set; }
- public bool IsLoading { get { return mHasStartLoad && !bLoaded; } }
- public bool IsLoaded { get { return mHasStartLoad && bLoaded; } }
- public BaseBattleScene(BaseBattle battle,string sceneName)
- {
- mBattle = battle;
- mSceneName = sceneName;
- IsDisposed = false;
- }
- public void StartLoad()
- {
- if (string.IsNullOrEmpty(mSceneName))
- return;
- mHasStartLoad = true;
- bLoaded = false;
- LoadScene();
- EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_LOAD_BEGIN, true));
- }
- void LoadScene(bool isReload = false)
- {
- EventMgr.AddEventListener<string>(ECoreEventType.EID_Scene_Loaded, SceneLoaded);
- SceneMgr.Instance.AsyncLoadMainScene(mSceneName);
- }
- void SceneLoaded(CoreEvent<string> sceneName)
- {
- EventMgr.RemoveEventListener<string>(ECoreEventType.EID_Scene_Loaded, SceneLoaded);
- bLoaded = true;
- mScene = SceneManager.GetSceneByName(mSceneName);
- if (mScene.isLoaded)
- {
- GameObject[] rootObjs = mScene.GetRootGameObjects();
- CameraContainer = rootObjs.FindFirst(a => a.name.CompareTo(Constants.go_name_camera_target) == 0);
- if (CameraContainer != null)
- {
- Camera cam = CameraContainer.GetComponentInChildren<Camera>();
- if (cam != null)
- {
- if(cam.cullingMask == 0)
- {
- cam.cullingMask = BattleCamera.Instance.CullingMask;
- }
- CameraTrans = cam.transform;
- }
- }
- GameObject designGo = rootObjs.FindFirst(a => a.name.CompareTo(Constants.design_go) == 0);
- if (designGo)
- {
- GlobalTrigger globalTrigger = designGo.GetComponent<GlobalTrigger>();
- if (globalTrigger)
- {
- mBattle.globalTrigger = globalTrigger;
- }
- }
- ComingCamera = GameObject.Find(Constants.coming_camera_target);
- OnSceneLoaded();
- }
- }
- public virtual void OnSceneLoaded()
- {
- }
- public virtual void SetSceneOjbVis(SceneObjData obj)
- {
- }
- public virtual void Dispose()
- {
- if (IsDisposed)
- return;
- mBattle = null;
- CameraContainer = null;
- IsDisposed = true;
- mHasStartLoad = false;
- bLoaded = false;
- }
- }
|