FightingMapState.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace YLBattle
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public class FightingMapState
  9. {
  10. private FightingMap mOwner = null;
  11. /// <summary>
  12. /// 当前状态
  13. /// </summary>
  14. private MapBaseState mCurrentState = null;
  15. /// <summary>
  16. /// 上一个状态
  17. /// </summary>
  18. private MapBaseState mPreviousState = null;
  19. #region(行为状态)
  20. private MapBaseState mLoading = null;
  21. private MapBaseState mIdle = null;
  22. private MapBaseState mReady = null;
  23. private MapBaseState mArrival = null;
  24. private MapBaseState mRotate = null;
  25. private MapBaseState mMove = null;
  26. private MapBaseState mDrag = null;
  27. private MapBaseState mOver = null;
  28. private MapBaseState mBoss = null;
  29. private MapBaseState mBeHit = null;
  30. private MapBaseState mPVP = null;
  31. /// <summary>
  32. /// 打断当前状态
  33. /// </summary>
  34. public void BreakCurrentState()
  35. {
  36. this.ChangeState(EMapState.Idle, null);
  37. }
  38. /// <summary>
  39. /// 获取上一次状态
  40. /// </summary>
  41. /// <returns>状态对象</returns>
  42. public MapBaseState GetPreviousState()
  43. {
  44. return this.mPreviousState;
  45. }
  46. #endregion
  47. /// <summary>
  48. /// 初始化
  49. /// </summary>
  50. /// <param name="param">所有者</param>
  51. public void Initialize(FightingMap param)
  52. {
  53. this.mOwner = param;
  54. this.mLoading = new MapLoading(this.mOwner);
  55. this.mIdle = new MapIdle(this.mOwner);
  56. this.mReady = new MapReady(this.mOwner);
  57. this.mBoss = new MapBoss(this.mOwner);
  58. this.mArrival = new MapArrival(this.mOwner);
  59. this.mRotate = new MapRotate(this.mOwner);
  60. this.mMove = new MapMove(this.mOwner);
  61. this.mDrag = new MapDrag(this.mOwner);
  62. this.mOver = new MapOver(this.mOwner);
  63. this.mBeHit = new MapBeHit(this.mOwner);
  64. this.mPVP = new MapPVP(this.mOwner);
  65. this.SetCurrentState(this.mReady, null);
  66. }
  67. /// <summary>
  68. /// 设置当前状态
  69. /// </summary>
  70. /// <param name="current">状态</param>
  71. /// <param name="param">参数</param>
  72. public void SetCurrentState(MapBaseState current, object param)
  73. {
  74. this.mCurrentState = current;
  75. this.mCurrentState.OnEnter(param);
  76. }
  77. /// <summary>
  78. /// 获取当前行为状态
  79. /// </summary>
  80. /// <returns>状态对象</returns>
  81. public MapBaseState GetCurrentState()
  82. {
  83. return this.mCurrentState;
  84. }
  85. /// <summary>
  86. /// 状态周期调度
  87. /// </summary>
  88. /// <param name="now">当前逻辑时间</param>
  89. public void OnUpdateState()
  90. {
  91. if (null != this.mCurrentState)
  92. {
  93. this.mCurrentState.OnUpdate();
  94. }
  95. }
  96. /// <summary>
  97. /// 切换到指定状态
  98. /// </summary>
  99. /// <param name="newState">新的状态</param>
  100. /// <param name="param">状态初始化参数</param>
  101. public void ChangeState(EMapState newState, object param)
  102. {
  103. if (this.mOwner.PlatAnimatorName == "0LaYuan")
  104. {
  105. return;
  106. }
  107. MapBaseState st = null;
  108. switch (newState)
  109. {
  110. case EMapState.Loading:
  111. st = this.mLoading;
  112. break;
  113. case EMapState.Idle:
  114. st = this.mIdle;
  115. break;
  116. case EMapState.Arrival:
  117. st = this.mArrival;
  118. break;
  119. case EMapState.Rotate:
  120. st = this.mRotate;
  121. break;
  122. case EMapState.Move:
  123. st = this.mMove;
  124. break;
  125. case EMapState.Over:
  126. st = this.mOver;
  127. break;
  128. case EMapState.Drag:
  129. st = this.mDrag;
  130. break;
  131. case EMapState.Ready:
  132. st = this.mReady;
  133. break;
  134. case EMapState.Boss:
  135. st = this.mBoss;
  136. break;
  137. case EMapState.BeHit:
  138. st = this.mBeHit;
  139. break;
  140. default:
  141. st = null;
  142. break;
  143. }
  144. if (null == st)
  145. {
  146. return;
  147. }
  148. this.mCurrentState.OnLeave();
  149. this.mPreviousState = this.mCurrentState;
  150. this.mCurrentState = st;
  151. this.mCurrentState.OnEnter(param);
  152. }
  153. }
  154. }