2025-06-04 22:49:37 +08:00
/ *
* @author Valentin Simonov / http : //va.lent.in/
* /
using TouchScript.Gestures ;
using UnityEditor ;
using UnityEngine ;
namespace TouchScript.Editor.Gestures
{
[CustomEditor(typeof(TapGesture), true)]
internal sealed class TapGestureEditor : GestureEditor
{
2025-08-24 18:59:40 +08:00
public static readonly GUIContent TEXT_TIME_LIMIT = new GUIContent ( "Limit Time (sec)" , "Gesture fails if in <value> seconds user didn't do the required number of taps." ) ;
public static readonly GUIContent TEXT_DISTANCE_LIMIT = new GUIContent ( "Limit Movement (cm)" , "Gesture fails if taps are made more than <value> cm away from the first pointer position." ) ;
public static readonly GUIContent TEXT_NUMBER_OF_TAPS_REQUIRED = new GUIContent ( "Number of Taps Required" , "Number of taps required for this gesture to be recognized." ) ;
public static readonly GUIContent TEXT_COMBINE_POINTERS = new GUIContent ( "Combine Pointers" , "When several fingers are used to perform a tap, pointers released not earlier than <CombineInterval> seconds ago are used to calculate gesture's final screen position." ) ;
public static readonly GUIContent TEXT_COMBINE_TOUCH_POINTERS = new GUIContent ( "Combine Interval (sec)" , TEXT_COMBINE_POINTERS . tooltip ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
public static readonly GUIContent TEXT_HELP = new GUIContent ( "This component recognizes a gesture when this GameObject is tapped." ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
private SerializedProperty numberOfTapsRequired , distanceLimit , timeLimit , combinePointers , combinePointersInterval ;
private SerializedProperty OnTap ;
2025-06-04 22:49:37 +08:00
protected override void OnEnable ( )
{
numberOfTapsRequired = serializedObject . FindProperty ( "numberOfTapsRequired" ) ;
timeLimit = serializedObject . FindProperty ( "timeLimit" ) ;
distanceLimit = serializedObject . FindProperty ( "distanceLimit" ) ;
2025-08-24 18:59:40 +08:00
combinePointers = serializedObject . FindProperty ( "combinePointers" ) ;
combinePointersInterval = serializedObject . FindProperty ( "combinePointersInterval" ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
OnTap = serializedObject . FindProperty ( "OnTap" ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
base . OnEnable ( ) ;
2025-06-04 22:49:37 +08:00
}
protected override void drawBasic ( )
{
2025-08-24 18:59:40 +08:00
EditorGUIUtility . labelWidth = 180 ;
EditorGUILayout . IntPopup ( numberOfTapsRequired , new [ ] { new GUIContent ( "One" ) , new GUIContent ( "Two" ) , new GUIContent ( "Three" ) } , new [ ] { 1 , 2 , 3 } , TEXT_NUMBER_OF_TAPS_REQUIRED , GUILayout . ExpandWidth ( true ) ) ;
}
2025-06-04 22:49:37 +08:00
protected override GUIContent getHelpText ( )
{
return TEXT_HELP ;
}
2025-08-24 18:59:40 +08:00
protected override void drawGeneral ( )
{
EditorGUIUtility . labelWidth = 180 ;
EditorGUILayout . IntPopup ( numberOfTapsRequired , new [ ] { new GUIContent ( "One" ) , new GUIContent ( "Two" ) , new GUIContent ( "Three" ) } , new [ ] { 1 , 2 , 3 } , TEXT_NUMBER_OF_TAPS_REQUIRED , GUILayout . ExpandWidth ( true ) ) ;
EditorGUILayout . PropertyField ( combinePointers , TEXT_COMBINE_POINTERS ) ;
if ( combinePointers . boolValue )
{
EditorGUIUtility . labelWidth = 160 ;
EditorGUILayout . BeginHorizontal ( ) ;
GUILayout . Label ( GUIContent . none , GUILayout . Width ( 10 ) ) ;
EditorGUILayout . BeginVertical ( GUILayout . ExpandWidth ( true ) ) ;
EditorGUILayout . PropertyField ( combinePointersInterval , TEXT_COMBINE_TOUCH_POINTERS ) ;
EditorGUILayout . EndVertical ( ) ;
EditorGUILayout . EndHorizontal ( ) ;
}
base . drawGeneral ( ) ;
}
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
protected override void drawLimits ( )
2025-06-04 22:49:37 +08:00
{
EditorGUILayout . PropertyField ( timeLimit , TEXT_TIME_LIMIT ) ;
EditorGUILayout . PropertyField ( distanceLimit , TEXT_DISTANCE_LIMIT ) ;
2025-08-24 18:59:40 +08:00
base . drawLimits ( ) ;
2025-06-04 22:49:37 +08:00
}
2025-08-24 18:59:40 +08:00
protected override void drawUnityEvents ( )
{
EditorGUILayout . PropertyField ( OnTap ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
base . drawUnityEvents ( ) ;
}
2025-06-04 22:49:37 +08:00
}
2025-08-24 18:59:40 +08:00
}