Skip to content

Commit 734ff05

Browse files
committed
Added session debugger tool
1 parent 1619aab commit 734ff05

File tree

5 files changed

+229
-32
lines changed

5 files changed

+229
-32
lines changed

Assets/UXF/Prefabs/[UXF_Core].prefab

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ GameObject:
2222
- component: {fileID: 114916036141644208}
2323
- component: {fileID: 114324480150258046}
2424
- component: {fileID: 114155219626309100}
25-
- component: {fileID: 114908171941659672}
2625
- component: {fileID: 114291432593817218}
2726
m_Layer: 0
2827
m_Name: '[UXF_Core]'
@@ -85,21 +84,6 @@ MonoBehaviour:
8584
m_Calls: []
8685
m_TypeName: UXF.WriteFileEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
8786
PublicKeyToken=null
88-
--- !u!114 &114908171941659672
89-
MonoBehaviour:
90-
m_ObjectHideFlags: 1
91-
m_PrefabParentObject: {fileID: 0}
92-
m_PrefabInternal: {fileID: 100100000}
93-
m_GameObject: {fileID: 1970900254558334}
94-
m_Enabled: 1
95-
m_EditorHideFlags: 0
96-
m_Script: {fileID: 11500000, guid: 93551dc7197ac2347b099263053405aa, type: 3}
97-
m_Name:
98-
m_EditorClassIdentifier:
99-
displaySessionProtocol: 0
100-
sessionProtocol: 'Press the above button after generating your blocks and trials
101-
to list all blocks and trials with their associated setting in the session. This
102-
helps you make sure settings are being applied to the correct trials. '
10387
--- !u!114 &114916036141644208
10488
MonoBehaviour:
10589
m_ObjectHideFlags: 1
@@ -111,6 +95,7 @@ MonoBehaviour:
11195
m_Script: {fileID: 11500000, guid: fa9f2505d11cc9e4aa44357b47b12905, type: 3}
11296
m_Name:
11397
m_EditorClassIdentifier:
98+
endOnQuit: 1
11499
endOnDestroy: 1
115100
settingsToLog: []
116101
customHeaders: []
@@ -130,6 +115,11 @@ MonoBehaviour:
130115
m_Calls: []
131116
m_TypeName: UXF.TrialEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
132117
PublicKeyToken=null
118+
onSessionEnd:
119+
m_PersistentCalls:
120+
m_Calls: []
121+
m_TypeName: UXF.SessionEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
122+
PublicKeyToken=null
133123
_hasInitialised: 0
134124
experimentName:
135125
ppid:

