diff --git a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs index 81f1b5c0b3e5c2e0cb649455f9edb902dd4a246c..225150034aedf5bb94f7b1c4b21b6f5b2017edd8 100644 --- a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs +++ b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs @@ -4,6 +4,8 @@ using System.IO; using System.Linq; using UnityEngine; using System.Threading.Tasks; +using Newtonsoft.Json; + #if UNITY_EDITOR using UnityEditor; @@ -278,7 +280,9 @@ namespace TeachR.ApplicationManager /// <returns>The script info list as Json.</returns> public string GetScriptInfoListAsJson() { - return JsonUtility.ToJson(new { scripts = scriptInfoList }, true); + string json = JsonConvert.SerializeObject(scriptInfoList, Formatting.Indented); + Debug.Log($"[Data] Sending scriptInfoList JSON: {json}"); + return json; } /// <summary> diff --git a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/ScriptInfo.cs b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/ScriptInfo.cs index db747a96667914a24e5415b57b340ac4129dd55e..091d28ed470ec4fe95f5555de0ed13bd80314c6b 100644 --- a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/ScriptInfo.cs +++ b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/ScriptInfo.cs @@ -1,3 +1,4 @@ +using Newtonsoft.Json; using System; using System.Collections.Generic; using UnityEngine; @@ -17,36 +18,42 @@ namespace TeachR.ApplicationManager public string scriptName; public string scriptAlias; [SerializeField] private bool _logScript; - private bool _scriptAvailable; - public bool scriptAvailable + + public bool logScript { - get => _scriptAvailable; + get => _logScript; set { - if (_scriptAvailable != value) + if (_logScript != value) { - _scriptAvailable = value; + _logScript = value; + OnLogScriptChanged?.Invoke(value, this); OnParameterChanged?.Invoke(this); } } } - public bool logScript + [SerializeField] private bool _scriptAvailable; + public bool scriptAvailable { - get => _logScript; + get => _scriptAvailable; set { - if (_logScript != value) + if (_scriptAvailable != value) { - _logScript = value; - OnLogScriptChanged?.Invoke(value, this); + _scriptAvailable = value; OnParameterChanged?.Invoke(this); } } } - public Action<bool, ScriptInfo> OnLogScriptChanged; - public Action<ScriptInfo> OnParameterChanged; + [JsonIgnore] public Action<bool, ScriptInfo> OnLogScriptChanged; + [JsonIgnore] public Action<ScriptInfo> OnParameterChanged; + + public void SetLogValueByWebsite(bool value) + { + _logScript = value; + } /// <summary> /// Used to send the scriptInfo to website @@ -54,7 +61,7 @@ namespace TeachR.ApplicationManager /// <returns>The script info as Json.</returns> public string GetScriptInfoAsJson() { - return JsonUtility.ToJson(new { scriptName = scriptName, scriptAlias = scriptAlias, logScript = logScript, scriptAvailable = scriptAvailable }, true); + return JsonConvert.SerializeObject(new { scriptAlias = this.scriptAlias, logScript = this.logScript }); } } } diff --git a/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs b/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs index 74b908198f72e006ad620208257ba3c58a84725f..38929c886f5d4a5d4e7714ec3030c367258ce319 100644 --- a/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs +++ b/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs @@ -54,7 +54,8 @@ namespace TeachR.WebCommunication WebsocketDelegateHooks.OnFixedUpdate += RunEventLoop; RegisterFunctionCheckResultHandler(HandleFunctionCheckResult); - RegisterScriptInfoListRequestHandler(HandleScriptInfoListRequest); + RegisterScriptInfoListHandler(HandleScriptInfoListRequest); + RegisterDataCollectionHandler(HandleManageScriptInfo); EventLogger.Instance.OnScriptInfoListChanged += HandleScriptInfoListEntryChanged; return Task.CompletedTask; @@ -86,10 +87,14 @@ namespace TeachR.WebCommunication Persistent.On("functionCheckResult", handler); } - private static void RegisterScriptInfoListRequestHandler(Action<JsonMsg> handler) + private static void RegisterScriptInfoListHandler(Action<JsonMsg> handler) { Persistent.On("requestScriptInfoList", handler); - Debug.Log("requestScriptInfoList bereit zum Empfang"); + } + + private static void RegisterDataCollectionHandler(Action<JsonMsg> handler) + { + Persistent.On("manageScriptInfo", handler); } private static void HandleFunctionCheckResult(JsonMsg msg) @@ -99,9 +104,32 @@ namespace TeachR.WebCommunication private static void HandleScriptInfoListRequest(JsonMsg msg) { - Send("sendScriptInfoList", EventLogger.Instance.GetScriptInfoListAsJson()); + var infoList = EventLogger.Instance.GetScriptInfoListAsJson(); + Send("sendScriptInfoList", infoList); EventLogger.Instance.AddEventListenerAfterConnection(); - Debug.Log("HandleScriptInfoListRequest löst send aus"); + } + + private static void HandleManageScriptInfo(JsonMsg msg) + { + var data = msg.GetValue<Dictionary<string, object>>(); + + string scriptAlias = data["scriptAlias"].ToString(); + bool logValue = Convert.ToBoolean(data["logValue"]); + + foreach (var scriptInfo in EventLogger.Instance.scriptInfoList) + { + if (scriptInfo.scriptAlias == scriptAlias) + { + scriptInfo.SetLogValueByWebsite(logValue); + } + } + } + + private static void HandleScriptInfoListEntryChanged(ScriptInfo scriptInfo) + { + var info = scriptInfo.GetScriptInfoAsJson(); + Send("updateScriptInfoEntry", info); + Debug.Log($"[DATA] update script Info entry: {info}"); } /// <summary> @@ -132,12 +160,6 @@ namespace TeachR.WebCommunication } } - private static void HandleScriptInfoListEntryChanged(ScriptInfo scriptInfo) - { - Send("sendScriptInfoList", scriptInfo.GetScriptInfoAsJson()); - Debug.Log($"[DATA] send script Info entry: {scriptInfo.GetScriptInfoAsJson()}"); - } - /// <summary> /// Converts parameters into a valid message to send to the frontend. The messages are probably /// sent from website-control\src\features\behaviourControls\behaviourGroups\BehaviourManagement\SendBehaviour.jsx . @@ -182,10 +204,10 @@ namespace TeachR.WebCommunication { Debug.Log($"[DEBUG] received speechtool parameters: {arg2}"); } - else if (arg1.Equals("requestScriptInfoList")) - { - Debug.Log($"[DEBUG] received requestScriptInfoList : {arg2}"); - } + //else if (arg1.Equals("requestScriptInfoList")) + //{ + // Debug.Log($"[DEBUG] received requestScriptInfoList : {arg2}"); + //} } private static void RunEventLoop()