123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using UnityEngine;
- using System.Collections;
- namespace YLBattle
- {
- /// <summary>
- ///
- /// </summary>
- public class FightingMapState
- {
- private FightingMap mOwner = null;
- /// <summary>
- /// 当前状态
- /// </summary>
- private MapBaseState mCurrentState = null;
- /// <summary>
- /// 上一个状态
- /// </summary>
- private MapBaseState mPreviousState = null;
- #region(行为状态)
- private MapBaseState mLoading = null;
- private MapBaseState mIdle = null;
- private MapBaseState mReady = null;
- private MapBaseState mArrival = null;
- private MapBaseState mRotate = null;
- private MapBaseState mMove = null;
- private MapBaseState mDrag = null;
- private MapBaseState mOver = null;
- private MapBaseState mBoss = null;
- private MapBaseState mBeHit = null;
- private MapBaseState mPVP = null;
- /// <summary>
- /// 打断当前状态
- /// </summary>
- public void BreakCurrentState()
- {
- this.ChangeState(EMapState.Idle, null);
- }
- /// <summary>
- /// 获取上一次状态
- /// </summary>
- /// <returns>状态对象</returns>
- public MapBaseState GetPreviousState()
- {
- return this.mPreviousState;
- }
- #endregion
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="param">所有者</param>
- public void Initialize(FightingMap param)
- {
- this.mOwner = param;
- this.mLoading = new MapLoading(this.mOwner);
- this.mIdle = new MapIdle(this.mOwner);
- this.mReady = new MapReady(this.mOwner);
- this.mBoss = new MapBoss(this.mOwner);
- this.mArrival = new MapArrival(this.mOwner);
- this.mRotate = new MapRotate(this.mOwner);
- this.mMove = new MapMove(this.mOwner);
- this.mDrag = new MapDrag(this.mOwner);
- this.mOver = new MapOver(this.mOwner);
- this.mBeHit = new MapBeHit(this.mOwner);
- this.mPVP = new MapPVP(this.mOwner);
- this.SetCurrentState(this.mReady, null);
- }
- /// <summary>
- /// 设置当前状态
- /// </summary>
- /// <param name="current">状态</param>
- /// <param name="param">参数</param>
- public void SetCurrentState(MapBaseState current, object param)
- {
- this.mCurrentState = current;
- this.mCurrentState.OnEnter(param);
- }
- /// <summary>
- /// 获取当前行为状态
- /// </summary>
- /// <returns>状态对象</returns>
- public MapBaseState GetCurrentState()
- {
- return this.mCurrentState;
- }
- /// <summary>
- /// 状态周期调度
- /// </summary>
- /// <param name="now">当前逻辑时间</param>
- public void OnUpdateState()
- {
- if (null != this.mCurrentState)
- {
- this.mCurrentState.OnUpdate();
- }
- }
- /// <summary>
- /// 切换到指定状态
- /// </summary>
- /// <param name="newState">新的状态</param>
- /// <param name="param">状态初始化参数</param>
- public void ChangeState(EMapState newState, object param)
- {
- if (this.mOwner.PlatAnimatorName == "0LaYuan")
- {
- return;
- }
- MapBaseState st = null;
- switch (newState)
- {
- case EMapState.Loading:
- st = this.mLoading;
- break;
- case EMapState.Idle:
- st = this.mIdle;
- break;
- case EMapState.Arrival:
- st = this.mArrival;
- break;
- case EMapState.Rotate:
- st = this.mRotate;
- break;
- case EMapState.Move:
- st = this.mMove;
- break;
- case EMapState.Over:
- st = this.mOver;
- break;
- case EMapState.Drag:
- st = this.mDrag;
- break;
- case EMapState.Ready:
- st = this.mReady;
- break;
- case EMapState.Boss:
- st = this.mBoss;
- break;
- case EMapState.BeHit:
- st = this.mBeHit;
- break;
- default:
- st = null;
- break;
- }
- if (null == st)
- {
- return;
- }
- this.mCurrentState.OnLeave();
- this.mPreviousState = this.mCurrentState;
- this.mCurrentState = st;
- this.mCurrentState.OnEnter(param);
- }
- }
- }
|