From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Components/ActionStates/XJumpComponent.cs | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Components/ActionStates/XJumpComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/Components/ActionStates/XJumpComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/Components/ActionStates/XJumpComponent.cs b/Client/Assets/Scripts/XMainClient/Components/ActionStates/XJumpComponent.cs new file mode 100644 index 00000000..3954c6ca --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Components/ActionStates/XJumpComponent.cs @@ -0,0 +1,130 @@ +using System; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal sealed class XJumpComponent : XActionStateComponent + { + public override uint ID + { + get + { + return XJumpComponent.uuID; + } + } + + public override bool IsUsingCurve + { + get + { + return false; + } + } + + public override string PresentCommand + { + get + { + return "ToJump"; + } + } + + public override string PresentName + { + get + { + return "Jump"; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("Basic_Jump"); + + private bool _jumpState = false; + + private float _hvelocity = 0f; + + private float _jumpforce = 4f; + + private float _gravity = -9.8f; + + private float _jumptime = 0f; + + protected override void EventSubscribe() + { + base.RegisterEvent(XEventDefine.XEvent_Jump, new XComponent.XEventHandler(base.OnActionEvent)); + } + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + this._selfState = XStateDefine.XState_Jump; + } + + protected override void Cancel(XStateDefine next) + { + this._jumpState = false; + this._jumptime = 0f; + } + + protected override bool OnGetEvent(XJumpEventArgs e, XStateDefine last) + { + this._hvelocity = e.Hvelocity; + this._jumpforce = e.Vvelocity; + this._gravity = e.Gravity; + return true; + } + + protected override void Begin() + { + this._jumpState = true; + this._jumptime = 0f; + } + + protected override void ActionUpdate(float deltaTime) + { + Vector3 vector = Vector3.zero; + this._jumpState = !this.CollisionOnTop(); + bool jumpState = this._jumpState; + if (jumpState) + { + this._jumptime += deltaTime; + float num = this._gravity * this._jumptime * this._jumptime / 2f; + num += this._jumpforce * this._jumptime; + bool flag = XSingleton.singleton.IsGreater(this._jumptime, this._jumpforce / -this._gravity); + if (flag) + { + this._jumpState = false; + this.SwithToFall(); + } + vector.y += num; + Vector3 vector2 = XSingleton.singleton.Horizontal(this._entity.EngineObject.Forward); + vector += deltaTime * this._hvelocity * vector2; + this._entity.ApplyMove(vector); + } + else + { + this.SwithToFall(); + } + } + + public override void OnRejected(XStateDefine current) + { + } + + private void SwithToFall() + { + XFallEventArgs @event = XEventPool.GetEvent(); + @event.HVelocity = this._hvelocity; + @event.Gravity = this._gravity; + @event.Firer = this._host; + XSingleton.singleton.FireEvent(@event); + base.Finish(); + } + + private bool CollisionOnTop() + { + return false; + } + } +} -- cgit v1.1-26-g67d0