From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../ActionStates/XActionStateComponent.cs | 253 +++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs b/Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs new file mode 100644 index 00000000..89a214fe --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Components/ActionStates/XActionStateComponent.cs @@ -0,0 +1,253 @@ +using System; +using XUtliPoolLib; + +namespace XMainClient +{ + internal abstract class XActionStateComponent : XComponent, IXStateTransform, IXInterface where T : XActionArgs + { + public virtual bool SyncPredicted + { + get + { + return !XSingleton.singleton.SyncMode; + } + } + + public virtual float Speed + { + get + { + throw new NotImplementedException(); + } + } + + public XStateDefine SelfState + { + get + { + return this._selfState; + } + } + + public bool IsStopped + { + get + { + return this._bStopped; + } + } + + public bool IsFinished + { + get + { + return this._bFinished || this._bStopped; + } + } + + public virtual bool ShouldBePresent + { + get + { + return true; + } + } + + public long Token + { + get + { + return this._stateToken; + } + } + + protected long SelfToken + { + get + { + return this._selfToken; + } + } + + public virtual int CollisionLayer + { + get + { + return this._entity.DefaultLayer; + } + } + + public abstract string PresentCommand { get; } + + public abstract string PresentName { get; } + + public bool Deprecated { get; set; } + + public abstract bool IsUsingCurve { get; } + + protected XStateDefine _selfState = XStateDefine.XState_Idle; + + private bool _bFinished = true; + + private bool _bStopped = false; + + private long _stateToken = 0L; + + private long _selfToken = 0L; + + public override void OnDetachFromHost() + { + bool flag = this.SelfState != XStateDefine.XState_Idle && this._entity.Machine.Current == this.SelfState; + if (flag) + { + this._entity.Machine.ForceToDefaultState(true); + } + base.OnDetachFromHost(); + } + + public bool IsPermitted(XStateDefine state) + { + bool flag = this.IsFinished && this._selfState != XStateDefine.XState_Move; + return flag || this.InnerPermitted(state); + } + + public virtual void OnRejected(XStateDefine current) + { + } + + public void StateUpdate(float deltaTime) + { + bool flag = this.SelfState != this._entity.Machine.Default && this.IsFinished; + if (flag) + { + this.Finish(); + } + else + { + this.ActionUpdate(deltaTime); + } + } + + private void Start() + { + this.Begin(); + } + + public void Stop(XStateDefine next) + { + bool flag = !this._bStopped; + if (flag) + { + this._bStopped = true; + this.Finish(); + this.Cancel(next); + } + } + + public virtual void OnGetPermission() + { + this._bStopped = false; + this._bFinished = false; + } + + public virtual string TriggerAnim(string pre) + { + string presentCommand = this.PresentCommand; + bool flag = pre != presentCommand; + if (flag) + { + bool flag2 = this._entity.Ator != null; + if (flag2) + { + this._entity.Ator.SetTrigger(presentCommand); + } + } + return presentCommand; + } + + protected void Finish() + { + bool flag = !this._bFinished; + if (flag) + { + this._bFinished = true; + this.Cease(); + } + } + + protected virtual void Cease() + { + } + + protected virtual void Begin() + { + } + + protected virtual void Cancel(XStateDefine next) + { + } + + protected virtual void OnMount(XMount mount) + { + } + + protected virtual bool SelfCheck(T args) + { + return true; + } + + protected bool GetPermission(T e) + { + bool flag = (this._entity.Skill == null || this._entity.Skill.CanPerformAction(this.SelfState, e)) && (this._entity.Machine == null || this._entity.Machine.TryTransferToState(this)); + bool flag2 = flag; + if (flag2) + { + this._stateToken = e.Token; + this._selfToken = XSingleton.singleton.UniqueToken; + } + return flag; + } + + protected virtual bool InnerPermitted(XStateDefine state) + { + return this._entity.Machine.StatePermitted(this._selfState, state); + } + + protected bool OnActionEvent(XEventArgs e) + { + T e2 = e as T; + XStateDefine last = this._entity.Machine.Current; + bool permission = this.GetPermission(e2); + if (permission) + { + this.OnGetEvent(e2, last); + this.Start(); + } + return true; + } + + protected bool OnMountEvent(XEventArgs e) + { + bool flag = e is XOnMountedEventArgs; + if (flag) + { + this.OnMount(this._entity.Mount); + } + else + { + bool flag2 = e is XOnUnMountedEventArgs; + if (flag2) + { + this.OnMount(null); + } + } + return true; + } + + protected abstract bool OnGetEvent(T e, XStateDefine last); + + protected virtual void ActionUpdate(float deltaTime) + { + } + } +} -- cgit v1.1-26-g67d0