Assets/UXF/Prefabs/[UXF_Rig].prefab

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,6 @@ GameObject:
13561356
- component: {fileID: 114916036141644208}
13571357
- component: {fileID: 114324480150258046}
13581358
- component: {fileID: 114155219626309100}
1359-
- component: {fileID: 114908171941659672}
13601359
- component: {fileID: 114291432593817218}
13611360
m_Layer: 0
13621361
m_Name: '[UXF_Rig]'
@@ -2674,6 +2673,11 @@ MonoBehaviour:
26742673
m_Name:
26752674
m_EditorClassIdentifier:
26762675
debug: 0
2676+
onWriteFile:
2677+
m_PersistentCalls:
2678+
m_Calls: []
2679+
m_TypeName: UXF.WriteFileEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
2680+
PublicKeyToken=null
26772681
--- !u!114 &114344481789201668
26782682
MonoBehaviour:
26792683
m_ObjectHideFlags: 1
@@ -4540,21 +4544,6 @@ MonoBehaviour:
45404544
m_TypeName: UnityEngine.UI.Toggle+ToggleEvent, UnityEngine.UI, Version=1.0.0.0,
45414545
Culture=neutral, PublicKeyToken=null
45424546
m_IsOn: 1
4543-
--- !u!114 &114908171941659672
4544-
MonoBehaviour:
4545-
m_ObjectHideFlags: 1
4546-
m_PrefabParentObject: {fileID: 0}
4547-
m_PrefabInternal: {fileID: 100100000}
4548-
m_GameObject: {fileID: 1970900254558334}
4549-
m_Enabled: 1
4550-
m_EditorHideFlags: 0
4551-
m_Script: {fileID: 11500000, guid: 93551dc7197ac2347b099263053405aa, type: 3}
4552-
m_Name:
4553-
m_EditorClassIdentifier:
4554-
displaySessionProtocol: 0
4555-
sessionProtocol: 'Press the above button after generating your blocks and trials
4556-
to list all blocks and trials with their associated setting in the session. This
4557-
helps you make sure settings are being applied to the correct trials. '
45584547
--- !u!114 &114916036141644208
45594548
MonoBehaviour:
45604549
m_ObjectHideFlags: 1
@@ -4566,6 +4555,7 @@ MonoBehaviour:
45664555
m_Script: {fileID: 11500000, guid: fa9f2505d11cc9e4aa44357b47b12905, type: 3}
45674556
m_Name:
45684557
m_EditorClassIdentifier:
4558+
endOnQuit: 1
45694559
endOnDestroy: 1
45704560
settingsToLog: []
45714561
customHeaders: []
@@ -4585,6 +4575,11 @@ MonoBehaviour:
45854575
m_Calls: []
45864576
m_TypeName: UXF.TrialEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
45874577
PublicKeyToken=null
4578+
onSessionEnd:
4579+
m_PersistentCalls:
4580+
m_Calls: []
4581+
m_TypeName: UXF.SessionEvent, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
4582+
PublicKeyToken=null
45884583
_hasInitialised: 0
45894584
experimentName:
45904585
ppid:
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using UXF;
6+
7+
namespace UXFTools
8+
{
9+
10+
[InitializeOnLoad]
11+
public class UXFSessionDisplay : EditorWindow
12+
{
13+
static Vector2 scrollPos;
14+
static Session session;
15+
static Dictionary<string, object> settingsDict;
16+
static bool parsed;
17+
18+
19+
[MenuItem("UXF/Show session debugger")]
20+
static void Init()
21+
{
22+
FetchReferences();
23+
var window = (UXFSessionDisplay)EditorWindow.GetWindow(typeof(UXFSessionDisplay));
24+
window.minSize = new Vector2(300, 500);
25+
window.titleContent = new GUIContent("UXF Session Debugger");
26+
window.Show();
27+
}
28+
29+
static UXFSessionDisplay()
30+
{
31+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
32+
}
33+
34+
static void OnPlayModeStateChanged(PlayModeStateChange state)
35+
{
36+
if (state == PlayModeStateChange.EnteredPlayMode)
37+
{
38+
FetchReferences();
39+
}
40+
}
41+
42+
static void FetchReferences()
43+
{
44+
session = FindObjectOfType<Session>();
45+
if (!session)
46+
{
47+
settingsDict = null;
48+
return;
49+
}
50+
if (session.settings == null)
51+
{
52+
settingsDict = null;
53+
return;
54+
}
55+
56+
settingsDict = new Dictionary<string, object>();
57+
// log each session setting
58+
foreach (string key in session.settings.Keys)
59+
settingsDict.Add(key, session.settings[key].ToString());
60+
61+
List<Dictionary<string, object>> blockList = new List<Dictionary<string, object>>();
62+
foreach (var block in session.blocks)
63+
{
64+
Dictionary<string, object> blockDict = new Dictionary<string, object>();
65+
// log each block setting
66+
foreach (string key in block.settings.Keys)
67+
blockDict.Add(key, block.settings[key].ToString());
68+
69+
List<Dictionary<string, object>> trialList = new List<Dictionary<string, object>>();
70+
// log each trial
71+
foreach (var trial in block.trials)
72+
{
73+
Dictionary<string, object> trialDict = new Dictionary<string, object>();
74+
// log each trial setting
75+
foreach (string key in trial.settings.Keys)
76+
trialDict.Add(key, trial.settings[key].ToString());
77+
78+
// add trial to block
79+
trialList.Add(trialDict);
80+
}
81+
blockDict.Add("_____trials", trialList);
82+
blockList.Add(blockDict);
83+
}
84+
settingsDict.Add("_____blocks", blockList);
85+
}
86+
87+
public void OnGUI()
88+
{
89+
EditorGUILayout.Space();
90+
GUIStyle labelStyle = new GUIStyle();
91+
labelStyle.wordWrap = true;
92+
labelStyle.margin = new RectOffset(6, 6, 0, 0);
93+
94+
GUILayout.Label("Press the button below after generating your blocks and trials to list all blocks and trials with their associated setting in the session. This helps you make sure settings are being applied to the correct trials. ", labelStyle);
95+
if (GUILayout.Button("Fetch session info"))
96+
{
97+
FetchReferences();
98+
}
99+
100+
if (settingsDict != null)
101+
{
102+
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
103+
ParseSettings();
104+
EditorGUILayout.EndScrollView();
105+
return;
106+
}
107+
else if (!session)
108+
{
109+
EditorGUILayout.HelpBox("Did not find a UXF.Session component in the scene! Press button above to try again.", UnityEditor.MessageType.Error);
110+
return;
111+
}
112+
else if (!session.hasInitialised)
113+
{
114+
EditorGUILayout.HelpBox("Session has not yet started! This debugging tool can be used only when the session has started. Press button above to try again.", UnityEditor.MessageType.Warning);
115+
return;
116+
}
117+
GUILayout.Label("Something went wrong.", labelStyle);
118+
return;
119+
120+
}
121+
122+
123+
static void ParseSettings()
124+
{
125+
EditorGUILayout.HelpBox("Remember, Settings requests cascade upwards: That means accessing a settings in a trial will first look inside the trial, if it is then not found, will look inside the block, then the session.", UnityEditor.MessageType.Info);
126+
127+
GUILayout.Label("Session .settings", EditorStyles.boldLabel);
128+
129+
// add more info...
130+
EditorGUILayout.BeginVertical("box");
131+
132+
// log each session setting
133+
GUIKeyValuePairColumns(settingsDict);
134+
EditorGUILayout.Space();
135+
136+
EditorGUILayout.BeginVertical("box");
137+
138+
var blockList = (List<Dictionary<string, object>>) settingsDict["_____blocks"];
139+
140+
int b = 0;
141+
foreach (var block in blockList)
142+
{
143+
GUILayout.Label(string.Format("Block {0} .settings", ++b), EditorStyles.boldLabel);
144+
EditorGUILayout.BeginVertical("box");
145+
146+
GUIKeyValuePairColumns(block);
147+
EditorGUILayout.Space();
148+
149+
var trialList = (List<Dictionary<string, object>>) block["_____trials"];
150+
151+
int t = 0;
152+
foreach (var trial in trialList)
153+
{
154+
GUILayout.Label(string.Format("Trial {0} .settings", ++t), EditorStyles.boldLabel);
155+
EditorGUILayout.BeginVertical("box");
156+
GUIKeyValuePairColumns(trial);
157+
158+
EditorGUILayout.EndVertical();
159+
}
160+
161+
162+
EditorGUILayout.EndVertical();
163+
}
164+
165+
EditorGUILayout.EndVertical();
166+
EditorGUILayout.EndVertical();
167+
168+
}
169+
170+
static void GUIKeyValuePairColumns(Dictionary<string, object> dict)
171+
{
172+
if (dict.Count == 0)
173+
{
174+
EditorGUILayout.LabelField("None", EditorStyles.miniLabel);
175+
return;
176+
}
177+
178+
foreach (KeyValuePair<string, object> pair in dict)
179+
{
180+
string k = pair.Key;
181+
if (k.StartsWith("_____")) continue;
182+
183+
GUILayout.BeginHorizontal();
184+
string v = Truncate(pair.Value.ToString(), 100);
185+
EditorGUILayout.LabelField(string.Format("[\"{0}\"]: {1}", k, v));
186+
GUILayout.EndHorizontal();
187+
}
188+
189+
}
190+
191+
192+
static string Truncate(string value, int maxChars)
193+
{
194+
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
195+
}
196+
}
197+
198+
}

Assets/UXF/Scripts/Etc/Editor/UXFSessionDisplay.cs.meta

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

Assets/UXF/Scripts/SessionDebugger.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace UXF
1111
/// Component which assists in debugging session structure.
1212
/// </summary>
1313
[ExecuteInEditMode]
14+
[System.Obsolete("Component is obsolete. Use the new Session Debugger editor tool.")]
1415
public class SessionDebugger : MonoBehaviour
1516
{
1617
[InspectorButton("DisplaySessionProtocol")]

0 commit comments

Comments
 (0)