Skip to content

Commit bcbb1ff

Browse files
committed
TouchScript pointer events debug.
1 parent 2fd095f commit bcbb1ff

7 files changed

Lines changed: 150 additions & 12 deletions

File tree

Source/Assets/TouchScript/Editor/TouchManagerEditor.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using TouchScript.Devices.Display;
8+
using TouchScript.Editor.Utils;
89
using TouchScript.Layers;
910
using UnityEditor;
1011
using UnityEditorInternal;
@@ -16,6 +17,8 @@ namespace TouchScript.Editor
1617
[CustomEditor(typeof(TouchManager))]
1718
internal sealed class TouchManagerEditor : UnityEditor.Editor
1819
{
20+
private static readonly GUIContent TEXT_ADVANCED_HEADER = new GUIContent("Advanced", "Advanced properties.");
21+
private static readonly GUIContent DEBUG_MODE = new GUIContent("Debug", "Turns on debug mode.");
1922
private static readonly GUIContent DISPLAY_DEVICE = new GUIContent("Display Device", "Display device properties where such parameters as target DPI are stored.");
2023
private static readonly GUIContent CREATE_CAMERA_LAYER = new GUIContent("Create Camera Layer", "Indicates if TouchScript should create a CameraLayer for you if no layers present in a scene. This is usually a desired behavior but sometimes you would want to turn this off if you are using TouchScript only to get input from some device.");
2124
private static readonly GUIContent CREATE_STANDARD_INPUT = new GUIContent("Create Standard Input", "");
@@ -26,11 +29,15 @@ internal sealed class TouchManagerEditor : UnityEditor.Editor
2629

2730
private TouchManager instance;
2831
private ReorderableList layersList;
32+
private SerializedProperty advanced;
33+
private SerializedProperty debugMode;
2934
private SerializedProperty layers, displayDevice, shouldCreateCameraLayer, shouldCreateStandardInput, useSendMessage, sendMessageTarget, sendMessageEvents;
3035

3136
private void OnEnable()
3237
{
3338
instance = target as TouchManager;
39+
advanced = serializedObject.FindProperty("advancedProps");
40+
debugMode = serializedObject.FindProperty("debugMode");
3441
layers = serializedObject.FindProperty("layers");
3542
displayDevice = serializedObject.FindProperty("displayDevice");
3643
shouldCreateCameraLayer = serializedObject.FindProperty("shouldCreateCameraLayer");
@@ -103,9 +110,39 @@ public override void OnInspectorGUI()
103110
layersList.DoLayoutList();
104111

105112
GUI.enabled = true;
113+
114+
if (debugMode != null)
115+
{
116+
EditorGUI.BeginChangeCheck();
117+
var expanded = GUIElements.BeginFoldout(advanced.isExpanded, TEXT_ADVANCED_HEADER);
118+
if (EditorGUI.EndChangeCheck())
119+
{
120+
advanced.isExpanded = expanded;
121+
}
122+
if (expanded)
123+
{
124+
GUILayout.BeginVertical(GUIElements.FoldoutStyle);
125+
drawAdvanced();
126+
GUILayout.EndVertical();
127+
}
128+
GUIElements.EndFoldout();
129+
}
106130
serializedObject.ApplyModifiedProperties();
107131
}
108132

133+
private void drawAdvanced()
134+
{
135+
drawDebug();
136+
}
137+
138+
private void drawDebug()
139+
{
140+
if (debugMode == null) return;
141+
EditorGUI.BeginChangeCheck();
142+
EditorGUILayout.PropertyField(debugMode, DEBUG_MODE);
143+
if (EditorGUI.EndChangeCheck()) instance.DebugMode = debugMode.boolValue;
144+
}
145+
109146
private void refresh()
110147
{
111148
var allLayers = FindObjectsOfType(typeof(TouchLayer)).Cast<TouchLayer>().ToList();

Source/Assets/TouchScript/Scripts/DebuggableMonoBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace TouchScript
1515
public class DebuggableMonoBehaviour : MonoBehaviour, IDebuggable
1616
{
1717
/// <inheritdoc />
18-
public bool DebugMode
18+
public virtual bool DebugMode
1919
{
2020
get
2121
{

Source/Assets/TouchScript/Scripts/Pointers/Pointer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
* @author Valentin Simonov / http://va.lent.in/
33
*/
44

5+
using System;
6+
using System.Text;
57
using TouchScript.Hit;
68
using TouchScript.InputSources;
79
using TouchScript.Layers;
10+
using TouchScript.Utils;
811
using UnityEngine;
912

1013
namespace TouchScript.Pointers
@@ -150,6 +153,8 @@ public ProjectionParams ProjectionParams
150153

151154
#region Private variables
152155

156+
private static StringBuilder builder;
157+
153158
private TouchManagerInstance manager;
154159
private int refCount = 0;
155160
private Vector2 position, newPosition;
@@ -216,6 +221,25 @@ public override int GetHashCode()
216221
return Id;
217222
}
218223

224+
/// <inheritdoc />
225+
public override string ToString()
226+
{
227+
if (builder == null) builder = new StringBuilder();
228+
builder.Length = 0;
229+
builder.Append("(Pointer type: ");
230+
builder.Append(Type);
231+
builder.Append(", id: ");
232+
builder.Append(Id);
233+
builder.Append(", flags: ");
234+
BinaryUtils.ToBinaryString(Flags, builder, 8);
235+
// builder.Append(", buttons: ");
236+
// builder.Append((uint)Buttons);
237+
builder.Append(", position: ");
238+
builder.Append(Position);
239+
builder.Append(")");
240+
return builder.ToString();
241+
}
242+
219243
#endregion
220244

221245
#region Constructor

Source/Assets/TouchScript/Scripts/TouchManager.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace TouchScript
2222
/// </remarks>
2323
[AddComponentMenu("TouchScript/Pointer Manager")]
2424
[HelpURL("http://touchscript.github.io/docs/html/T_TouchScript_TouchManager.htm")]
25-
public sealed class TouchManager : MonoBehaviour
25+
public sealed class TouchManager : DebuggableMonoBehaviour
2626
{
2727
#region Constants
2828

@@ -247,7 +247,21 @@ public GameObject SendMessageTarget
247247
}
248248
}
249249

250-
#endregion
250+
#if TOUCHSCRIPT_DEBUG
251+
252+
public override bool DebugMode
253+
{
254+
get { return base.DebugMode; }
255+
set
256+
{
257+
base.DebugMode = value;
258+
if (Application.isPlaying) (Instance as TouchManagerInstance).DebugMode = value;
259+
}
260+
}
261+
262+
#endif
263+
264+
#endregion
251265

252266
#region Public methods
253267

@@ -265,6 +279,9 @@ public static bool IsInvalidPosition(Vector2 position)
265279

266280
#region Private variables
267281

282+
[SerializeField]
283+
private bool advancedProps; // is used to save if advanced properties are opened or closed
284+
268285
[SerializeField]
269286
private Object displayDevice;
270287

Source/Assets/TouchScript/Scripts/TouchManagerInstance.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ internal void INTERNAL_AddPointer(Pointer pointer)
366366
{
367367
pointer.INTERNAL_Init(nextPointerId++);
368368
pointersAdded.Add(pointer);
369+
370+
#if TOUCHSCRIPT_DEBUG
371+
if (DebugMode) Debug.Log("TouchScript > Pointer Added: " + pointer);
372+
#endif
369373
}
370374
}
371375

@@ -382,13 +386,17 @@ internal void INTERNAL_UpdatePointer(int id)
382386
if (pointer == null)
383387
{
384388
#if TOUCHSCRIPT_DEBUG
385-
Debug.LogWarning("TouchScript > Pointer with id [" + id + "] is requested to MOVE to but no pointer with such id found.");
389+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id + "] is requested to MOVE to but no pointer with such id found.");
386390
#endif
387391
return;
388392
}
389393
}
390394

