Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
Unity jslib import in c# script don't work?

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda