-
Notifications
You must be signed in to change notification settings - Fork 0
/
State.cs
74 lines (59 loc) · 2.23 KB
/
State.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
public abstract class State : ScriptableObject
{
[Header("Animation")]
public bool skipAnim = false;
public string animationStateName = "default";
public float transitionTime = 0.1f;
public float transitionTimeOffset;
public float transitionTimeNormalized;
[Header("State Data")]
public int maxFrame;
[SerializeField]
protected bool looping;
[SerializeField]
protected List<InputInterruption> interruptableByInput;
[System.Serializable]
public class InputInterruption
{
[HideInInspector]
public int dyanmicInt;
[HorizontalGroup("V2I"), HideLabel]
public InputActions action;
[HorizontalGroup("V2I"), HideLabel, MinMaxSlider(0, "@dyanmicInt")]
public Vector2Int frames;
}
private void OnValidate()
{
foreach (InputInterruption interrupt in interruptableByInput)
interrupt.dyanmicInt = maxFrame;
}
public abstract void OnEnter(ControlledObject controlledObject);
public virtual void OnLateUpdate(ControlledObject controlledObject) { }
public virtual void OnUpdate(ControlledObject controlledObject) { }
public virtual void OnFixedUpdate(ControlledObject controlledObject) { }
public virtual void OnExit(ControlledObject controlledObject) { }
public abstract void HandleState(ControlledObject controlledObject);
protected virtual void Inturruptions(ControlledObject controlledObject) { }
public abstract List<InputActions> ValidInputs(ControlledObject controlledObject);
protected abstract void Exit(ControlledObject controlledObject);
protected Vector3 GetInputVector(ControlledObject controlledObject)
{
Vector2 input = controlledObject.controller.GetInput<Vector2>(InputActions.Move);
Vector3 moveInputVector = new Vector3(input.x, 0f, input.y).normalized;
if (controlledObject.reorientToCamera)
{
moveInputVector = Reorient(Camera.main.transform.forward, moveInputVector);
}
return moveInputVector;
}
protected Vector3 Reorient(Vector3 newForward, Vector3 vector)
{
if (newForward == Vector3.zero) return vector;
Vector3 planarDirection = Vector3.ProjectOnPlane(newForward, Vector3.up);
return Quaternion.LookRotation(planarDirection, Vector3.up) * vector;
}
}