A game about forced loneliness, made by TACStudios
at master 81 lines 2.6 kB view raw
1#if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI 2using UnityEngine.EventSystems; 3using UnityEngine.InputSystem.Layouts; 4 5#if UNITY_EDITOR 6using UnityEngine.InputSystem.Editor; 7#endif 8 9////TODO: custom icon for OnScreenButton component 10 11namespace UnityEngine.InputSystem.OnScreen 12{ 13 /// <summary> 14 /// A button that is visually represented on-screen and triggered by touch or other pointer 15 /// input. 16 /// </summary> 17 [AddComponentMenu("Input/On-Screen Button")] 18 [HelpURL(InputSystem.kDocUrl + "/manual/OnScreen.html#on-screen-buttons")] 19 public class OnScreenButton : OnScreenControl, IPointerDownHandler, IPointerUpHandler 20 { 21 public void OnPointerUp(PointerEventData eventData) 22 { 23 SendValueToControl(0.0f); 24 } 25 26 public void OnPointerDown(PointerEventData eventData) 27 { 28 SendValueToControl(1.0f); 29 } 30 31 ////TODO: pressure support 32 /* 33 /// <summary> 34 /// If true, the button's value is driven from the pressure value of touch or pen input. 35 /// </summary> 36 /// <remarks> 37 /// This essentially allows having trigger-like buttons as on-screen controls. 38 /// </remarks> 39 [SerializeField] private bool m_UsePressure; 40 */ 41 42 [InputControl(layout = "Button")] 43 [SerializeField] 44 private string m_ControlPath; 45 46 protected override string controlPathInternal 47 { 48 get => m_ControlPath; 49 set => m_ControlPath = value; 50 } 51 52#if UNITY_EDITOR 53 [UnityEditor.CustomEditor(typeof(OnScreenButton))] 54 internal class OnScreenButtonEditor : UnityEditor.Editor 55 { 56 private UnityEditor.SerializedProperty m_ControlPathInternal; 57 58 public void OnEnable() 59 { 60 m_ControlPathInternal = serializedObject.FindProperty(nameof(OnScreenButton.m_ControlPath)); 61 } 62 63 public void OnDisable() 64 { 65 new InputComponentEditorAnalytic(InputSystemComponent.OnScreenButton).Send(); 66 } 67 68 public override void OnInspectorGUI() 69 { 70 // Current implementation has UGUI dependencies (ISXB-915, ISXB-916) 71 UGUIOnScreenControlEditorUtils.ShowWarningIfNotPartOfCanvasHierarchy((OnScreenButton)target); 72 73 UnityEditor.EditorGUILayout.PropertyField(m_ControlPathInternal); 74 75 serializedObject.ApplyModifiedProperties(); 76 } 77 } 78#endif 79 } 80} 81#endif