Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: application now boots on android #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion 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 @@ -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<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
11 changes: 9 additions & 2 deletions Runtime/Statistics/StatisticsWriterInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down