using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif namespace Lightbug.CharacterControllerPro.Implementation { [System.Serializable] public struct Vector2Action { /// /// The action current value. /// public Vector2 value; /// /// Resets the action /// public void Reset() { value = Vector2.zero; } /// /// Returns true if the value is not equal to zero (e.g. When pressing a D-pad) /// public bool Detected { get { return value != Vector2.zero; } } /// /// Returns true if the x component is positive. /// public bool Right { get { return value.x > 0; } } /// /// Returns true if the x component is negative. /// public bool Left { get { return value.x < 0; } } /// /// Returns true if the y component is positive. /// public bool Up { get { return value.y > 0; } } /// /// Returns true if the y component is negative. /// public bool Down { get { return value.y < 0; } } } // ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── // EDITOR ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── // ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── #if UNITY_EDITOR [CustomPropertyDrawer(typeof(Vector2Action))] public class Vector2ActionEditor : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty value = property.FindPropertyRelative("value"); Rect fieldRect = position; fieldRect.height = EditorGUIUtility.singleLineHeight; fieldRect.width = 100; EditorGUI.LabelField(fieldRect, label); fieldRect.x += 110; EditorGUI.PropertyField(fieldRect, value, GUIContent.none); EditorGUI.EndProperty(); } } #endif }