Example #1
0
 /// <summary>
 /// Change the canvas scale and store the value in the persistent PlayerPrefs
 /// </summary>
 /// <param name="scaleFactor"></param>
 public void ChangeCanvasScale(float scaleFactor)
 {
     canvasScale = scaleFactor;
     canvasScaler.scaleFactor = canvasScale;
     PlayerPrefs.SetFloat(canvasScaleFactorKey, canvasScale);
     JavascriptMethodCaller.SetInterfaceScale(canvasScale);
 }
Example #2
0
 /// <summary>
 /// Scale up the canvas when we have a screen width high DPI like a 4k monitor or ultrawide.
 /// Do not go all the way up to 2x, but it is allowed through the settings menu.
 /// </summary>
 public float DetectPreferedCanvasScale()
 {
     canvasScale = Mathf.Clamp(Screen.width / referenceWidth, 1.0f, maxAutoWidth);
     canvasScaler.scaleFactor = canvasScale;
     JavascriptMethodCaller.SetInterfaceScale(canvasScale);
     return(canvasScale);
 }
Example #3
0
        private void OpenURLByGameObjectName()
        {
            var httpPosition = gameObject.name.IndexOf("http");
            var url          = gameObject.name.Substring(httpPosition, gameObject.name.Length - httpPosition);

            JavascriptMethodCaller.OpenURL(url);

            //Make sure to release everything manually (release event is blocked by our new browser window)
            EventSystem.current.SetSelectedGameObject(null);
        }
Example #4
0
    public void Save()
    {
#if UNITY_EDITOR
        var mydocs = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
        dxfDocument.Save(Path.Combine(mydocs, "testDXFBinary.dxf"), true);
        return;
#endif
        using (var stream = new MemoryStream())
        {
            if (dxfDocument.Save(stream))
            {
                JavascriptMethodCaller.DownloadByteArrayAsFile(stream.ToArray(), stream.ToArray().Length, "testfile.dxf");
            }
            else
            {
                Debug.Log("cant write file");
            }
        }
    }
    public void Save(string filename = "")
    {
#if UNITY_EDITOR
        var mydocs = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
        File.WriteAllText(Path.Combine(mydocs, (filename != "") ? filename : "ColladaExport.dae"), stringWriter.ToString());
        stringWriter = null;
        writer       = null;
        return;
#endif

        if (stringWriter != null)
        {
            byte[] byteArray = Encoding.UTF8.GetBytes(stringWriter.ToString());
            stringWriter = null;
            writer       = null;
            JavascriptMethodCaller.DownloadByteArrayAsFile(byteArray, byteArray.Length, (filename != "") ? filename : "ColladaExport.dae");
        }
        else
        {
            Debug.Log("cant write file");
        }
    }
        /// <summary>
        /// Start the parsing of OBJ and MTL strings
        /// </summary>
        /// <param name="objText">The OBJ string data</param>
        /// <param name="mtlText">The MTL string data</param>
        /// <returns></returns>
        private IEnumerator ParseOBJFromString(string objText, string mtlText = "")
        {
            //Create a new gameobject that parses OBJ lines one by one
            var   newOBJLoader = new GameObject().AddComponent <ObjLoad>();
            float remainingLinesToParse;
            float totalLines;
            float percentage;

            //Parse the mtl file, filling our material library
            if (mtlText != "")
            {
                newOBJLoader.SetMaterialData(ref mtlText);
                remainingLinesToParse = newOBJLoader.ParseNextMtlLines(1);
                totalLines            = remainingLinesToParse;

                loadingObjScreen.ShowMessage("Materialen worden geladen...");
                while (remainingLinesToParse > 0)
                {
                    remainingLinesToParse = newOBJLoader.ParseNextMtlLines(maxLinesPerFrame);
                    percentage            = 1.0f - (remainingLinesToParse / totalLines);
                    loadingObjScreen.ProgressBar.Percentage(percentage / 100.0f);                   //Show first percent
                    yield return(null);
                }
            }

            //Parse the obj line by line
            newOBJLoader.SetGeometryData(ref objText);
            loadingObjScreen.ShowMessage("Objecten worden geladen...");

            var parsingSucceeded = true;

            remainingLinesToParse = newOBJLoader.ParseNextObjLines(1);
            totalLines            = remainingLinesToParse;
            while (remainingLinesToParse > 0)
            {
                remainingLinesToParse = newOBJLoader.ParseNextObjLines(maxLinesPerFrame);
                if (remainingLinesToParse == -1)
                {
                    //Failed to parse the line. Probably not a triangulated OBJ
                    parsingSucceeded = false;
                    JavascriptMethodCaller.Alert("Het is niet gelukt dit model te importeren.\nZorg dat de OBJ is opgeslagen met 'Triangulated' als instelling.");
                }
                else
                {
                    percentage = 1.0f - (remainingLinesToParse / totalLines);
                    loadingObjScreen.ProgressBar.SetMessage(Mathf.Round(percentage * 100.0f) + "%");
                    loadingObjScreen.ProgressBar.Percentage(percentage);
                }
                yield return(null);
            }
            if (parsingSucceeded)
            {
                newOBJLoader.Build(defaultLoadedObjectsMaterial);

                //Make interactable
                newOBJLoader.transform.localScale = new Vector3(1.0f, 1.0f, -1.0f);
                newOBJLoader.name = objModelName;
                newOBJLoader.gameObject.AddComponent <Transformable>();
                newOBJLoader.gameObject.AddComponent <MeshCollider>().sharedMesh = newOBJLoader.GetComponent <MeshFilter>().sharedMesh;
                newOBJLoader.gameObject.AddComponent <ClearMeshAndMaterialsOnDestroy>();
                customObjectPlacer.PlaceExistingObjectAtPointer(newOBJLoader.gameObject);
            }
            //hide panel and loading screen after loading
            loadingObjScreen.Hide();

            //Invoke done event
            doneLoadingModel.Invoke();

            //Remove this loader from finished object
            Destroy(newOBJLoader);
        }
 /// <summary>
 /// Start the parsing of the OBJ, fetching the obj and mtl strings from Javascript
 /// </summary>
 public void LoadOBJFromJavascript()
 {
     StartCoroutine(ParseOBJFromString(JavascriptMethodCaller.FetchOBJDataAsString(), JavascriptMethodCaller.FetchMTLDataAsString()));
 }
    public void LoadCSVFromJavascript()
    {
        var csv = JavascriptMethodCaller.FetchOBJDataAsString();

        ParseCsv(csv);
    }
