TimeBattleStatePreloading.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TimeBattleStatePreloading : TimeBattleState
  4. {
  5. public static TimeBattleStatePreloading Creator(TimeBattle battle)
  6. {
  7. return new TimeBattleStatePreloading(battle);
  8. }
  9. public TimeBattleStatePreloading(TimeBattle battle):
  10. base(battle,TimeBattleStateType.Preloading)
  11. {
  12. }
  13. PreloadingStep mStep = PreloadingStep.None;
  14. public override void OnEnter()
  15. {
  16. mBattle.SetLoadSetting();
  17. LoadScene();
  18. }
  19. public override void Update(float deltaTime)
  20. {
  21. if (mStep == PreloadingStep.LoadingScene)
  22. {
  23. if (mBattle.BattleScene.IsLoaded)
  24. {
  25. LoadFlyWord();
  26. }
  27. }
  28. else if (mStep == PreloadingStep.LoadingFlywordAssets)
  29. {
  30. if (BattleFlyWordMgr.Instance.Loaded)
  31. LoadPrepareAssets();
  32. }
  33. else if (mStep == PreloadingStep.LoadingPrepareAssets)
  34. {
  35. if (!BattlePrepareManager.Instance.IsLoading)
  36. InstantiateGo();
  37. }
  38. else if (mStep == PreloadingStep.LoadingInstantiate)
  39. {
  40. OpenScreen();
  41. }
  42. else if (mStep == PreloadingStep.OpeningScreen)
  43. {
  44. EndLoad();
  45. }
  46. }
  47. public override void OnLeave()
  48. {
  49. mBattle.RestoreLoadSetting();
  50. }
  51. void LoadScene()
  52. {
  53. mStep = PreloadingStep.LoadingScene;
  54. mBattle.BattleScene.StartLoad();
  55. }
  56. void LoadFlyWord()
  57. {
  58. mBattle.NotifyLoadProgress(0.3f);
  59. mStep = PreloadingStep.LoadingFlywordAssets;
  60. BattleFlyWordMgr.Instance.StartLoad();
  61. }
  62. void LoadPrepareAssets()
  63. {
  64. mBattle.NotifyLoadProgress(0.4f);
  65. mStep = PreloadingStep.LoadingPrepareAssets;
  66. BattlePrepareManager.Instance.StartLoad();
  67. }
  68. void InstantiateGo()
  69. {
  70. mStep = PreloadingStep.LoadingInstantiate;
  71. }
  72. void OpenScreen()
  73. {
  74. mStep = PreloadingStep.OpeningScreen;
  75. }
  76. void EndLoad()
  77. {
  78. mBattle.SpawnActors();
  79. mBattle.OnLoadComplete();
  80. ChangeState(TimeBattleStateType.Battle);
  81. }
  82. }