This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
forked from qoopen0815/OcsVehicle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BackhoeController.cs
47 lines (40 loc) · 1.85 KB
/
BackhoeController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ocs.Vehicle.Controller
{
public class BackhoeController : MonoBehaviour
{
[SerializeField] private Backhoe _vehicle;
private Ocs.Input.VehicleInput _input;
private void Awake()
{
this._input = new Ocs.Input.VehicleInput();
}
private void OnEnable() => this._input.Enable();
private void OnDestroy() => this._input.Dispose();
private void OnDisable()
{
this._input.Disable();
}
private void Start()
{
// Callback
this._input.Crawler.LeftReverse.started += context => this._vehicle.LeftReverse = !this._vehicle.LeftReverse;
this._input.Crawler.RightReverse.started += context => this._vehicle.RightReverse = !this._vehicle.RightReverse;
this._input.Equipment.Light.started += context => this._vehicle.SwitchLight();
this._input.Equipment.Hone.started += context => this._vehicle.PlayHone();
this._input.Equipment.LeftWinker.started += context => this._vehicle.SwitchLeftWinker();
this._input.Equipment.RightWinker.started += context => this._vehicle.SwitchRightWinker();
}
void Update()
{
this._vehicle.LeftCrawlerInput = this._input.Crawler.LeftForward.ReadValue<float>();
this._vehicle.RightCrawlerInput = this._input.Crawler.RightForward.ReadValue<float>();
this._vehicle.BaseInput = this._input.Backhoe.Lever0.ReadValue<Vector2>()[0];
this._vehicle.BoomInput = -this._input.Backhoe.Lever1.ReadValue<Vector2>()[1];
this._vehicle.ArmInput = this._input.Backhoe.Lever0.ReadValue<Vector2>()[1];
this._vehicle.EndInput = this._input.Backhoe.Lever1.ReadValue<Vector2>()[0];
}
}
}