-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
5,081 additions
and
2,827 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 44 additions & 2 deletions
46
...y/Assets/Maroon/GlobalEntities/WebGLUrlParameterReader/Scripts/WebGLUrlParameterReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
using UnityEngine; | ||
using System.Runtime.InteropServices; | ||
using System.Collections.Generic; | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Maroon | ||
{ | ||
public class WebGLUrlParameterReader : MonoBehaviour | ||
public enum WebGlUrlParameter | ||
{ | ||
LoadScene, | ||
Config, | ||
} | ||
public class WebGlUrlParameterReader : MonoBehaviour | ||
{ | ||
// JS implementation at Plugins/WebGLUrlParameterReader.jslib | ||
[DllImport("__Internal")] | ||
public static extern string GetUrlParameter(string urlParameterName); | ||
private static extern string _getUrlParameter(string urlParameterName); | ||
[DllImport("__Internal")] | ||
private static extern IntPtr _getAllUrlParameters(); | ||
|
||
[Obsolete("GetUrlParameter is deprecated due to case-sensitivity. Use 'BootstrappingManager.UrlParameters' instead.")] | ||
public static string GetUrlParameter(WebGlUrlParameter urlParameter) | ||
{ | ||
return GetAllUrlParameters().TryGetValue(urlParameter, out string value) ? value : null; | ||
} | ||
|
||
public static Dictionary<WebGlUrlParameter, string> GetAllUrlParameters() | ||
{ | ||
// rawJson = {"LoadScene":"Optics","Config":"Default"} | ||
var rawJson = Marshal.PtrToStringAnsi(_getAllUrlParameters()); | ||
var stringKeyedValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson); | ||
|
||
var enumKeyedValues = new Dictionary<WebGlUrlParameter, string>(); | ||
|
||
foreach (var kvp in stringKeyedValues) | ||
{ | ||
// TODO: ignore case sensitivity of enums | ||
// Enum consists of LoadScene and Config | ||
if (Enum.TryParse(kvp.Key, true, out WebGlUrlParameter parsedEnum)) | ||
{ | ||
enumKeyedValues[parsedEnum] = kvp.Value; | ||
} | ||
else | ||
{ | ||
// Handle the case where the key cannot be parsed into an enum | ||
Debug.LogWarning($"Key '{kvp.Key}' does not exist in WebGlUrlParameter enum and will be ignored."); | ||
} | ||
} | ||
|
||
return enumKeyedValues; | ||
} | ||
} | ||
} |
Oops, something went wrong.