Exemplo n.º 1
0
 public static IEnumerator DownloadPDF(Action callback, Action <string> callbackError)
 {
     DebugUnity.Log("Download PDF: " + GetStudy().pdf_url);
     Application.OpenURL(GetStudy().pdf_url);
     callback();
     yield return(null);
 }
Exemplo n.º 2
0
    public static IEnumerator DownloadOFF(Action callbackSuccess, Action <string> callbackError)
    {
        if (GetStudy().off_url == null)
        {
            Debug.LogError("OFF download url not valid: " + GetStudy().off_url);

            if (callbackError != null)
            {
                callbackError("OFF download url not valid");
            }
        }
        else
        {
            string downloadUrl = GetStudy().off_url;

            DebugUnity.Log("Start downloading OFF: " + downloadUrl);

            UnityWebRequest requestOff = UnityWebRequest.Get(GetStudy().off_url);

            yield return(requestOff.SendWebRequest());

            if (requestOff.isNetworkError || requestOff.isHttpError)
            {
                Debug.LogError("Downloading OFF error: " + requestOff.error);
            }
            else
            {
                DebugUnity.Log("OFF downloaded - " + (requestOff.downloadedBytes / 1024f / 1024f).ToString("0.0") + "MB");
                string fileString = System.Text.Encoding.UTF8.GetString(requestOff.downloadHandler.data);

                PointCloudManager.Instance.file = fileString;
                callbackSuccess();
            }
        }
    }
Exemplo n.º 3
0
    public static IEnumerator LoginRequest(string _usuario, string _password, Action callbackSuccess, Action <string> callbackError)
    {
        LoginInfo newLogin = new LoginInfo(_usuario);

        if (currentLogin.user != newLogin.user || (currentLogin.user == newLogin.user && !currentLogin.isLoggedIn))
        {
            DebugUnity.Log("Attempting Login for user: "******"...");


            WWWForm form = new WWWForm();
            form.AddField("email", _usuario);
            form.AddField("password", _password);

            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

            UnityWebRequest requestLogin = UnityWebRequest.Post(URL + "/login", form);

            //requestLogin.SetRequestHeader("Access-Control-Allow-Credentials","true");

            yield return(requestLogin.SendWebRequest());

            if (requestLogin.isNetworkError || requestLogin.isHttpError)
            {
                string msg = "";
                Debug.LogError("Login error: " + requestLogin.error);

                if (requestLogin.isNetworkError)
                {
                    msg = "Error de conexión con el servidor";
                }
                else
                {
                    msg = "Usuario o contraseña incorrecto";
                }

                if (callbackError != null)
                {
                    callbackError(msg);
                }
            }
            else
            {
                DebugUnity.Log("Login Successful!");
                DebugUnity.Log("Login response: " + requestLogin.downloadHandler.text);
                currentLogin            = JsonUtility.FromJson <LoginInfo>(requestLogin.downloadHandler.text);
                currentLogin.isLoggedIn = true;

                if (callbackSuccess != null)
                {
                    callbackSuccess();
                }
            }
        }
    }
Exemplo n.º 4
0
    public static IEnumerator RequestManagedCorporations(Action callback)
    {
        string strResponseValue = string.Empty;


        DebugUnity.Log("Requesting managed corporations...");
        ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

        UnityWebRequest corporationRequest = UnityWebRequest.Get(URL + "/search");

        corporationRequest.SetRequestHeader("token", currentLogin.token);
        corporationRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        //corporationRequest.SetRequestHeader("Access-Control-Allow-Credentials","true");

        DebugUnity.Log("Corporations test...");

        yield return(corporationRequest.SendWebRequest());

        if (corporationRequest.isNetworkError || corporationRequest.isHttpError)
        {
            Debug.LogError("Managed Corporations error: " + corporationRequest.error);
        }
        else
        {
            DebugUnity.Log("Managed Corporations Received!");

            strResponseValue = corporationRequest.downloadHandler.text;
            DebugUnity.Log("Corporations response:\n" + strResponseValue);


            managedCorporations = JsonUtility.FromJson <ManagedCorporations>(strResponseValue);

            if (DebugUnity.IsEditor)
            {
                string debugData = "Managed Corporations: " + managedCorporations.corporations.Length;

                foreach (Corporation corporation in managedCorporations.corporations)
                {
                    debugData += "\n\t- " + corporation.name;
                }
                DebugUnity.Log(debugData);
            }

            if (managedCorporations.corporations.Length > 0)
            {
                corporationIndex = 0;
            }
            else
            {
                corporationIndex = -1;
            }
        }
        callback();
    }
