Skip to content

Commit 6c867a4

Browse files
committed
make the debug panel more generic.
1 parent fb69c3f commit 6c867a4

File tree

6 files changed

+268
-29
lines changed

6 files changed

+268
-29
lines changed

Assets/HoloToolkit/SharingWithUNET/Scenes/sharingwithunet.unity

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,22 @@ Transform:
287287
m_Father: {fileID: 0}
288288
m_RootOrder: 0
289289
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
290+
--- !u!1 &917363093 stripped
291+
GameObject:
292+
m_PrefabParentObject: {fileID: 1371320736001650, guid: 2617ed8230126704a992bd57fe1c7440,
293+
type: 2}
294+
m_PrefabInternal: {fileID: 1410349150}
295+
--- !u!114 &917363094
296+
MonoBehaviour:
297+
m_ObjectHideFlags: 0
298+
m_PrefabParentObject: {fileID: 0}
299+
m_PrefabInternal: {fileID: 0}
300+
m_GameObject: {fileID: 917363093}
301+
m_Enabled: 1
302+
m_EditorHideFlags: 0
303+
m_Script: {fileID: 11500000, guid: c34a8789a29e1644bab6e6054360bb99, type: 3}
304+
m_Name:
305+
m_EditorClassIdentifier:
290306
--- !u!1 &942915099
291307
GameObject:
292308
m_ObjectHideFlags: 0

Assets/HoloToolkit/SharingWithUNET/Scripts/UNetAnchorManager.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
3-
43
using UnityEngine;
54
using System.Collections.Generic;
65
using UnityEngine.Networking;
@@ -178,6 +177,13 @@ private void Start()
178177
{
179178
networkTransmitter.dataReadyEvent += NetworkTransmitter_dataReadyEvent;
180179
}
180+
181+
// If we have a debug panel, then we have debug data for the panel.
182+
DebugPanel debugPanel = DebugPanel.Instance;
183+
if (debugPanel != null)
184+
{
185+
DebugPanel.Instance.RegisterExternalLogCallback(GenearteDebugData);
186+
}
181187
}
182188

183189
private void Update()
@@ -216,6 +222,21 @@ private void Update()
216222
#endif
217223
}
218224

225+
/// <summary>
226+
/// creates a debug string with information about the anchor state.
227+
/// </summary>
228+
/// <returns>The calculated string</returns>
229+
private string GenearteDebugData()
230+
{
231+
return string.Format("Anchor Name: {0}\nAnchor Size: {1}\nAnchor Established?: {2}\nImporting?: {3}\nDownloading? {4}\n",
232+
AnchorName,
233+
anchorData == null? exportingAnchorBytes.Count : anchorData.Length,
234+
AnchorEstablished.ToString(),
235+
ImportInProgress.ToString(),
236+
DownloadingAnchor.ToString()
237+
);
238+
}
239+
219240
/// <summary>
220241
/// If we are supposed to create the anchor for export, this is the function to call.
221242
/// </summary>

