BaseBattleScene.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.SceneManagement;
  4. public class BaseBattleScene
  5. {
  6. protected BaseBattle mBattle;
  7. protected string mSceneName;
  8. protected Scene mScene;
  9. protected bool mHasStartLoad = false; //是否已经开始加载
  10. protected bool bLoaded = false;
  11. public GameObject CameraContainer { get; private set; }
  12. public GameObject ComingCamera { get; private set; }
  13. public GameObject StoryCameraGo { get; private set; }
  14. public Transform CameraTrans { get; private set; }
  15. public bool IsDisposed { get; private set; }
  16. public bool IsLoading { get { return mHasStartLoad && !bLoaded; } }
  17. public bool IsLoaded { get { return mHasStartLoad && bLoaded; } }
  18. public BaseBattleScene(BaseBattle battle,string sceneName)
  19. {
  20. mBattle = battle;
  21. mSceneName = sceneName;
  22. IsDisposed = false;
  23. }
  24. public void StartLoad()
  25. {
  26. if (string.IsNullOrEmpty(mSceneName))
  27. return;
  28. mHasStartLoad = true;
  29. bLoaded = false;
  30. LoadScene();
  31. EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_LOAD_BEGIN, true));
  32. }
  33. void LoadScene(bool isReload = false)
  34. {
  35. EventMgr.AddEventListener<string>(ECoreEventType.EID_Scene_Loaded, SceneLoaded);
  36. SceneMgr.Instance.AsyncLoadMainScene(mSceneName);
  37. }
  38. void SceneLoaded(CoreEvent<string> sceneName)
  39. {
  40. EventMgr.RemoveEventListener<string>(ECoreEventType.EID_Scene_Loaded, SceneLoaded);
  41. bLoaded = true;
  42. mScene = SceneManager.GetSceneByName(mSceneName);
  43. if (mScene.isLoaded)
  44. {
  45. GameObject[] rootObjs = mScene.GetRootGameObjects();
  46. CameraContainer = rootObjs.FindFirst(a => a.name.CompareTo(Constants.go_name_camera_target) == 0);
  47. if (CameraContainer != null)
  48. {
  49. Camera cam = CameraContainer.GetComponentInChildren<Camera>();
  50. if (cam != null)
  51. {
  52. if(cam.cullingMask == 0)
  53. {
  54. cam.cullingMask = BattleCamera.Instance.CullingMask;
  55. }
  56. CameraTrans = cam.transform;
  57. }
  58. }
  59. GameObject designGo = rootObjs.FindFirst(a => a.name.CompareTo(Constants.design_go) == 0);
  60. if (designGo)
  61. {
  62. GlobalTrigger globalTrigger = designGo.GetComponent<GlobalTrigger>();
  63. if (globalTrigger)
  64. {
  65. mBattle.globalTrigger = globalTrigger;
  66. }
  67. }
  68. ComingCamera = GameObject.Find(Constants.coming_camera_target);
  69. OnSceneLoaded();
  70. }
  71. }
  72. public virtual void OnSceneLoaded()
  73. {
  74. }
  75. public virtual void SetSceneOjbVis(SceneObjData obj)
  76. {
  77. }
  78. public virtual void Dispose()
  79. {
  80. if (IsDisposed)
  81. return;
  82. mBattle = null;
  83. CameraContainer = null;
  84. IsDisposed = true;
  85. mHasStartLoad = false;
  86. bLoaded = false;
  87. }
  88. }