2025-06-04 22:49:37 +08:00
/ *
* @author Valentin Simonov / http : //va.lent.in/
* /
using TouchScript.InputSources ;
using UnityEditor ;
using UnityEngine ;
using TouchScript.Editor.EditorUI ;
namespace TouchScript.Editor.InputSources
{
2025-08-24 18:59:40 +08:00
[CustomEditor(typeof(StandardInput), true)]
2025-06-04 22:49:37 +08:00
internal sealed class StandardInputEditor : InputSourceEditor
{
2025-08-24 18:59:40 +08:00
public static readonly GUIContent TEXT_GENERAL_HEADER = new GUIContent ( "General" , "General settings." ) ;
public static readonly GUIContent TEXT_WINDOWS_HEADER = new GUIContent ( "Windows" , "Windows specific settings." ) ;
2025-06-04 22:49:37 +08:00
public static readonly GUIContent TEXT_WEBGL_HEADER = new GUIContent ( "WebGL" , "WebGL specific settings." ) ;
public static readonly GUIContent TEXT_EMULATE_MOUSE = new GUIContent ( "Emulate Second Mouse Pointer" , "If selected, you can press ALT to make a stationary mouse pointer. This is used to simulate multi-touch." ) ;
2025-08-24 18:59:40 +08:00
public static readonly GUIContent TEXT_WINDOWS_API = new GUIContent ( "Select which touch API to use:\n - Windows 8 — new WM_POINTER API,\n - Windows 7 — old WM_TOUCH API,\n - Unity — Unity's WM_TOUCH implementation,\n - None — no touch." ) ;
public static readonly GUIContent TEXT_WINDOWS8 = new GUIContent ( "Windows 8+ API" ) ;
public static readonly GUIContent TEXT_WINDOWS7 = new GUIContent ( "Windows 7 API" ) ;
public static readonly GUIContent TEXT_WINDOWS8_MOUSE = new GUIContent ( "Enable Mouse on Windows 8+" ) ;
public static readonly GUIContent TEXT_WINDOWS7_MOUSE = new GUIContent ( "Enable Mouse on Windows 7" ) ;
public static readonly GUIContent TEXT_UWP_MOUSE = new GUIContent ( "Enable Mouse on UWP" ) ;
2025-06-04 22:49:37 +08:00
public static readonly GUIContent TEXT_HELP = new GUIContent ( "This component gathers input data from various devices like touch, mouse and pen on all platforms." ) ;
private SerializedProperty basicEditor ;
2025-08-24 18:59:40 +08:00
2025-06-04 22:49:37 +08:00
private SerializedProperty windows8Touch , windows7Touch , webGLTouch , windows8Mouse ,
2025-08-24 18:59:40 +08:00
windows7Mouse , universalWindowsMouse , emulateSecondMousePointer ;
private SerializedProperty generalProps , windowsProps , webglProps ;
2025-06-04 22:49:37 +08:00
private StandardInput instance ;
protected override void OnEnable ( )
{
base . OnEnable ( ) ;
instance = target as StandardInput ;
basicEditor = serializedObject . FindProperty ( "basicEditor" ) ;
windows8Touch = serializedObject . FindProperty ( "windows8API" ) ;
windows7Touch = serializedObject . FindProperty ( "windows7API" ) ;
webGLTouch = serializedObject . FindProperty ( "webGLTouch" ) ;
windows8Mouse = serializedObject . FindProperty ( "windows8Mouse" ) ;
windows7Mouse = serializedObject . FindProperty ( "windows7Mouse" ) ;
universalWindowsMouse = serializedObject . FindProperty ( "universalWindowsMouse" ) ;
emulateSecondMousePointer = serializedObject . FindProperty ( "emulateSecondMousePointer" ) ;
2025-08-24 18:59:40 +08:00
generalProps = serializedObject . FindProperty ( "generalProps" ) ;
windowsProps = serializedObject . FindProperty ( "windowsProps" ) ;
2025-06-04 22:49:37 +08:00
webglProps = serializedObject . FindProperty ( "webglProps" ) ;
}
public override void OnInspectorGUI ( )
{
#if UNITY_5_6_OR_NEWER
2025-08-24 18:59:40 +08:00
serializedObject . UpdateIfRequiredOrScript ( ) ;
2025-06-04 22:49:37 +08:00
# else
serializedObject . UpdateIfDirtyOrScript ( ) ;
# endif
2025-08-24 18:59:40 +08:00
GUILayout . Space ( 5 ) ;
2025-06-04 22:49:37 +08:00
2025-08-24 18:59:40 +08:00
if ( basicEditor . boolValue )
{
2025-06-04 22:49:37 +08:00
EditorGUI . BeginChangeCheck ( ) ;
2025-08-24 18:59:40 +08:00
EditorGUILayout . PropertyField ( emulateSecondMousePointer , TEXT_EMULATE_MOUSE ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
instance . EmulateSecondMousePointer = emulateSecondMousePointer . boolValue ;
}
if ( GUIElements . BasicHelpBox ( TEXT_HELP ) )
{
basicEditor . boolValue = false ;
Repaint ( ) ;
}
}
else
{
drawGeneral ( ) ;
drawWindows ( ) ;
drawWebGL ( ) ;
}
2025-06-04 22:49:37 +08:00
serializedObject . ApplyModifiedProperties ( ) ;
base . OnInspectorGUI ( ) ;
}
private void drawGeneral ( )
{
2025-08-24 18:59:40 +08:00
var display = GUIElements . Header ( TEXT_GENERAL_HEADER , generalProps ) ;
if ( display )
{
EditorGUI . indentLevel + + ;
EditorGUI . BeginChangeCheck ( ) ;
EditorGUILayout . PropertyField ( emulateSecondMousePointer , TEXT_EMULATE_MOUSE ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
instance . EmulateSecondMousePointer = emulateSecondMousePointer . boolValue ;
}
EditorGUI . indentLevel - - ;
}
2025-06-04 22:49:37 +08:00
}
private void drawWindows ( )
{
2025-08-24 18:59:40 +08:00
var display = GUIElements . Header ( TEXT_WINDOWS_HEADER , windowsProps ) ;
if ( display )
{
EditorGUI . indentLevel + + ;
EditorGUILayout . PropertyField ( windows8Touch , TEXT_WINDOWS8 ) ;
EditorGUILayout . PropertyField ( windows7Touch , TEXT_WINDOWS7 ) ;
EditorGUILayout . LabelField ( TEXT_WINDOWS_API , GUIElements . HelpBox ) ;
EditorGUILayout . PropertyField ( windows8Mouse , TEXT_WINDOWS8_MOUSE ) ;
EditorGUILayout . PropertyField ( windows7Mouse , TEXT_WINDOWS7_MOUSE ) ;
EditorGUILayout . PropertyField ( universalWindowsMouse , TEXT_UWP_MOUSE ) ;
EditorGUI . indentLevel - - ;
}
2025-06-04 22:49:37 +08:00
}
private void drawWebGL ( )
{
2025-08-24 18:59:40 +08:00
var display = GUIElements . Header ( TEXT_WEBGL_HEADER , webglProps ) ;
if ( display )
{
EditorGUI . indentLevel + + ;
EditorGUILayout . PropertyField ( webGLTouch ) ;
EditorGUI . indentLevel - - ;
}
2025-06-04 22:49:37 +08:00
}
}
}