391395
pointersUpdated.Add(id);
396+
397+
#if TOUCHSCRIPT_DEBUG
398+
if (DebugMode) Debug.Log("TouchScript > Pointer Updated: " + pointer);
399+
#endif
392400
}
393401
}
394402

@@ -405,19 +413,23 @@ internal void INTERNAL_PressPointer(int id)
405413
if (pointer == null)
406414
{
407415
#if TOUCHSCRIPT_DEBUG
408-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
416+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
409417
"] is requested to PRESS but no pointer with such id found.");
410418
#endif
411419
return;
412420
}
413421
}
414422
#if TOUCHSCRIPT_DEBUG
415423
if (!pointersPressed.Add(id))
416-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
424+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
417425
"] is requested to PRESS more than once this frame.");
418426
#else
419427
pointersPressed.Add(id);
420428
#endif
429+
430+
#if TOUCHSCRIPT_DEBUG
431+
if (DebugMode) Debug.Log("TouchScript > Pointer Pressed: " + pointer);
432+
#endif
421433
}
422434
}
423435

@@ -435,19 +447,23 @@ internal void INTERNAL_ReleasePointer(int id)
435447
if (pointer == null)
436448
{
437449
#if TOUCHSCRIPT_DEBUG
438-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
450+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
439451
"] is requested to END but no pointer with such id found.");
440452
#endif
441453
return;
442454
}
443455
}
444456
#if TOUCHSCRIPT_DEBUG
445457
if (!pointersReleased.Add(id))
446-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
458+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
447459
"] is requested to END more than once this frame.");
448460
#else
449461
pointersReleased.Add(id);
450462
#endif
463+
464+
#if TOUCHSCRIPT_DEBUG
465+
if (DebugMode) Debug.Log("TouchScript > Pointer Released: " + pointer);
466+
#endif
451467
}
452468
}
453469

