| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | /// <summary> |
| | 5 | | /// An on/off action that triggers Start when the input is read and Finished when the input has gone |
| | 6 | | /// </summary> |
| | 7 | | [CreateAssetMenu(fileName = "InputAction_Hold", menuName = "InputActions/Hold")] |
| | 8 | | public class InputAction_Hold : ScriptableObject |
| | 9 | | { |
| | 10 | | public delegate void Started(DCLAction_Hold action); |
| | 11 | | public delegate void Finished(DCLAction_Hold action); |
| | 12 | | public event Started OnStarted; |
| | 13 | | public event Finished OnFinished; |
| | 14 | |
|
| | 15 | | [SerializeField] internal DCLAction_Hold dclAction; |
| 0 | 16 | | public DCLAction_Hold GetDCLAction() => dclAction; |
| | 17 | |
|
| 0 | 18 | | public bool isOn { get; private set; } |
| | 19 | |
|
| | 20 | | [SerializeField] internal BooleanVariable holdBlocked; |
| 0 | 21 | | public BooleanVariable isHoldBlocked { get => holdBlocked; set => holdBlocked = value; } |
| | 22 | |
|
| | 23 | | public void RaiseOnStarted() |
| | 24 | | { |
| 5 | 25 | | isOn = true; |
| 5 | 26 | | OnStarted?.Invoke(dclAction); |
| 3 | 27 | | } |
| | 28 | |
|
| | 29 | | public void RaiseOnFinished() |
| | 30 | | { |
| 35 | 31 | | isOn = false; |
| 35 | 32 | | OnFinished?.Invoke(dclAction); |
| 34 | 33 | | } |
| | 34 | |
|
| | 35 | | #region Editor |
| | 36 | |
|
| | 37 | | #if UNITY_EDITOR |
| | 38 | |
|
| | 39 | | [UnityEditor.CustomEditor(typeof(InputAction_Hold), true)] |
| | 40 | | internal class InputAction_HoldEditor : UnityEditor.Editor |
| | 41 | | { |
| | 42 | | public override void OnInspectorGUI() |
| | 43 | | { |
| 0 | 44 | | DrawDefaultInspector(); |
| 0 | 45 | | if (Application.isPlaying && GUILayout.Button("Raise OnStarted")) |
| | 46 | | { |
| 0 | 47 | | ((InputAction_Hold)target).RaiseOnStarted(); |
| | 48 | | } |
| 0 | 49 | | if (Application.isPlaying && GUILayout.Button("Raise OnFinished")) |
| | 50 | | { |
| 0 | 51 | | ((InputAction_Hold)target).RaiseOnFinished(); |
| | 52 | | } |
| 0 | 53 | | } |
| | 54 | | } |
| | 55 | | #endif |
| | 56 | |
|
| | 57 | | #endregion |
| | 58 | |
|
| | 59 | | } |