-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionState.cs
77 lines (71 loc) · 2.23 KB
/
ActionState.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "State/Actions/Generic Action")]
public class ActionState : State
{
[SerializeField]
protected ActionState exitState;
[Tooltip("Leave the state null to use the controlled object's default locomotion states. Empty will force Idle.")]
public SerializedDictionary<Locomotion, LocomotionState> allowedLocomotion = new SerializedDictionary<Locomotion, LocomotionState>();
public override void OnEnter(ControlledObject controlledObject)
{
if (allowedLocomotion.Count == 0)
{
controlledObject.stateMachine.SetLocomotionState(Locomotion.Idle);
}
else
{
if (allowedLocomotion.ContainsKey(controlledObject.stateMachine.CurrentLocomotion))
{
controlledObject.stateMachine.SetLocomotionState(controlledObject.stateMachine.CurrentLocomotion);
}
else
{
foreach (KeyValuePair<Locomotion, LocomotionState> keyValue in allowedLocomotion)
{
controlledObject.stateMachine.SetLocomotionState(keyValue.Key);
break;
}
}
}
if (!skipAnim)
{
controlledObject.CrossFadeInFixedTime(animationStateName, transitionTime, 0, transitionTimeOffset, transitionTimeNormalized);
controlledObject.MeshRoot.localPosition = controlledObject.MeshRootOffset;
}
}
public sealed override void HandleState(ControlledObject controlledObject)
{
Inturruptions(controlledObject);
if (controlledObject.stateMachine.actionFrame >= maxFrame)
{
if (looping)
{
controlledObject.stateMachine.actionFrame = 0;
}
else
{
Exit(controlledObject);
}
}
}
public override List<InputActions> ValidInputs(ControlledObject controlledObject)
{
List<InputActions> valid = new List<InputActions>();
foreach (InputInterruption interrupt in interruptableByInput)
{
if (controlledObject.stateMachine.actionFrame >= interrupt.frames.x
&& controlledObject.stateMachine.actionFrame <= interrupt.frames.y
&& controlledObject.controller.GetBuffer(interrupt.action) > 0)
{
valid.Add(interrupt.action);
}
}
return valid;
}
protected override void Exit(ControlledObject controlledObject)
{
controlledObject.stateMachine.SetActionState(exitState);
}
}