@@ -465,19 +481,23 @@ internal void INTERNAL_RemovePointer(int id)
465481
if (pointer == null)
466482
{
467483
#if TOUCHSCRIPT_DEBUG
468-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
484+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
469485
"] is requested to REMOVE but no pointer with such id found.");
470486
#endif
471487
return;
472488
}
473489
}
474490
#if TOUCHSCRIPT_DEBUG
475491
if (!pointersRemoved.Add(pointer.Id))
476-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
492+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
477493
"] is requested to REMOVE more than once this frame.");
478494
#else
479495
pointersRemoved.Add(pointer.Id);
480496
#endif
497+
498+
#if TOUCHSCRIPT_DEBUG
499+
if (DebugMode) Debug.Log("TouchScript > Pointer Removed: " + pointer);
500+
#endif
481501
}
482502
}
483503

@@ -495,19 +515,23 @@ internal void INTERNAL_CancelPointer(int id)
495515
if (pointer == null)
496516
{
497517
#if TOUCHSCRIPT_DEBUG
498-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
518+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
499519
"] is requested to CANCEL but no pointer with such id found.");
500520
#endif
501521
return;
502522
}
503523
}
504524
#if TOUCHSCRIPT_DEBUG
505525
if (!pointersCancelled.Add(pointer.Id))
506-
Debug.LogWarning("TouchScript > Pointer with id [" + id +
526+
if (DebugMode) Debug.LogWarning("TouchScript > Pointer with id [" + id +
507527
"] is requested to CANCEL more than once this frame.");
508528
#else
509529
pointersCancelled.Add(pointer.Id);
510530
#endif
531+
532+
#if TOUCHSCRIPT_DEBUG
533+
if (DebugMode) Debug.Log("TouchScript > Pointer Cancelled: " + pointer);
534+
#endif
511535
}
512536
}
513537

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @author Valentin Simonov / http://va.lent.in/
3+
*/
4+
5+
using System.Text;
6+
7+
namespace TouchScript.Utils
8+
{
9+
public static class BinaryUtils
10+
{
11+
12+
public static void ToBinaryString(uint value, StringBuilder builder, int digits = 32)
13+
{
14+
int i = digits-1;
15+
16+
while (i >= 0)
17+
{
18+
builder.Append((value & (1 << i)) == 0 ? 0 : 1);
19+
i--;
20+
}
21+
}
22+
23+
}
24+
}

Source/Assets/TouchScript/Scripts/Utils/BinaryUtils.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)