Assets/HoloToolkit/Utilities/Prefabs/DebugPanelButton.prefab

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ GameObject:
4545
m_NavMeshLayer: 0
4646
m_StaticEditorFlags: 0
4747
m_IsActive: 1
48+
--- !u!1 &1232119099239622
49+
GameObject:
50+
m_ObjectHideFlags: 1
51+
m_PrefabParentObject: {fileID: 0}
52+
m_PrefabInternal: {fileID: 100100000}
53+
serializedVersion: 5
54+
m_Component:
55+
- component: {fileID: 4251504571719366}
56+
- component: {fileID: 23966609145256688}
57+
- component: {fileID: 102134708139338272}
58+
- component: {fileID: 114393306038206784}
59+
- component: {fileID: 65611560049109936}
60+
m_Layer: 0
61+
m_Name: ResetAnchorButton
62+
m_TagString: Untagged
63+
m_Icon: {fileID: 0}
64+
m_NavMeshLayer: 0
65+
m_StaticEditorFlags: 0
66+
m_IsActive: 1
4867
--- !u!1 &1371320736001650
4968
GameObject:
5069
m_ObjectHideFlags: 1
@@ -56,6 +75,7 @@ GameObject:
5675
- component: {fileID: 23933927152624494}
5776
- component: {fileID: 102947068611790156}
5877
- component: {fileID: 114792128557023346}
78+
- component: {fileID: 114373287903851202}
5979
m_Layer: 0
6080
m_Name: BasicStatus
6181
m_TagString: Untagged
@@ -127,6 +147,19 @@ GameObject:
127147
m_NavMeshLayer: 0
128148
m_StaticEditorFlags: 0
129149
m_IsActive: 1
150+
--- !u!4 &4251504571719366
151+
Transform:
152+
m_ObjectHideFlags: 1
153+
m_PrefabParentObject: {fileID: 0}
154+
m_PrefabInternal: {fileID: 100100000}
155+
m_GameObject: {fileID: 1232119099239622}
156+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
157+
m_LocalPosition: {x: 0, y: 0.24, z: 0}
158+
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
159+
m_Children: []
160+
m_Father: {fileID: 4780174366001566}
161+
m_RootOrder: 2
162+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
130163
--- !u!4 &4264367764062018
131164
Transform:
132165
m_ObjectHideFlags: 1
@@ -186,7 +219,7 @@ Transform:
186219
m_PrefabInternal: {fileID: 100100000}
187220
m_GameObject: {fileID: 1458721125678660}
188221
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
189-
m_LocalPosition: {x: 0.42, y: 0, z: -0.49}
222+
m_LocalPosition: {x: 0.05, y: 0.19, z: 0}
190223
m_LocalScale: {x: 1, y: 1, z: 1}
191224
m_Children:
192225
- {fileID: 4264367764062018}
@@ -208,6 +241,7 @@ Transform:
208241
m_Children:
209242
- {fileID: 4998650542038264}
210243
- {fileID: 4453389005104068}
244+
- {fileID: 4251504571719366}
211245
m_Father: {fileID: 4742522814745148}
212246
m_RootOrder: 3
213247
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -320,6 +354,50 @@ MeshRenderer:
320354
m_SortingLayerID: 0
321355
m_SortingLayer: 0
322356
m_SortingOrder: 0
357+
--- !u!23 &23966609145256688
358+
MeshRenderer:
359+
m_ObjectHideFlags: 1
360+
m_PrefabParentObject: {fileID: 0}
361+
m_PrefabInternal: {fileID: 100100000}
362+
m_GameObject: {fileID: 1232119099239622}
363+
m_Enabled: 1
364+
m_CastShadows: 1
365+
m_ReceiveShadows: 1
366+
m_MotionVectors: 1
367+
m_LightProbeUsage: 1
368+
m_ReflectionProbeUsage: 1
369+
m_Materials:
370+
- {fileID: 10100, guid: 0000000000000000e000000000000000, type: 0}
371+
m_StaticBatchInfo:
372+
firstSubMesh: 0
373+
subMeshCount: 0
374+
m_StaticBatchRoot: {fileID: 0}
375+
m_ProbeAnchor: {fileID: 0}
376+
m_LightProbeVolumeOverride: {fileID: 0}
377+
m_ScaleInLightmap: 1
378+
m_PreserveUVs: 0
379+
m_IgnoreNormalsForChartDetection: 0
380+
m_ImportantGI: 0
381+
m_SelectedEditorRenderState: 3
382+
m_MinimumChartSize: 4
383+
m_AutoUVMaxDistance: 0.5
384+
m_AutoUVMaxAngle: 89
385+
m_LightmapParameters: {fileID: 0}
386+
m_SortingLayerID: 0
387+
m_SortingLayer: 0
388+
m_SortingOrder: 0
389+
--- !u!65 &65611560049109936
390+
BoxCollider:
391+
m_ObjectHideFlags: 1
392+
m_PrefabParentObject: {fileID: 0}
393+
m_PrefabInternal: {fileID: 100100000}
394+
m_GameObject: {fileID: 1232119099239622}
395+
m_Material: {fileID: 0}
396+
m_IsTrigger: 0
397+
m_Enabled: 1
398+
serializedVersion: 2
399+
m_Size: {x: 72.799995, y: 13.406249, z: 0}
400+
m_Center: {x: 36.399998, y: -6.703155, z: 0}
323401
--- !u!65 &65654802773861156
324402
BoxCollider:
325403
m_ObjectHideFlags: 1
@@ -332,6 +410,27 @@ BoxCollider:
332410
serializedVersion: 2
333411
m_Size: {x: 5.1999993, y: 4.9599996, z: 0.19999999}
334412
m_Center: {x: 0, y: 0, z: 0.000015258789}
413+
--- !u!102 &102134708139338272
414+
TextMesh:
415+
serializedVersion: 3
416+
m_ObjectHideFlags: 1
417+
m_PrefabParentObject: {fileID: 0}
418+
m_PrefabInternal: {fileID: 100100000}
419+
m_GameObject: {fileID: 1232119099239622}
420+
m_Text: Reset Anchor
421+
m_OffsetZ: 0
422+
m_CharacterSize: 1
423+
m_LineSpacing: 1
424+
m_Anchor: 0
425+
m_Alignment: 0
426+
m_TabSize: 4
427+
m_FontSize: 120
428+
m_FontStyle: 0
429+
m_RichText: 1
430+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
431+
m_Color:
432+
serializedVersion: 2
433+
rgba: 4279242986
335434
--- !u!102 &102364529909080226
336435
TextMesh:
337436
serializedVersion: 3
@@ -397,6 +496,28 @@ TextMesh:
397496
m_Color:
398497
serializedVersion: 2
399498
rgba: 4283567824
499+
--- !u!114 &114373287903851202
500+
MonoBehaviour:
501+
m_ObjectHideFlags: 1
502+
m_PrefabParentObject: {fileID: 0}
503+
m_PrefabInternal: {fileID: 100100000}
504+
m_GameObject: {fileID: 1371320736001650}
505+
m_Enabled: 1
506+
m_EditorHideFlags: 0
507+
m_Script: {fileID: 11500000, guid: c34a8789a29e1644bab6e6054360bb99, type: 3}
508+
m_Name:
509+
m_EditorClassIdentifier:
510+
--- !u!114 &114393306038206784
511+
MonoBehaviour:
512+
m_ObjectHideFlags: 1
513+
m_PrefabParentObject: {fileID: 0}
514+
m_PrefabInternal: {fileID: 100100000}
515+
m_GameObject: {fileID: 1232119099239622}
516+
m_Enabled: 1
517+
m_EditorHideFlags: 0
518+
m_Script: {fileID: 11500000, guid: 76bb4107aed53a54ca76f5b4fb92dc16, type: 3}
519+
m_Name:
520+
m_EditorClassIdentifier:
400521
--- !u!114 &114469014515939562
401522
MonoBehaviour:
402523
m_ObjectHideFlags: 1