Example #9
0
        /// <summary>
        /// The complete upload bar progress.
        /// </summary>
        private IEnumerator Share()
        {
            progressBar.SetMessage("Instellingen opslaan..");
            progressBar.Percentage(0.2f);

            ChangeState(SharingState.SHARING_SCENE);
            yield return(new WaitForEndOfFrame());

            var jsonScene = JsonUtility.ToJson(sceneSerializer.SerializeScene(editAllowToggle.isOn), true);
            //Post basic scene, and optionaly get unique tokens in return
            UnityWebRequest sceneSaveRequest = UnityWebRequest.Put(Config.activeConfiguration.sharingBaseURL + "customUpload.php", jsonScene);

            sceneSaveRequest.SetRequestHeader("Content-Type", "application/json");
            yield return(sceneSaveRequest.SendWebRequest());

            if (sceneSaveRequest.isNetworkError || sceneSaveRequest.isHttpError || !sceneSaveRequest.downloadHandler.text.StartsWith("{"))
            {
                ChangeState(SharingState.SERVER_PROBLEM);
                yield break;
            }
            else
            {
                //Check if we got some tokens for model upload, and download them 1 at a time.
                ServerReturn serverReturn = JsonUtility.FromJson <ServerReturn>(sceneSaveRequest.downloadHandler.text);
                sceneSerializer.sharedSceneId = serverReturn.sceneId;
                Debug.Log("Scene return: " + sceneSaveRequest.downloadHandler.text);

                if (serverReturn.modelUploadTokens.Length > 0)
                {
                    progressBar.SetMessage("Objecten opslaan..");
                    progressBar.Percentage(0.3f);
                    var currentModel = 0;
                    while (currentModel < serverReturn.modelUploadTokens.Length)
                    {
                        progressBar.SetMessage("Objecten opslaan.. " + (currentModel + 1) + "/" + serverReturn.modelUploadTokens.Length);
                        var jsonCustomObject = JsonUtility.ToJson(sceneSerializer.SerializeCustomObject(currentModel, serverReturn.sceneId, serverReturn.modelUploadTokens[currentModel].token), false);

                        UnityWebRequest modelSaveRequest = UnityWebRequest.Put(Config.activeConfiguration.sharingBaseURL + "customUpload.php?sceneId=" + serverReturn.sceneId + "&meshToken=" + serverReturn.modelUploadTokens[currentModel].token, jsonCustomObject);
                        modelSaveRequest.SetRequestHeader("Content-Type", "application/json");
                        yield return(modelSaveRequest.SendWebRequest());

                        if (modelSaveRequest.isNetworkError || modelSaveRequest.isHttpError)
                        {
                            ChangeState(SharingState.SERVER_PROBLEM);
                            yield break;
                        }
                        else
                        {
                            Debug.Log("Model return: " + modelSaveRequest.downloadHandler.text);
                            currentModel++;
                            var currentModelLoadPercentage = (float)currentModel / ((float)serverReturn.modelUploadTokens.Length);
                            progressBar.Percentage(0.3f + (0.7f * currentModelLoadPercentage));
                            yield return(new WaitForSeconds(0.2f));
                        }
                    }
                }

                //Make sure the progressbar shows 100% before jumping to the next state
                progressBar.Percentage(1.0f);
                yield return(new WaitForSeconds(0.1f));

                ChangeState(SharingState.SHOW_URL);
                Debug.Log(Config.activeConfiguration.sharingViewUrl + serverReturn.sceneId);
                JavascriptMethodCaller.ShowUniqueShareToken(true, serverReturn.sceneId);
                yield return(null);
            }
        }
Example #10
0
 private void OnDisable()
 {
     StopAllCoroutines();
     JavascriptMethodCaller.ShowUniqueShareToken(false);
 }