Skip to content

Commit 6ab5845

Browse files
committed
#53 and tidied up Log calls
1 parent bdcdf31 commit 6ab5845

14 files changed

+87
-48
lines changed

Assets/UXF/Prefabs/[UXF_Rig].prefab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ MonoBehaviour:
9393
m_Script: {fileID: 11500000, guid: 325d8bc56dfbdf4439627ee58ed3a5a4, type: 3}
9494
m_Name:
9595
m_EditorClassIdentifier:
96+
setAsMainInstance: 1
97+
logDebugLogCalls: 1
9698
--- !u!1 &64655937078549661
9799
GameObject:
98100
m_ObjectHideFlags: 0

Assets/UXF/Scripts/DataHandling/FileSaver.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override void SetUp()
5555
}
5656
else
5757
{
58-
Debug.LogWarning("Parallel thread is still active!");
58+
Utilities.UXFDebugLogWarning("Parallel thread is still active!");
5959
}
6060
}
6161

@@ -84,13 +84,13 @@ public void ManageInWorker(System.Action action)
8484
void Worker()
8585
{
8686
if (verboseDebug)
87-
Debug.Log("Started worker thread");
87+
Utilities.UXFDebugLog("Started worker thread");
8888

8989
// performs FileIO tasks in seperate thread
9090
foreach (var action in bq)
9191
{
9292
if (verboseDebug)
93-
Debug.LogFormat("Managing action");
93+
Utilities.UXFDebugLogFormat("Managing action");
9494

9595
try
9696
{
@@ -102,7 +102,7 @@ void Worker()
102102
}
103103
catch (IOException e)
104104
{
105-
Debug.LogError(string.Format("Error, file may be in use! Exception: {0}", e));
105+
Utilities.UXFDebugLogError(string.Format("Error, file may be in use! Exception: {0}", e));
106106
}
107107
catch (System.Exception e)
108108
{
@@ -115,7 +115,7 @@ void Worker()
115115
}
116116

117117
if (verboseDebug)
118-
Debug.Log("Finished worker thread");
118+
Utilities.UXFDebugLog("Finished worker thread");
119119
}
120120

121121
/// <summary>
@@ -143,7 +143,7 @@ public override string HandleDataTable(UXFDataTable table, string experiment, st
143143
Directory.CreateDirectory(directory);
144144
string savePath = Path.Combine(directory, string.Format("{0}.csv", dataName));
145145

146-
if (verboseDebug) Debug.LogFormat("Queuing save of file: {0}", savePath);
146+
if (verboseDebug) Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
147147

148148
ManageInWorker(() => { File.WriteAllLines(savePath, lines); });
149149
return GetRelativePath(storagePath, savePath);;
@@ -160,7 +160,7 @@ public override string HandleJSONSerializableObject(List<object> serializableObj
160160
Directory.CreateDirectory(directory);
161161
string savePath = Path.Combine(directory, string.Format("{0}.json", dataName));
162162

163-
if (verboseDebug) Debug.LogFormat("Queuing save of file: {0}", savePath);
163+
if (verboseDebug) Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
164164

165165
ManageInWorker(() => { File.WriteAllText(savePath, text); });
166166
return GetRelativePath(storagePath, savePath);;
@@ -177,7 +177,7 @@ public override string HandleJSONSerializableObject(Dictionary<string, object> s
177177
Directory.CreateDirectory(directory);
178178
string savePath = Path.Combine(directory, string.Format("{0}.json", dataName));
179179

180-
if (verboseDebug) Debug.LogFormat("Queuing save of file: {0}", savePath);
180+
if (verboseDebug) Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
181181

182182
ManageInWorker(() => { File.WriteAllText(savePath, text); });
183183
return GetRelativePath(storagePath, savePath);;
@@ -192,7 +192,7 @@ public override string HandleText(string text, string experiment, string ppid, i
192192
Directory.CreateDirectory(directory);
193193
string savePath = Path.Combine(directory, string.Format("{0}.txt", dataName));
194194

195-
if (verboseDebug) Debug.LogFormat("Queuing save of file: {0}", savePath);
195+
if (verboseDebug) Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
196196

197197
ManageInWorker(() => { File.WriteAllText(savePath, text); });
198198
return GetRelativePath(storagePath, savePath);;
@@ -207,7 +207,7 @@ public override string HandleBytes(byte[] bytes, string experiment, string ppid,
207207
Directory.CreateDirectory(directory);
208208
string savePath = Path.Combine(directory, string.Format("{0}.txt", dataName));
209209

210-
if (verboseDebug) Debug.LogFormat("Queuing save of file: {0}", savePath);
210+
if (verboseDebug) Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
211211

212212
ManageInWorker(() => { File.WriteAllBytes(savePath, bytes); });
213213
return GetRelativePath(storagePath, savePath);
@@ -221,7 +221,7 @@ public string GetSessionPath(string experiment, string ppid, int sessionNum)
221221
{
222222
storageLocationSafe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "UXF_Data");
223223
Directory.CreateDirectory(storageLocationSafe);
224-
Debug.LogErrorFormat("Selected storage location ({0}) does not exist! Defaulting to {1}.", base.storagePath, storageLocationSafe);
224+
Utilities.UXFDebugLogErrorFormat("Selected storage location ({0}) does not exist! Defaulting to {1}.", base.storagePath, storageLocationSafe);
225225
}
226226
return Path.Combine(storageLocationSafe, experiment, ppid, SessionNumToName(sessionNum));
227227
}
@@ -238,7 +238,7 @@ public static string SessionNumToName(int num)
238238
public override void CleanUp()
239239
{
240240
if (verboseDebug)
241-
Debug.Log("Joining File Saver Thread");
241+
Utilities.UXFDebugLog("Joining File Saver Thread");
242242
quitting = true;
243243
bq.Enqueue(doNothing); // ensures bq breaks from foreach loop
244244
parallelThread.Join();

Assets/UXF/Scripts/DataHandling/WebAWSDynamoDB.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override void SetUp()
6262
{
6363
bool ok = CheckCurrentTargetOK();
6464
if (!ok) return;
65-
if (credentials == null) Debug.LogError("Credentials have not been set!");
65+
if (credentials == null) Utilities.UXFDebugLogError("Credentials have not been set!");
6666
DDB_Setup(credentials.region, credentials.cognitoIdentityPool, gameObject.name);
6767

6868
var allDataTypes = Enum.GetValues(typeof(UXFDataType));
@@ -86,11 +86,10 @@ void AddBrowserInfo()
8686
if (!session.participantDetails.ContainsKey(kvp.Key))
8787
{
8888
session.participantDetails.Add(kvp.Key, kvp.Value);
89-
Debug.LogFormat("{0}: {1}", kvp.Key, kvp.Value);
9089
}
9190
else
9291
{
93-
Debug.LogErrorFormat("participantDetails already contains key \"{0}\"!", kvp.Key);
92+
Utilities.UXFDebugLogErrorFormat("participantDetails already contains key \"{0}\"!", kvp.Key);
9493
}
9594
}
9695
}
@@ -123,7 +122,7 @@ public override string HandleDataTable(UXFDataTable table, string experiment, st
123122

124123
if (!table.Headers.Contains("trial_num"))
125124
{
126-
Debug.LogError("Data supplied is supposed to be per-trial but does not contain 'trial_num' column!");
125+
Utilities.UXFDebugLogError("Data supplied is supposed to be per-trial but does not contain 'trial_num' column!");
127126
return "error";
128127
}
129128
var dataList = table.GetAsListOfDict()
@@ -347,12 +346,12 @@ public void GetCustomDataFromDB(string tableName, string primaryKeyName, object
347346

348347
private void ShowError(string text)
349348
{
350-
Debug.LogError(text);
349+
Utilities.UXFDebugLogError(text);
351350
}
352351

353352
private void HandleSuccessfulDBRead(string jsonResult)
354353
{
355-
Debug.Log(jsonResult);
354+
Utilities.UXFDebugLog(jsonResult);
356355
Dictionary<string, object> jsonRequest = (Dictionary<string, object>) MiniJSON.Json.Deserialize(jsonResult);
357356
string guid = (string) jsonRequest["guid"];
358357
Action<Dictionary<string, object>> callback = requestCallbackMap[guid];
@@ -408,9 +407,9 @@ private bool CheckCurrentTargetOK()
408407
var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
409408
if (buildTarget != UnityEditor.BuildTarget.WebGL)
410409
{
411-
Debug.LogError("Web AWS DynamoDB Data Handler is not compatible with current build target. Please switch your platform in Build Settings to WebGL if you wish to use this.");
410+
Utilities.UXFDebugLogError("Web AWS DynamoDB Data Handler is not compatible with current build target. Please switch your platform in Build Settings to WebGL if you wish to use this.");
412411
}
413-
Debug.LogWarning("Unfortunately the Web AWS DynamoDB Data Handler cannot communicate with the database whilst running in the Unity Editor, because it relies on the AWS JavaScript SDK. To test data upload, create a build of your application and test it in a web browser. You can still test in the Unity Editor without database access.");
412+
Utilities.UXFDebugLogWarning("Unfortunately the Web AWS DynamoDB Data Handler cannot communicate with the database whilst running in the Unity Editor, because it relies on the AWS JavaScript SDK. To test data upload, create a build of your application and test it in a web browser. You can still test in the Unity Editor without database access.");
414413
return false;
415414
# else
416415
return true;

Assets/UXF/Scripts/Etc/AWSCredentials.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public bool CheckIfValidFormat()
1818
{
1919
if (region == string.Empty)
2020
{
21-
Debug.LogError("Region in AWS Credentials is blank! Please supply your region (e.g. eu-west-2)");
21+
Utilities.UXFDebugLogError("Region in AWS Credentials is blank! Please supply your region (e.g. eu-west-2)");
2222
return false;
2323
}
2424
if (cognitoIdentityPool == string.Empty)
2525
{
26-
Debug.LogError("Cognito Identity Pool in AWS Credentials is blank! Please supply your Cognito Identity Pool (e.g. eu-west-2:00000000-0000-0000-0000-000000000000)");
26+
Utilities.UXFDebugLogError("Cognito Identity Pool in AWS Credentials is blank! Please supply your Cognito Identity Pool (e.g. eu-west-2:00000000-0000-0000-0000-000000000000)");
2727
return false;
2828
}
2929
return true;

Assets/UXF/Scripts/Etc/Editor/DataHandlerDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
4444
{
4545
var obj = new SerializedObject(property.objectReferenceValue);
4646
var prop = obj.FindProperty("active");
47-
if (EditorGUI.PropertyField(activeBox, prop, GUIContent.none)) Debug.Log("df");
47+
if (EditorGUI.PropertyField(activeBox, prop, GUIContent.none)) { }
4848
obj.ApplyModifiedProperties();
4949
name = dh.name;
5050
}

Assets/UXF/Scripts/Etc/Editor/UIControllerEditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,30 @@ public void HaltPlayIfUIIsInvalid(PlayModeStateChange state)
230230
{
231231
EditorApplication.isPlaying = false;
232232
string errorText = "Incompatibility Error: " + ppidReasonText;
233-
Debug.LogError(errorText);
233+
Utilities.UXFDebugLogError(errorText);
234234
}
235235

236236
string settingsReasonText;
237237
if (!uiController.SettingsModeIsValid(out settingsReasonText))
238238
{
239239
EditorApplication.isPlaying = false;
240240
string errorText = "Incompatibility Error: " + settingsReasonText;
241-
Debug.LogError(errorText);
241+
Utilities.UXFDebugLogError(errorText);
242242
}
243243

244244
string datapointsReasonText;
245245
if (!uiController.DatapointsAreValid(out datapointsReasonText))
246246
{
247247
EditorApplication.isPlaying = false;
248248
string errorText = "Incompatibility Error: " + datapointsReasonText;
249-
Debug.LogError(errorText);
249+
Utilities.UXFDebugLogError(errorText);
250250
}
251251

252252
string localPathStateReasonText;
253253
if (!uiController.LocalPathStateIsValid(out localPathStateReasonText))
254254
{
255255
string errorText = "Incompatibility Error: " + localPathStateReasonText;
256-
Debug.LogError(errorText);
256+
Utilities.UXFDebugLogError(errorText);
257257
}
258258
}
259259
}

Assets/UXF/Scripts/Etc/Editor/UXFBuildPreprocessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UXFBuildPreprocessor : IProcessSceneWithReport
2222
public void OnProcessScene(Scene scene, BuildReport report)
2323
{
2424
if (report == null) return;
25-
Debug.LogFormat("UXF is pre-processing your built scene '{0}' for platform '{1}' to make sure settings are compatible with the build... ", scene.name, report.summary.platform);
25+
Utilities.UXFDebugLogFormat("UXF is pre-processing your built scene '{0}' for platform '{1}' to make sure settings are compatible with the build... ", scene.name, report.summary.platform);
2626

2727
var uis = scene
2828
.GetRootGameObjects()
@@ -31,7 +31,7 @@ public void OnProcessScene(Scene scene, BuildReport report)
3131
if (report.summary.platform == BuildTarget.WebGL &&
3232
PlayerSettings.WebGL.template != "PROJECT:UXF WebGL")
3333
{
34-
Debug.LogWarning("The UXF WebGL template is not selected in WebGL player settings! This may lead to errors. You can fix the is with the UXF Wizard (press UXF at the top, Show UXF Wizard).");
34+
Utilities.UXFDebugLogWarning("The UXF WebGL template is not selected in WebGL player settings! This may lead to errors. You can fix the is with the UXF Wizard (press UXF at the top, Show UXF Wizard).");
3535
}
3636

3737
foreach (var ui in uis)
@@ -79,7 +79,7 @@ public void OnProcessScene(Scene scene, BuildReport report)
7979

8080
if (!compatible && !incompatible)
8181
{
82-
Debug.LogWarningFormat(
82+
Utilities.UXFDebugLogWarningFormat(
8383
"Warning: (Scene: {0}) - The data handler '{1}' has not reported either compatibility or incompatibility with platform group '{2}'. Use at your own risk!",
8484
scene.name,
8585
dh.name,

Assets/UXF/Scripts/Etc/Trial.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void Begin()
103103
}
104104
catch (NullReferenceException)
105105
{
106-
Debug.LogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
106+
Utilities.UXFDebugLogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
107107
}
108108
}
109109
session.onTrialBegin.Invoke(this);
@@ -137,7 +137,7 @@ public void End()
137137
}
138138
catch (NullReferenceException)
139139
{
140-
Debug.LogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
140+
Utilities.UXFDebugLogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
141141
}
142142
}
143143

@@ -154,7 +154,7 @@ public bool CheckDataTypeIsValid(string dataName, UXFDataType dataType)
154154
{
155155
if (dataType.GetDataLevel() != UXFDataLevel.PerTrial)
156156
{
157-
Debug.LogErrorFormat(
157+
Utilities.UXFDebugLogErrorFormat(
158158
"Error trying to save data '{0}' of type UXFDataType.{1} associated with the Trial. The valid types for this method are {2}. Reverting to type UXFDataType.OtherTrialData.",
159159
dataName,
160160
dataType,

Assets/UXF/Scripts/Etc/Utilities.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace UXF
6+
{
7+
/// <summary>
8+
/// Useful methods
9+
/// </summary>
10+
public static class Utilities
11+
{
12+
13+
public static void UXFDebugLog(string message) { Debug.Log(UXFFormatString(message)); }
14+
public static void UXFDebugLogWarning(string message) { Debug.LogWarning(UXFFormatString(message)); }
15+
public static void UXFDebugLogError(string message) { Debug.LogError(UXFFormatString(message)); }
16+
public static void UXFDebugLogFormat(string format, params object[] args) { Debug.LogFormat(UXFFormatString(format), args); }
17+
public static void UXFDebugLogWarningFormat(string format, params object[] args) { Debug.LogWarningFormat(UXFFormatString(format), args); }
18+
public static void UXFDebugLogErrorFormat(string format, params object[] args) { Debug.LogErrorFormat(UXFFormatString(format), args); }
19+
20+
21+
private static string UXFFormatString(string message) { return string.Format("[<b><color=#AD477C>UXF</color></b>] {0}", message); }
22+
23+
}
24+
25+
}

Assets/UXF/Scripts/Etc/Utilities.cs.meta

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

Assets/UXF/Scripts/Session.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ public void Begin(string experimentName, string participantId, int sessionNumber
314314
}
315315
_hasInitialised = true;
316316

317+
Utilities.UXFDebugLog("Beginning session.");
318+
317319
// raise the session events
318320
onSessionBegin.Invoke(this);
319321
}
@@ -509,7 +511,7 @@ public bool CheckDataTypeIsValid(string dataName, UXFDataType dataType)
509511
{
510512
if (dataType.GetDataLevel() != UXFDataLevel.PerSession)
511513
{
512-
Debug.LogErrorFormat(
514+
Utilities.UXFDebugLogErrorFormat(
513515
"Error trying to save data '{0}' of type UXFDataType.{1} associated with the Session. The valid types for this method are {2}. Reverting to type UXFDataType.OtherSessionData.",
514516
dataName,
515517
dataType,
@@ -657,7 +659,7 @@ public void End()
657659
blocks = new List<Block>();
658660
_hasInitialised = false;
659661

660-
Debug.Log("Ended session.");
662+
Utilities.UXFDebugLog("Ended session.");
661663
isEnding = false;
662664
}
663665
}

Assets/UXF/Scripts/UI/ExperimentProfileSelector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Populate(bool retry = true)
3939
{
4040
if (!Directory.Exists(Application.streamingAssetsPath))
4141
{
42-
Debug.LogWarning("StreamingAssets folder was moved or deleted! Creating a new one.");
42+
Utilities.UXFDebugLogWarning("StreamingAssets folder was moved or deleted! Creating a new one.");
4343
Directory.CreateDirectory(Application.streamingAssetsPath);
4444
}
4545

@@ -78,7 +78,7 @@ public void Populate(bool retry = true)
7878
if (!File.Exists(newPath))
7979
{
8080
File.WriteAllText(newPath, "{\n}");
81-
Debug.LogErrorFormat("No profiles found in {0} that match search pattern {1}. A blank one called {2} has been made for you.", Application.streamingAssetsPath, uiController.settingsSearchPattern, newName);
81+
Utilities.UXFDebugLogErrorFormat("No profiles found in {0} that match search pattern {1}. A blank one called {2} has been made for you.", Application.streamingAssetsPath, uiController.settingsSearchPattern, newName);
8282
if (retry) Populate(retry: false);
8383
}
8484
}
@@ -91,7 +91,7 @@ public void ShowFolder()
9191
string winPath = Application.streamingAssetsPath.Replace("/", "\\");
9292
System.Diagnostics.Process.Start("explorer.exe", "/root," + winPath);
9393
#else
94-
Debug.LogError("Cannot open directory unless on PC platform!");
94+
Utilities.UXFDebugLogError("Cannot open directory unless on PC platform!");
9595
#endif
9696
}
9797

0 commit comments

Comments
 (0)