-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModifiersController.cs
94 lines (75 loc) · 2.57 KB
/
ModifiersController.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Cuboid (http://github.com/arjonagelhout/cuboid)
// Copyright (c) 2023 Arjo Nagelhout
//
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cuboid.Input;
namespace Cuboid
{
/// <summary>
/// The ModifiersController is responsible for
/// </summary>
public sealed class ModifiersController : MonoBehaviour
{
private static ModifiersController _instance;
public static ModifiersController Instance => _instance;
private InputController _inputController;
private Action<bool> _nonDominantHandPrimaryButtonChanged;
private Action<bool> _nonDominantHandSecondaryButtonChanged;
[NonSerialized] public Binding<bool> ShiftModifier = new(false);
[NonSerialized] public Binding<bool> OptionModifier = new(false);
private void Awake()
{
// Singleton implementation
if (_instance != null && _instance != this) { Destroy(this); } else { _instance = this; }
}
private void Start()
{
_inputController = InputController.Instance;
_nonDominantHandPrimaryButtonChanged = OnNonDominantHandPrimaryButtonChanged;
_nonDominantHandSecondaryButtonChanged = OnNonDominantHandSecondaryButtonChanged;
Register();
}
private void OnNonDominantHandPrimaryButtonChanged(bool pressed)
{
ShiftModifier.Value = pressed;
}
private void OnNonDominantHandSecondaryButtonChanged(bool pressed)
{
OptionModifier.Value = pressed;
}
#region Action registration
private void Register()
{
if (_inputController != null)
{
_inputController.NonDominantHandPrimaryButton.Register(_nonDominantHandPrimaryButtonChanged);
_inputController.NonDominantHandSecondaryButton.Register(_nonDominantHandSecondaryButtonChanged);
}
}
private void Unregister()
{
if (_inputController != null)
{
_inputController.NonDominantHandPrimaryButton.Unregister(_nonDominantHandPrimaryButtonChanged);
_inputController.NonDominantHandSecondaryButton.Unregister(_nonDominantHandSecondaryButtonChanged);
}
}
private void OnEnable()
{
Register();
}
private void OnDisable()
{
Unregister();
}
private void OnDestroy()
{
Unregister();
}
#endregion
}
}