diff --git a/Runtime/Configuration/CmdArgsReader.cs b/Runtime/Configuration/CmdArgsReader.cs index 25d53d1..1f2229a 100644 --- a/Runtime/Configuration/CmdArgsReader.cs +++ b/Runtime/Configuration/CmdArgsReader.cs @@ -9,6 +9,10 @@ using UnityEngine; using WebSocketSharp; using Random = UnityEngine.Random; +using System.IO; +#if PLATFORM_ANDROID +using UnityEngine.Android; +#endif #if UNITY_EDITOR using ParrelSync; @@ -19,9 +23,19 @@ namespace PolkaDOTS.Configuration { public static class CmdArgsReader { + [Serializable] + private class CmdArgsJson + { + public string[] args = new string[0]; + } #if UNITY_EDITOR private static EditorCmdArgs editorArgs; + #endif + + [SerializeField] + private static string argjsonFileName = "cmdArgs"; + // Returns the string array of cmd line arguments from environment, ParrelSync, or an editor GameObject private static string[] GetCommandlineArgs() { @@ -38,14 +52,28 @@ private static string[] GetCommandlineArgs() { // Otherwise, use arguments in editor MonoBehaviour args = editorArgs.editorArgs.Split(' '); + //args = getArgsFromJson(); } #else // Read from normal command line application arguments args = Environment.GetCommandLineArgs(); + if(args.Length == 1){ + args = getArgsFromJson(); + } #endif + Debug.Log($"running with arguments: {args.ToString()}"); return args; } - + + private static string[] getArgsFromJson() + { + TextAsset jsonTxt = Resources.Load(argjsonFileName); + Debug.Log($"[CONFIG:] Found arg json: {jsonTxt}"); + CmdArgsJson argsObj = JsonConvert.DeserializeObject(jsonTxt.text); + Debug.Log($"[CONFIG:] Found args: {argsObj.args}"); + return argsObj.args; + } + public static bool ParseCmdArgs() { var arguments = GetCommandlineArgs(); diff --git a/Runtime/Configuration/ConfigParser.cs b/Runtime/Configuration/ConfigParser.cs index e55cd6b..f8cbe00 100644 --- a/Runtime/Configuration/ConfigParser.cs +++ b/Runtime/Configuration/ConfigParser.cs @@ -258,31 +258,26 @@ static bool TryParseJsonFileArgument(string[] arguments, string argumentName, bool result = TryParseFilePathArgument(arguments, argumentName, out string value, ""); if (result && !string.IsNullOrEmpty(value)) { - string text = File.ReadAllText(value); - try + string text = ""; + if (File.Exists(value)) { - //argumentValue = JsonUtility.FromJson(text); - argumentValue = JsonConvert.DeserializeObject(text); - return true; + text = File.ReadAllText(value); } - catch (Exception) + else //If file operation fails, attempt to load it from resources { - result = false; + Debug.LogWarning($"[CONFIG] json argument file {value} not found, attempting to load from Assets/Resources/{value}"); + TextAsset jsonTxt = Resources.Load(value); + if (jsonTxt != null) + { + text = jsonTxt.text; + Debug.Log($"[CONFIG]json arg found in resources!"); + } + else + { + Debug.LogError($"[CONFIG] jsonargument not {value} found"); + } } - } - else if (required) - result = false; - argumentValue = null; - return result; - } - - /*static bool TryParseJsonFileArgumentClass(string[] arguments, string argumentName, out T argumentValue, - bool required = false) where T : class - { - bool result = TryParseFilePathArgument(arguments, argumentName, out string value); - if (result && !string.IsNullOrEmpty(value)) - { - string text = File.ReadAllText(value); + try { //argumentValue = JsonUtility.FromJson(text); @@ -298,7 +293,7 @@ static bool TryParseJsonFileArgument(string[] arguments, string argumentName, result = false; argumentValue = null; return result; - }*/ + } static bool TryParseFilePathArgument(string[] arguments, string argumentName, out string argumentValue, string def) { diff --git a/Runtime/Player/Emulation/InputRecorder.cs b/Runtime/Player/Emulation/InputRecorder.cs index cc8b74b..b40a101 100644 --- a/Runtime/Player/Emulation/InputRecorder.cs +++ b/Runtime/Player/Emulation/InputRecorder.cs @@ -4,6 +4,7 @@ using UnityEngine.InputSystem; using UnityEngine.InputSystem.Layouts; using UnityEngine.InputSystem.LowLevel; +using System.IO; // from InputSystem package Input Recorder Sample namespace PolkaDOTS.Emulation @@ -281,9 +282,20 @@ public void LoadCaptureFromFile(string fileName) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(nameof(fileName)); + CreateEventTrace(); - m_EventTrace.ReadFrom(fileName); + + if (!File.Exists(fileName)) + { + TextAsset ta = Resources.Load(fileName); + Stream inputTraceStream = new MemoryStream(ta.bytes); + m_EventTrace.ReadFrom(inputTraceStream); + } + else + { + m_EventTrace.ReadFrom(fileName); + } } public void SaveCaptureToFile(string fileName) diff --git a/Runtime/Statistics/StatisticsSystem.cs b/Runtime/Statistics/StatisticsSystem.cs index f82027b..51eaae6 100644 --- a/Runtime/Statistics/StatisticsSystem.cs +++ b/Runtime/Statistics/StatisticsSystem.cs @@ -16,7 +16,7 @@ namespace PolkaDOTS.Statistics [UniqueSystem] public partial struct StatisticsSystem : ISystem { - +#if UNITY_EDITOR || NETCODE_DEBUG public void OnCreate(ref SystemState state) { @@ -73,6 +73,7 @@ public void OnUpdate(ref SystemState state) } } +#endif } /// diff --git a/Runtime/Statistics/StatisticsWriterInstance.cs b/Runtime/Statistics/StatisticsWriterInstance.cs index 26b1334..20bb1bd 100644 --- a/Runtime/Statistics/StatisticsWriterInstance.cs +++ b/Runtime/Statistics/StatisticsWriterInstance.cs @@ -123,8 +123,15 @@ public void Update() foreach (var (_, rec) in recorders) sb.Append($"{rec.LastValue.ToString()};"); sb.Append("\n"); - metricsBuffer += sb.ToString(); - +#if PLATFORM_ANDROID || UNITY_EDITOR + if(ApplicationConfig.LogStats) + { + Debug.Log($"[STATISTIC]{sb.ToString()}"); + } +#else + metricsBuffer += sb.ToString(); +#endif + } public void WriteStatisticsBuffer()