using UnityEngine; using System.Collections; namespace YLBattle { /// /// /// public class FightingMapState { private FightingMap mOwner = null; /// /// 当前状态 /// private MapBaseState mCurrentState = null; /// /// 上一个状态 /// 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; /// /// 打断当前状态 /// public void BreakCurrentState() { this.ChangeState(EMapState.Idle, null); } /// /// 获取上一次状态 /// /// 状态对象 public MapBaseState GetPreviousState() { return this.mPreviousState; } #endregion /// /// 初始化 /// /// 所有者 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); } /// /// 设置当前状态 /// /// 状态 /// 参数 public void SetCurrentState(MapBaseState current, object param) { this.mCurrentState = current; this.mCurrentState.OnEnter(param); } /// /// 获取当前行为状态 /// /// 状态对象 public MapBaseState GetCurrentState() { return this.mCurrentState; } /// /// 状态周期调度 /// /// 当前逻辑时间 public void OnUpdateState() { if (null != this.mCurrentState) { this.mCurrentState.OnUpdate(); } } /// /// 切换到指定状态 /// /// 新的状态 /// 状态初始化参数 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); } } }