I started using jslib plugins with unity and following the documentation I created this jslib file:
var plugin = {
Autologin: function () {
var sessionData = [
sessionStorage.getItem("USERNAME"),
sessionStorage.getItem("PASSWORD")
];
return sessionData;
},
GetTargetParams: function () {
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
return findGetParameter("platform");
},
};
mergeInto(LibraryManager.library, plugin);
I use the jslib functions in the c# file like that:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.UIElements;
using UnityEngine.SceneManagement;
using System;
using System.Runtime.InteropServices;
public class InitHandler : MonoBehaviour
{
public bool isMobile = false;
[DllImport("__Internal")]
private static extern string[] Autologin();
[DllImport("__Internal")]
private static extern string GetTargetParams();
// Start is called before the first frame update
void Start()
{
try
{
switch (GetTargetParams())
{
case "mobile":
isMobile = true;
break;
case "pc":
isMobile = false;
break;
}
}
catch { Debug.LogWarning("Target checking will not be executed cause it's not a webgl build."); }
try
{
StartCoroutine(StartAUTOLogin(Autologin()[0], Autologin()[1]));
}
catch { Debug.LogWarning("Autologin will not be executed cause it's not a webgl build."); }
SceneManager.LoadScene("Login");
}
// Update is called once per frame
void Update()
{
}
IEnumerator StartAUTOLogin(string User, string Password)
{
WWWForm form = new WWWForm();
form.AddField("Username", User);
form.AddField("Password", Password);
}
}
When I build this i don't get ANY compiler errors. My question is now why the functions I import don't work in a webgl build. So when I pass the parameter platform=mobile it's not setting isMobile to true. I'm beginner with jslibs so don't be hard please and don't critisize my english. I'm not native speaker.
Hope you can help me, Franz Fischer