Exemplo n.º 5
0
    private IEnumerator LoadImage()
    {
        string url = null;

        if (TI_API.GetSubdependencie().images != null)
        {
            url = TI_API.GetSubdependencie().images[0].imageUrl;
        }

        if (url != null)
        {
            //WWWForm form = new WWWForm();
            //form.AddField("email", _usuario);
            //form.AddField("password", _password);
            UnityWebRequest img = UnityWebRequestTexture.GetTexture(url.ToString());

            //WWW img = new WWW(url);
            Debug.Log("Downloading Image");
            Debug.Log("URL: " + url.ToString());
            yield return(img.Send());

            if (img.isNetworkError || img.isHttpError)
            {
                string msg = "";
                Debug.LogError("Download error: " + img.error);

                if (img.isNetworkError)
                {
                    msg = "Error de conexión con el servidor";
                }
            }
            else
            {
                DebugUnity.Log("Scale Download Successful!");
                DebugUnity.Log("Scale response: " + img.downloadHandler.text);
            }


            Debug.Log(img.downloadedBytes);
            Debug.Log(img.downloadedBytes.ToString());
            //Texture a = new Texture();

            DownloadHandlerTexture handler = (DownloadHandlerTexture)img.downloadHandler;
            Sprite sprt = Sprite.Create(handler.texture, new Rect(0, 0, handler.texture.width, handler.texture.height), new Vector2(0.5f, 0.5f));
            scaleView.sprite = sprt;
            scaleView.gameObject.SetActive(true);
        }
        else
        {
            Debug.LogWarning("No image attached");
            scaleView.gameObject.SetActive(false);
            yield return(null);
        }
    }
Exemplo n.º 6
0
    public override void CargarLista(int id)
    {
        base.CargarLista(id);

        DebugUnity.Log("Load Corporations.");

        for (int i = 0; i < TI_API.CorporationsCount; i++)
        {
            AddBoton(TI_API.GetCorporation(i).name, i);
        }
    }
Exemplo n.º 7
0
    public override void CargarLista(int id)
    {
        base.CargarLista(id);

        Enterprise enterprise = TI_API.GetEnterprise(myIndex);

        DebugUnity.Log("Load dependencie: [" + myIndex + "] " + enterprise.name);

        if (enterprise.dependencies != null)
        {
            for (int i = 0; i < enterprise.dependencies.Length; i++)
            {
                AddBoton(enterprise.dependencies[i].name, i);
            }
        }
    }
Exemplo n.º 8
0
    public override void CargarLista(int id)
    {
        base.CargarLista(id);

        Corporation corporation = TI_API.GetCorporation(myIndex);

        DebugUnity.Log("Load Enterprises: [" + myIndex + "] " + corporation.name);

        if (corporation.enterprises != null)
        {
            for (int i = 0; i < corporation.enterprises.Length; i++)
            {
                AddBoton(corporation.enterprises[i].name, i);
            }
        }
    }
Exemplo n.º 9
0
    public override void CargarLista(int id)
    {
        base.CargarLista(id);

        Subdependencie subdependencie = TI_API.GetSubdependencie(myIndex);

        DebugUnity.Log("Load Studies: [" + myIndex + "] " + subdependencie.name);

        if (subdependencie.studies != null)
        {
            for (int i = 0; i < subdependencie.studies.Length; i++)
            {
                ElementoLista el = AddBoton(subdependencie.studies[i].name + " " + subdependencie.studies[i].date + (!string.IsNullOrEmpty(subdependencie.studies[i].off_url) ? " (Scan)" : "") + (!string.IsNullOrEmpty(subdependencie.studies[i].pdf_url) ? " (PDF)" : ""), i);

                el.elegirEntregable = elegirEntregable;
            }
        }
    }
Exemplo n.º 10
0
    public override void CargarLista(int id)
    {
        base.CargarLista(id);

        Dependencie dependencie = TI_API.GetDependencie(myIndex);

        DebugUnity.Log("Load Subdependencie: [" + myIndex + "] " + dependencie.name);

        if (dependencie.subdependencies != null)
        {
            for (int i = 0; i < dependencie.subdependencies.Length; i++)
            {
                int a = dependencie.subdependencies[i].studies != null ? dependencie.subdependencies[i].studies.Length : 0;

                AddBoton(dependencie.subdependencies[i].name, i);
            }
        }
    }
Exemplo n.º 11
0
    // Start Coroutine of reading the points from the OFF file and creating the meshes
    IEnumerator LoadOFF()
    {
        DebugUnity.Log(file);
        StringReader sr = new StringReader(file);

        sr.ReadLine();         // OFF
        string firstLine = sr.ReadLine().Replace("# ", "");

        string[] buffer = firstLine.Split(); // nPoints, nFaces
        //Debug.Log("\"" + buffer[0] + "\"");
        numPoints = int.Parse(buffer[0]);
        points    = new Vector3[numPoints];
        widths    = new float[numPoints];
        pointsDir = new Quaternion[numPoints];

        colors   = new Color[numPoints];
        minValue = new Vector3();

        for (int i = 0; i < numPoints; i++)
        {
            buffer = sr.ReadLine().Split();

            if (!invertYZ)
            {
                points[i] = new Vector3(float.Parse(buffer[0]) - 1.9f, float.Parse(buffer[1]), float.Parse(buffer[2]));
            }
            else
            {
                points[i] = new Vector3(float.Parse(buffer[0]) - 1.9f, float.Parse(buffer[2]), float.Parse(buffer[1]));
            }

            if (buffer.Length >= 6)
            {
                colors[i] = new Color(int.Parse(buffer[3]) / 255.0f, int.Parse(buffer[4]) / 255.0f, int.Parse(buffer[5]) / 255.0f);
            }
            else
            {
                colors[i] = Color.cyan;
            }

            if (points[i].magnitude > maxLenght)
            {
                maxLenght = points[i].magnitude;
            }

            if (buffer.Length >= 7)
            {
                widths[i] = float.Parse(buffer[6]);                // / 100f;
            }
            else
            {
                widths[i] = 0f;
            }

            pointsDir[i].w = i;


            // GUI
            if (i % Mathf.FloorToInt(numPoints / 20) == 0)
            {
                loadingBar.Show("Cargando Puntos", (i * 1f) / numPoints);
                yield return(null);
            }
        }
        loadingBar.Hide();

        //Scale and recenter
        yield return(StartCoroutine(ReshapePoints()));

        yield return(StartCoroutine(OrderPoints()));

        // Instantiate Point Groups
        numPointGroups = Mathf.CeilToInt(numPoints * 1.0f / limitPoints * 1.0f);

        pointCloud = new GameObject("OFF");

        for (int i = 0; i < numPointGroups - 1; i++)
        {
            InstantiateMesh(i, limitPoints);

            if (i % 10 == 0)
            {
                loadingBar.Show("Generando Malla", (i * 1f) / numPoints);
                yield return(null);
            }
        }
        loadingBar.Hide();

        InstantiateMesh(numPointGroups - 1, numPoints - (numPointGroups - 1) * limitPoints);
        //pointCloud.transform.LookAt(pointCloud.transform.position + Vector3.up);
        //Store PointCloud
        //UnityEditor.PrefabUtility.CreatePrefab ("Assets/Resources/PointCloudMeshes/" + filename + ".prefab", pointCloud);

        //pointCloud.transform.rotation = Quaternion.Euler(90f, 0f, 0f) * Quaternion.identity;

        loaded = true;
    }