blob: 3954c6ca9f6ee893bff0acd0eccb3cd8a2a6b837 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
using System;
using UnityEngine;
using XUtliPoolLib;
namespace XMainClient
{
internal sealed class XJumpComponent : XActionStateComponent<XJumpEventArgs>
{
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<XCommon>.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<XCommon>.singleton.IsGreater(this._jumptime, this._jumpforce / -this._gravity);
if (flag)
{
this._jumpState = false;
this.SwithToFall();
}
vector.y += num;
Vector3 vector2 = XSingleton<XCommon>.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<XFallEventArgs>.GetEvent();
@event.HVelocity = this._hvelocity;
@event.Gravity = this._gravity;
@event.Firer = this._host;
XSingleton<XEventMgr>.singleton.FireEvent(@event);
base.Finish();
}
private bool CollisionOnTop()
{
return false;
}
}
}
|