| | 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 | | public void RaiseOnStarted() |
| | 21 | | { |
| 7 | 22 | | isOn = true; |
| 7 | 23 | | OnStarted?.Invoke(dclAction); |
| 3 | 24 | | } |
| | 25 | |
|
| | 26 | | public void RaiseOnFinished() |
| | 27 | | { |
| 36 | 28 | | isOn = false; |
| 36 | 29 | | OnFinished?.Invoke(dclAction); |
| 34 | 30 | | } |
| | 31 | |
|
| | 32 | | #region Editor |
| | 33 | |
|
| | 34 | | #if UNITY_EDITOR |
| | 35 | |
|
| | 36 | | [UnityEditor.CustomEditor(typeof(InputAction_Hold), true)] |
| | 37 | | internal class InputAction_HoldEditor : UnityEditor.Editor |
| | 38 | | { |
| | 39 | | public override void OnInspectorGUI() |
| | 40 | | { |
| 0 | 41 | | DrawDefaultInspector(); |
| 0 | 42 | | if (Application.isPlaying && GUILayout.Button("Raise OnStarted")) |
| | 43 | | { |
| 0 | 44 | | ((InputAction_Hold)target).RaiseOnStarted(); |
| | 45 | | } |
| 0 | 46 | | if (Application.isPlaying && GUILayout.Button("Raise OnFinished")) |
| | 47 | | { |
| 0 | 48 | | ((InputAction_Hold)target).RaiseOnFinished(); |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | | } |
| | 52 | | #endif |
| | 53 | |
|
| | 54 | | #endregion |
| | 55 | |
|
| | 56 | | } |