Assets/HoloToolkit/Utilities/Scripts/DebugPanel.cs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System.Collections;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
using HoloToolkit.Unity;
24
using System.Collections.Generic;
35
using UnityEngine;
46

57
/// <summary>
68
/// Script to control writing the Debug.Log output to a control.
79
/// </summary>
8-
public class DebugPanel : MonoBehaviour
10+
public class DebugPanel : SingleInstance<DebugPanel>
911
{
1012
/// <summary>
1113
/// The text mesh we will write log messages to
@@ -24,12 +26,17 @@ public class DebugPanel : MonoBehaviour
2426
private int maxLogMessages = 30;
2527

2628
/// <summary>
27-
/// Variables for an FPS counter
29+
/// If another script wants to make a log entry per frame they will implement this delegate.
2830
/// </summary>
29-
private int frameCount;
30-
private int framesPerSecond;
31-
private int lastWholeTime = 0;
31+
/// <returns></returns>
32+
public delegate string GetLogLine();
3233

34+
/// <summary>
35+
/// A list of GetLogLine delegates to call for per frame information.
36+
/// </summary>
37+
private List<GetLogLine> ExternalLogs = new List<GetLogLine>();
38+
39+
3340
void Awake()
3441
{
3542
textMesh = GetComponent<TextMesh>();
@@ -38,12 +45,8 @@ void Awake()
3845

3946
void Update()
4047
{
41-
UpdateFPS();
42-
4348
string logMessageString = CalculateLogMessageString();
44-
string FPSString = string.Format("FPS: {0}\n", framesPerSecond);
45-
46-
textMesh.text = string.Format("{0}\n{1}\n", FPSString, logMessageString);
49+
textMesh.text = logMessageString;
4750
}
4851

4952
/// <summary>
@@ -52,7 +55,17 @@ void Update()
5255
/// <returns>The formatted string</returns>
5356
string CalculateLogMessageString()
5457
{
55-
string logMessageString = "";
58+
string logMessageString = "Per Frame Data:\n------\n";
59+
for(int index=0;index<ExternalLogs.Count;index++)
60+
{
61+
string nextExternalLine = ExternalLogs[index]();
62+
if (!string.IsNullOrEmpty(nextExternalLine))
63+
{
64+
logMessageString += string.Format("{0}\n", nextExternalLine);
65+
}
66+
}
67+
68+
logMessageString += string.Format("------\n");
5669

5770
lock (logMessages)
5871
{
@@ -73,21 +86,6 @@ string CalculateLogMessageString()
7386
return logMessageString;
7487
}
7588

76-
/// <summary>
77-
/// Keeps track of rough frames per second.
78-
/// </summary>
79-
void UpdateFPS()
80-
{
81-
frameCount++;
82-
int currentWholeTime = (int)Time.realtimeSinceStartup;
83-
if (currentWholeTime != lastWholeTime)
84-
{
85-
lastWholeTime = currentWholeTime;
86-
framesPerSecond = frameCount;
87-
frameCount = 0;
88-
}
89-
}
90-
9189
/// <summary>
9290
/// Called when the application calls Debug.Log and friends
9391
/// </summary>
@@ -117,4 +115,25 @@ private void LogCallback(string Message, string stack, LogType logType)
117115
}
118116
}
119117
}
118+
119+
/// <summary>
120+
/// Call this to register your script to provide a debug string each frame.
121+
/// </summary>
122+
/// <param name="callback">The delegate to call back</param>
123+
public void RegisterExternalLogCallback(GetLogLine callback)
124+
{
125+
ExternalLogs.Add(callback);
126+
}
127+
128+
/// <summary>
129+
/// Call this when you no longer want to provide a debug string each frame.
130+
/// </summary>
131+
/// <param name="callback">The callback to stop calling</param>
132+
public void UnregisterExternalLogCallback(GetLogLine callback)
133+
{
134+
if (ExternalLogs.Contains(callback))
135+
{
136+
ExternalLogs.Remove(callback);
137+
}
138+
}
120139
}

0 commit comments

Comments
 (0)