-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerControl.cs
More file actions
58 lines (48 loc) · 1.53 KB
/
PlayerControl.cs
File metadata and controls
58 lines (48 loc) · 1.53 KB
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
using UnityEngine;
public class PlayerControl : MonoBehaviour, IMITPlayerInputDriver
{
[SerializeField] private MessageInterchange messageInterchange;
private const float sqrMagAttackInputThreshold = 0.75f * 0.75f;
public Vector2 InputDirMove { get; private set; }
public Vector3 WorldDirMove { get; private set; }
public Vector2 InputDirAttack { get; private set; }
public float SqrMagInputDirAttack { get => InputDirAttack.sqrMagnitude; }
public Vector3 WorldDirAttack { get; private set; }
public bool ButtonRoll { get; private set; }
public bool ButtonTake { get; private set; }
public bool ButtonDrop { get; private set; }
void OnEnable()
{
messageInterchange.Register(this);
}
void OnDisable()
{
messageInterchange.Deregister(this);
}
void IMITPlayerInputDriver.OnMove(Vector2 inputDir)
{
InputDirMove = inputDir;
WorldDirMove = InputDirMove.ToWorldDir();
}
void IMITPlayerInputDriver.OnAttack(Vector2 inputDir)
{
if (inputDir.sqrMagnitude < sqrMagAttackInputThreshold)
{
inputDir = Vector2.zero;
}
InputDirAttack = inputDir;
WorldDirAttack = InputDirAttack.ToWorldDir();
}
void IMITPlayerInputDriver.OnRoll(bool isPressing)
{
ButtonRoll = isPressing;
}
void IMITPlayerInputDriver.OnTake(bool isPressing)
{
ButtonTake = isPressing;
}
void IMITPlayerInputDriver.OnDrop(bool isPressing)
{
ButtonDrop = isPressing;
}
}