| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// An instantaneous action which dispatches an event as soon as the input is read |
| | 5 | | /// </summary> |
| | 6 | | [CreateAssetMenu(fileName = "InputAction_Trigger", menuName = "InputActions/Trigger")] |
| | 7 | | public class InputAction_Trigger : ScriptableObject |
| | 8 | | { |
| | 9 | | public delegate void Triggered(DCLAction_Trigger action); |
| | 10 | | public event Triggered OnTriggered; |
| | 11 | |
|
| | 12 | | [SerializeField] internal DCLAction_Trigger dclAction; |
| 0 | 13 | | public DCLAction_Trigger GetDCLAction() => dclAction; |
| | 14 | |
|
| | 15 | | [SerializeField] internal BooleanVariable blockTrigger; |
| 0 | 16 | | public BooleanVariable isTriggerBlocked { get => blockTrigger; set => blockTrigger = value; } |
| | 17 | |
|
| 60 | 18 | | private int triggeredInFrame = -1; |
| | 19 | |
|
| 3 | 20 | | public bool WasTriggeredThisFrame() { return triggeredInFrame == Time.frameCount; } |
| | 21 | |
|
| | 22 | | public void RaiseOnTriggered() |
| | 23 | | { |
| 5 | 24 | | triggeredInFrame = Time.frameCount; |
| 5 | 25 | | OnTriggered?.Invoke(dclAction); |
| 3 | 26 | | } |
| | 27 | |
|
| | 28 | | #region Editor |
| | 29 | |
|
| | 30 | | #if UNITY_EDITOR |
| | 31 | |
|
| | 32 | | [UnityEditor.CustomEditor(typeof(InputAction_Trigger), true)] |
| | 33 | | internal class InputAction_TriggerEditor : UnityEditor.Editor |
| | 34 | | { |
| | 35 | | public override void OnInspectorGUI() |
| | 36 | | { |
| 0 | 37 | | DrawDefaultInspector(); |
| 0 | 38 | | if (Application.isPlaying && GUILayout.Button("Raise OnChange")) |
| | 39 | | { |
| 0 | 40 | | ((InputAction_Trigger)target).RaiseOnTriggered(); |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | | } |
| | 44 | | #endif |
| | 45 | |
|
| | 46 | | #endregion |
| | 47 | |
|
| | 48 | | } |