Skip to content

Commit

Permalink
fix: application now boots on android
Browse files Browse the repository at this point in the history
Fixed: application now boots on android phone
Made: support for json arguments
fix: include error on Android
fix: inputTracing now works on android

inputTracing now works on android

Update CmdArgsReader.cs
  • Loading branch information
JoachimBose committed Aug 21, 2024
1 parent abce2e0 commit 557464a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
32 changes: 30 additions & 2 deletions Runtime/Configuration/CmdArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand All @@ -37,15 +51,29 @@ private static string[] GetCommandlineArgs()
else
{
// Otherwise, use arguments in editor MonoBehaviour
args = editorArgs.editorArgs.Split(' ');
//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<TextAsset>(argjsonFileName);
Debug.Log($"[CONFIG:] Found arg json: {jsonTxt}");
CmdArgsJson argsObj = JsonConvert.DeserializeObject<CmdArgsJson>(jsonTxt.text);
Debug.Log($"[CONFIG:] Found args: {argsObj.args}");
return argsObj.args;
}

public static bool ParseCmdArgs()
{
var arguments = GetCommandlineArgs();
Expand Down
39 changes: 17 additions & 22 deletions Runtime/Configuration/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,26 @@ static bool TryParseJsonFileArgument<T>(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<T>(text);
argumentValue = JsonConvert.DeserializeObject<T>(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<TextAsset>(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<T>(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<T>(text);
Expand All @@ -298,7 +293,7 @@ static bool TryParseJsonFileArgument<T>(string[] arguments, string argumentName,
result = false;
argumentValue = null;
return result;
}*/
}

static bool TryParseFilePathArgument(string[] arguments, string argumentName, out string argumentValue, string def)
{
Expand Down
14 changes: 13 additions & 1 deletion Runtime/Player/Emulation/InputRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TextAsset>(fileName);
Stream inputTraceStream = new MemoryStream(ta.bytes);
m_EventTrace.ReadFrom(inputTraceStream);
}
else
{
m_EventTrace.ReadFrom(fileName);
}
}

public void SaveCaptureToFile(string fileName)
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Statistics/StatisticsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace PolkaDOTS.Statistics
[UniqueSystem]
public partial struct StatisticsSystem : ISystem
{
#if UNITY_EDITOR || NETCODE_DEBUG
public void OnCreate(ref SystemState state)
{

Expand Down Expand Up @@ -73,6 +73,7 @@ public void OnUpdate(ref SystemState state)
}

}
#endif
}

/// <summary>
Expand Down

0 comments on commit 557464a

Please sign in to comment.