| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | /// <summary> |
| | 5 | | /// An analogical action that raises events when the value is changed. The most common use-case is implementing axis |
| | 6 | | /// </summary> |
| | 7 | | [CreateAssetMenu(fileName = "InputAction_Measurable", menuName = "InputActions/Measurable")] |
| | 8 | | public class InputAction_Measurable : ScriptableObject |
| | 9 | | { |
| | 10 | | public delegate void ValueChanged(DCLAction_Measurable action, float value); |
| | 11 | | public event ValueChanged OnValueChanged; |
| | 12 | |
|
| | 13 | | [SerializeField] internal DCLAction_Measurable dclAction; |
| 0 | 14 | | public DCLAction_Measurable GetDCLAction() => dclAction; |
| | 15 | |
|
| | 16 | | [SerializeField] private float currentValue = 0; |
| 0 | 17 | | public float GetValue() => currentValue; |
| | 18 | |
|
| | 19 | | internal void RaiseOnValueChanged(float value) |
| | 20 | | { |
| 27820 | 21 | | if (Math.Abs(currentValue - value) > Mathf.Epsilon) |
| | 22 | | { |
| 5 | 23 | | currentValue = value; |
| 5 | 24 | | OnValueChanged?.Invoke(dclAction, currentValue); |
| | 25 | | } |
| 27816 | 26 | | } |
| | 27 | |
|
| | 28 | | #region Editor |
| | 29 | |
|
| | 30 | | #if UNITY_EDITOR |
| | 31 | |
|
| | 32 | | [UnityEditor.CustomEditor(typeof(InputAction_Measurable), true)] |
| | 33 | | internal class InputAction_MeasurableEditor : UnityEditor.Editor |
| | 34 | | { |
| | 35 | | private float changeValue = 0; |
| | 36 | | public override void OnInspectorGUI() |
| | 37 | | { |
| 0 | 38 | | DrawDefaultInspector(); |
| 0 | 39 | | changeValue = GUILayout.HorizontalSlider(changeValue, 0, 1); |
| 0 | 40 | | if (Application.isPlaying && GUILayout.Button("Raise OnChange")) |
| | 41 | | { |
| 0 | 42 | | ((InputAction_Measurable)target).RaiseOnValueChanged(changeValue); |
| | 43 | | } |
| 0 | 44 | | } |
| | 45 | | } |
| | 46 | | #endif |
| | 47 | |
|
| | 48 | | #endregion |
| | 49 | |
|
| | 50 | | } |