-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cs
More file actions
92 lines (80 loc) · 2.73 KB
/
Copy pathController.cs
File metadata and controls
92 lines (80 loc) · 2.73 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
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
using UnityEngine;
public class Controller : MonoBehaviour
{
[SerializeField] private Iscp_ControlPublisher publisher;
// Inputs
private ControllerInputs inputs;
public float Steering;
public float Accel;
public float Footbrake;
public float Handbrake;
public TMPro.TMP_Text InputText;
public float InputTextRefreshRate = 10;
private float inputTextRefreshTimeElapsed = 0f;
private float? inputTextTargetRate;
private float inputTextTargetTime = 0f;
// Called when the script is first activated.
private void Awake()
{
// Prepare input action scripts generated by inputactions.
this.inputs = new ControllerInputs();
}
// Start is called before the first frame update
void Start() { }
// Update is called once per frame
void Update()
{
// Read Inputs
{
var controller = this.inputs.Controller;
Steering = controller.Steering.ReadValue<float>();
Accel= controller.Accel.ReadValue<float>();
Footbrake = controller.Footbrake.ReadValue<float>();
Handbrake = controller.Handbrake.ReadValue<float>();
}
// Publish Inputs
if (publisher != null)
{
publisher.Steering = Steering;
publisher.Accel = Accel;
publisher.Footbrake = Footbrake;
publisher.Handbrake = Handbrake;
}
// Output Inputs
if (InputText != null)
{
if (this.inputTextTargetRate != this.InputTextRefreshRate)
{
this.inputTextTargetRate = this.InputTextRefreshRate;
this.inputTextTargetTime = 1f / this.inputTextTargetRate.Value;
}
this.inputTextRefreshTimeElapsed += Time.deltaTime;
if (this.inputTextRefreshTimeElapsed >= this.inputTextTargetTime)
{
this.inputTextRefreshTimeElapsed -= this.inputTextTargetTime;
string text = "";
text += "¡ Controller Inputs";
text += "\nSteering: " + this.Steering;
text += "\nAccel: " + this.Accel;
text += "\nFootbrake: " + this.Footbrake;
text += "\nHandbrake: " + this.Handbrake;
text += "\n";
text += "¡ Key Binds";
text += "\nSteering: A or D";
text += "\nAccel: W";
text += "\nFootbrake: Space";
text += "\nHandbrake: Shift";
InputText.text = text;
}
}
}
private void OnEnable()
{
// Input actions must be enabled.
this.inputs.Enable();
}
private void OnDisable()
{
this.inputs.Disable();
}
}