Ejemplo n.º 1
0
    void ExportFile()     // Create (Export) button has been hit (NOT wizard has been created!)
    {
        var ext = GlTF_Writer.binary ? "glb" : "gltf";

        path = EditorUtility.SaveFilePanel("Save glTF file as", savedPath, savedFile, ext);
        if (path.Length != 0)
        {
            if (presetAsset != null)
            {
                string psPath = AssetDatabase.GetAssetPath(presetAsset);
                if (psPath != null)
                {
                    psPath = psPath.Remove(0, "Assets".Length);
                    psPath = Application.dataPath + psPath;
                    preset.Load(psPath);
                }
            }
            exportOption.mFileName    = path;
            exportOption.mAnimation   = exportAnimation;
            exportOption.mCombineMesh = convertImages;
            exportOption.presetAsset  = preset;

            exporter.ExportCoroutine(exportOption);
        }
    }
Ejemplo n.º 2
0
        private void Export()
        {
            InitExportPath();
            string mExportPath           = Directory.GetParent(Application.dataPath).FullName + "/export";
            RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider();

            byte[] byteCsp = new byte[4];
            csp.GetBytes(byteCsp);
            string mParamName     = System.BitConverter.ToString(byteCsp).Replace("-", null);
            string exportFileName = Path.Combine(mExportPath, mParamName + ".gltf");

            void callBack(bool state, string msg)
            {
                _error = !state;
                if (state)
                {
                    _successMsg = msg;
                }
                else
                {
                    _errMsg = msg;
                }
            }

            _exporter.ExportCoroutine(exportFileName, null, _glb, true, true, false, callBack);
        }
Ejemplo n.º 3
0
        private void Export()
        {
            InitExportPath();
            string mExportPath = Directory.GetParent(Application.dataPath).FullName + "/export";
            //RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider();
            //byte[] byteCsp = new byte[4];
            //csp.GetBytes(byteCsp);
            //string mParamName = System.BitConverter.ToString(byteCsp).Replace("-", null);
            string mParamName     = Selection.objects[0].name;
            string exportFileName = Path.Combine(mExportPath, mParamName + ".gltf");
            var    callBack       = new System.Action <bool, string>((bool state, string msg) =>
            {
                _error = !state;
                if (state)
                {
                    _successMsg = msg;
                    string url  = string.Format("{0}?assetUrl={1}{2}.glb", webServer.Prefix, exportFileServer.Prefix, Selection.objects[0].name);
                    Process.Start(url);
                }
                else
                {
                    _errMsg = msg;
                }
            });

            _exporter.ExportCoroutine(exportFileName, null, _glb, true, true, false, callBack);
        }
Ejemplo n.º 4
0
    void OnGUI()
    {
        // Export path
        GUILayout.Label("Export Path", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        exportPath = EditorGUILayout.TextField(exportPath);
        if (GUILayout.Button("...", GUILayout.Width(48), GUILayout.Height(16)))
        {
            exportPath = EditorUtility.OpenFolderPanel("Export Path", exportPath, "");
        }
        GUILayout.EndHorizontal();

        GUILayout.Label("Options", EditorStyles.boldLabel);
        GUILayout.Space(5);
        GUILayout.BeginHorizontal();
        opt_exportAnimation = EditorGUILayout.Toggle("Export animation (beta)", opt_exportAnimation);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        bool enable = updateExporterStatus();

        if (enable)
        {
            GUI.color = blueColor;
        }
        else
        {
            GUI.color = greyColor;
        }

        GUI.enabled = enable;
        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button(status, GUILayout.Width(250), GUILayout.Height(40)))
        {
            if (!enable)
            {
                EditorUtility.DisplayDialog("Error", status, "Ok");
            }
            else
            {
                Transform[] transforms     = Selection.GetTransforms(SelectionMode.TopLevel);
                string      exportFileName = Path.Combine(exportPath, transforms[0].name + ".gltf");
                string      zipFileName    = Path.Combine(exportPath, transforms[0].name + ".zip");
                if (System.IO.File.Exists(zipFileName))
                {
                    System.IO.File.Delete(zipFileName);
                }

                exporter.ExportCoroutine(exportFileName, null, true, true, opt_exportAnimation, true);
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
    }
    void ExportScene()
    {
        Debug.Log("Exporting Scene...");

        Object[] previousSelection = Selection.objects;
        Selection.objects = sceneObjects;
        //preset.Load(activeScene.path);
        if (exportPath != string.Empty)
        {
            exporter.ExportCoroutine(exportPath, preset, false, true, true);
        }

        Selection.objects = previousSelection;
        Debug.Log(activeScene.path);
        Debug.Log("Exporting done");
    }
Ejemplo n.º 6
0
    void OnGUI()
    {
        path = EditorGUILayout.TextField("Output File", path);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Output File", GUILayout.Width(150), GUILayout.Height(40)))
        {
            // Hack to deal with the fact that its implemented
            // in a Coroutine.
            path = EditorUtility.SaveFilePanel("glTF Export Filename", "", "", "gltf");
        }

        EditorGUI.BeginDisabledGroup(path == String.Empty || path.EndsWith(".zip"));
        if (GUILayout.Button("Convert", GUILayout.Width(150), GUILayout.Height(40)))
        {
            Initialize();
            exporter.ExportCoroutine(path, null, true, true, false, true);
        }
        EditorGUI.EndDisabledGroup();
        GUILayout.EndHorizontal();
    }
Ejemplo n.º 7
0
    void OnGUI()
    {
        if (exporterLabel == null)
        {
            exporterLabel          = new GUIStyle(GUI.skin.label);
            exporterLabel.richText = true;
        }

        if (exporterTextArea == null)
        {
            exporterTextArea             = new GUIStyle(GUI.skin.textArea);
            exporterTextArea.fixedWidth  = descSize.x;
            exporterTextArea.fixedHeight = descSize.y;
        }

        if (exporterClickableLabel == null)
        {
            exporterClickableLabel          = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
            exporterClickableLabel.richText = true;
        }
        //Header
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(header);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        // Account settings
        if (access_token.Length == 0)
        {
            GUILayout.Label("Log in with your Sketchfab account", EditorStyles.centeredGreyMiniLabel);
            user_name     = EditorGUILayout.TextField("Email", user_name);
            user_password = EditorGUILayout.PasswordField("Password", user_password);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("<color=" + clickableLabelColor + ">Create an account  - </color>", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(createAccountUrl);
            }
            if (GUILayout.Button("<color=" + clickableLabelColor + ">Reset your password  - </color>", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(resetPasswordUrl);
            }
            if (GUILayout.Button("<color=" + clickableLabelColor + ">Report an issue</color>", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(reportAnIssueUrl);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Login", GUILayout.Width(150), GUILayout.Height(25)))
            {
                www = publisher.www;
                publisher.oauth(user_name, user_password);
                EditorPrefs.SetString(usernameEditorKey, user_name);
                //EditorPrefs.SetString(passwordEditorKey, user_password);
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            if (latestVersion.Length == 0)
            {
                Color current = GUI.color;
                GUI.color = Color.red;
                GUILayout.Label("An error occured when looking for the latest exporter version\nYou might be using an old and not fully supported version", EditorStyles.centeredGreyMiniLabel);
                if (GUILayout.Button("Click here to be redirected to release page"))
                {
                    Application.OpenURL(latestReleaseUrl);
                }
                GUI.color = current;
            }
            else if (exporterVersion != latestVersion)
            {
                Color current = GUI.color;
                GUI.color = redColor;
                GUILayout.Label("New version " + latestVersion + " available (current version is " + exporterVersion + ")", EditorStyles.centeredGreyMiniLabel);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Go to release page", GUILayout.Width(150), GUILayout.Height(25)))
                {
                    Application.OpenURL(latestReleaseUrl);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUI.color = current;
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Exporter is up to date (version:" + exporterVersion + ")", EditorStyles.centeredGreyMiniLabel);

                GUILayout.FlexibleSpace();
                if (GUILayout.Button("<color=" + clickableLabelColor + ">Help  -</color>", exporterClickableLabel, GUILayout.Height(20)))
                {
                    Application.OpenURL(latestReleaseUrl);
                }

                if (GUILayout.Button("<color=" + clickableLabelColor + ">Report an issue</color>", exporterClickableLabel, GUILayout.Height(20)))
                {
                    Application.OpenURL(reportAnIssueUrl);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal("Box");
            GUILayout.Label("Account: <b>" + userDisplayName + "</b> (" + (isUserPro ? "PRO" : "FREE") + " account)", exporterLabel);
            if (GUILayout.Button("Logout"))
            {
                access_token = "";
                //EditorPrefs.DeleteKey(usernameEditorKey);
                //EditorPrefs.DeleteKey(passwordEditorKey);
                resizeWindow(loginSize);
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(SPACE_SIZE);

        if (access_token.Length > 0)
        {
            // Model settings
            GUILayout.Label("Model properties", EditorStyles.boldLabel);

            // Model name
            GUILayout.Label("Name");
            param_name = EditorGUILayout.TextField(param_name);
            GUILayout.Label("(" + param_name.Length + "/" + NAME_LIMIT + ")", EditorStyles.centeredGreyMiniLabel);
            EditorStyles.textField.wordWrap = true;
            GUILayout.Space(SPACE_SIZE);

            GUILayout.Label("Description");
            param_description = EditorGUILayout.TextArea(param_description, exporterTextArea);
            GUILayout.Label("(" + param_description.Length + " / 1024)", EditorStyles.centeredGreyMiniLabel);
            GUILayout.Space(SPACE_SIZE);
            GUILayout.Label("Tags (separated by spaces)");
            param_tags = EditorGUILayout.TextField(param_tags);
            GUILayout.Label("'unity' and 'unity3D' added automatically (" + param_tags.Length + "/50)", EditorStyles.centeredGreyMiniLabel);
            GUILayout.Space(SPACE_SIZE);
            // ENable only if user is pro

            GUILayout.Label("PRO only features", EditorStyles.centeredGreyMiniLabel);
            if (isUserPro)
            {
                EditorGUILayout.BeginVertical("Box");
                GUILayout.BeginHorizontal();
                param_private = EditorGUILayout.Toggle("Private model", param_private);
                if (GUILayout.Button("(<color=" + clickableLabelColor + ">more info</color>)", exporterClickableLabel, GUILayout.Height(20)))
                {
                    Application.OpenURL(latestReleaseUrl);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUI.enabled = isUserPro && param_private;
                GUILayout.Label("Password");
                param_password = EditorGUILayout.TextField(param_password);
                EditorGUILayout.EndVertical();
                GUI.enabled = true;
            }
            GUILayout.Label("Options", EditorStyles.boldLabel);
            GUILayout.BeginHorizontal();
            opt_exportAnimation = EditorGUILayout.Toggle("Export animation", opt_exportAnimation);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            param_autopublish = EditorGUILayout.Toggle("Publish immediately ", param_autopublish);
            if (GUILayout.Button("(<color=" + clickableLabelColor + ">more info</color>)", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(latestReleaseUrl);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            //GUILayout.Space(SPACE_SIZE);

            //if (categories.Count > 0)
            //	categoryIndex = EditorGUILayout.Popup(categoryIndex, categoriesNames.ToArray());

            //GUILayout.Space(SPACE_SIZE);
            bool enable = updateExporterStatus();

            if (enable)
            {
                GUI.color = blueColor;
            }
            else
            {
                GUI.color = greyColor;
            }

            if (publisher != null && publisher.getState() == ExporterState.PUBLISH_MODEL && publisher.www != null)
            {
                Rect r = EditorGUILayout.BeginVertical();
                EditorGUI.ProgressBar(r, progress(), "Upload progress");
                GUILayout.Space(18);
                EditorGUILayout.EndVertical();
            }
            else
            {
                GUI.enabled = enable;
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(status, GUILayout.Width(250), GUILayout.Height(40)))
                {
                    if (!enable)
                    {
                        EditorUtility.DisplayDialog("Error", status, "Ok");
                    }
                    else
                    {
                        if (System.IO.File.Exists(zipPath))
                        {
                            System.IO.File.Delete(zipPath);
                        }

                        exporter.ExportCoroutine(exportPath, null, true, true, opt_exportAnimation, true);

                        if (File.Exists(zipPath))
                        {
                            publisher.setFilePath(zipPath);
                            publisher.publish(buildParameterDict(), access_token);
                            www = publisher.www;
                        }
                        else
                        {
                            Debug.Log("Zip file has not been generated. Aborting publish.");
                        }
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
        }
    }
    void OnGUI()
    {
        if (mTextAreaStyle == null)
        {
            mTextAreaStyle             = new GUIStyle(GUI.skin.textArea);
            mTextAreaStyle.fixedWidth  = DESC_SIZE.x;
            mTextAreaStyle.fixedHeight = DESC_SIZE.y;
        }

        if (mStatusStyle == null)
        {
            mStatusStyle          = new GUIStyle(EditorStyles.label);
            mStatusStyle.richText = true;
        }

        // Export path
        GUILayout.Label("Export Path", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        mExportPath = EditorGUILayout.TextField(mExportPath);
        if (GUILayout.Button("...", GUILayout.Width(48), GUILayout.Height(16)))
        {
            mExportPath = EditorUtility.OpenFolderPanel("Export Path", mExportPath, "");
        }
        GUILayout.EndHorizontal();

        // Model settings
        GUILayout.Label("Model properties", EditorStyles.boldLabel);

        // Model name
        GUILayout.Label("Name");
        mParamName = EditorGUILayout.TextField(mParamName);
        GUILayout.Label("(" + mParamName.Length + "/" + NAME_LIMIT + ")", EditorStyles.centeredGreyMiniLabel);
        EditorStyles.textField.wordWrap = true;
        GUILayout.Space(SPACE_SIZE);

        GUILayout.Label("Description");
        mParamDescription = EditorGUILayout.TextArea(mParamDescription, mTextAreaStyle);
        GUILayout.Label("(" + mParamDescription.Length + " / 1024)", EditorStyles.centeredGreyMiniLabel);
        GUILayout.Space(SPACE_SIZE);

        GUILayout.Label("Tags (separated by spaces)");
        mParamTags = EditorGUILayout.TextField(mParamTags);
        GUILayout.Label("'unity' and 'unity3D' added automatically (" + mParamTags.Length + "/50)", EditorStyles.centeredGreyMiniLabel);
        GUILayout.Space(SPACE_SIZE);

        GUILayout.Label("Options", EditorStyles.boldLabel);
        GUILayout.BeginVertical();
        mExportPBR       = EditorGUILayout.Toggle("Export PBR Material", mExportPBR);
        mExportAnimation = EditorGUILayout.Toggle("Export animation (beta)", mExportAnimation);
        mConvertImage    = EditorGUILayout.Toggle("Convert Images", mConvertImage);
        mBuildZip        = EditorGUILayout.Toggle("Build Zip", mBuildZip);
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();

        GUILayout.Space(SPACE_SIZE);

        bool enable = updateExporterStatus();

        GUILayout.Label("Status", EditorStyles.boldLabel);

        if (enable)
        {
            GUILayout.Label(string.Format("<color=#0F0F0FFF>{0}</color>", mStatus), mStatusStyle);
        }
        else
        {
            GUILayout.Label(string.Format("<color=#F00F0FFF>{0}</color>", mStatus), mStatusStyle);
        }

        if (mResult.Length > 0)
        {
            GUILayout.Label(string.Format("<color=#0F0F0FFF>{0}</color>", mResult), mStatusStyle);
        }


        GUILayout.Space(SPACE_SIZE);
        GUI.enabled = enable;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Export Selection", GUILayout.Width(220), GUILayout.Height(32)))
        {
            if (!enable)
            {
                EditorUtility.DisplayDialog("Error", mStatus, "Ok");
            }
            else
            {
                string exportFileName = Path.Combine(mExportPath, mParamName + ".gltf");
                mExporter.ExportCoroutine(exportFileName, null, mBuildZip, mExportPBR, mExportAnimation, mConvertImage);
                mResult = string.Format("Exort Finished: {0}", exportFileName);
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        // Banner
        GUILayout.Space(SPACE_SIZE * 2);
        GUI.enabled = true;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        string url = "https://neil3d.github.io/app/unity-gltf-exporter.html";

        if (GUILayout.Button("Document: " + url, EditorStyles.helpBox))
        {
            Application.OpenURL(url);
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.Space(SPACE_SIZE * 2);
    }
Ejemplo n.º 9
0
    void OnGUI()
    {
        if (exporterLabel == null)
        {
            exporterLabel          = new GUIStyle(GUI.skin.label);
            exporterLabel.richText = true;
        }

        if (exporterTextArea == null)
        {
            exporterTextArea             = new GUIStyle(GUI.skin.textArea);
            exporterTextArea.fixedWidth  = descSize.x;
            exporterTextArea.fixedHeight = descSize.y;
        }

        if (exporterClickableLabel == null)
        {
            exporterClickableLabel          = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
            exporterClickableLabel.richText = true;
        }

        GUILayout.Space(SPACE_SIZE);

        // Model settings
        GUILayout.Label("Model properties", EditorStyles.boldLabel);

        // Model name
        GUILayout.Label("Name");
        param_name = EditorGUILayout.TextField(param_name);
        GUILayout.Space(SPACE_SIZE);

        GUILayout.Label("Texture properties", EditorStyles.boldLabel);

        GUILayout.Label("Texture max size");
        Exporter.opt_maxSize = EditorGUILayout.IntField(Exporter.opt_maxSize);
        GUILayout.Label("Texture jpg quality");
        Exporter.opt_jpgQuality = EditorGUILayout.IntField(Exporter.opt_jpgQuality);
        GUILayout.Space(SPACE_SIZE);

        GUILayout.Label("Options", EditorStyles.boldLabel);
        opt_exportAnimation = EditorGUILayout.Toggle("Export animation", opt_exportAnimation);
        opt_splitChunks     = EditorGUILayout.Toggle("Split chunks", opt_splitChunks);

        GUILayout.Label("Lights", EditorStyles.boldLabel);
        EditorGUIUtility.labelWidth = 200;
        opt_halfSpotAngle           = EditorGUILayout.Toggle("Half spot angle(Hilo3d, Threejs...)", Exporter.opt_halfSpotAngle);
        opt_quadraticAttenuation    = EditorGUILayout.Toggle("Light quadratic attenuation(Hilo3d...)", Exporter.opt_quadraticAttenuation);

        GUILayout.Label("Materials", EditorStyles.boldLabel);
        opt_noLighting = EditorGUILayout.Toggle("No Lighting(Always for mobile)", Exporter.opt_noLighting);

        //GUILayout.Space(SPACE_SIZE);

        //if (categories.Count > 0)
        //	categoryIndex = EditorGUILayout.Popup(categoryIndex, categoriesNames.ToArray());

        //GUILayout.Space(SPACE_SIZE);
        bool enable = updateExporterStatus();

        if (enable)
        {
            GUI.color = blueColor;
        }
        else
        {
            GUI.color = greyColor;
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Export", GUILayout.Width(250), GUILayout.Height(40)))
        {
            if (System.IO.File.Exists(zipPath))
            {
                System.IO.File.Delete(zipPath);
            }
            zipPath    = Application.temporaryCachePath + "/" + param_name + ".zip";
            exportPath = Application.temporaryCachePath + "/" + param_name + ".gltf";
            exporter.ExportCoroutine(exportPath, null, false, true, opt_exportAnimation, true);
            OpenInFileBrowser.Open(Path.GetDirectoryName(exportPath));
        }
    }
Ejemplo n.º 10
0
    void OnGUI()
    {
        if (mTextAreaStyle == null)
        {
            mTextAreaStyle             = new GUIStyle(GUI.skin.textArea);
            mTextAreaStyle.fixedWidth  = DESC_SIZE.x;
            mTextAreaStyle.fixedHeight = DESC_SIZE.y;
        }

        if (mStatusStyle == null)
        {
            mStatusStyle          = new GUIStyle(EditorStyles.label);
            mStatusStyle.richText = true;
        }

        // Export path
        GUILayout.Label("Export Path", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        //mExportPath = EditorGUILayout.TextField(mExportPath);
        exportOption.mPrePath = EditorGUILayout.TextField(exportOption.mPrePath);

        if (GUILayout.Button("...", GUILayout.Width(48), GUILayout.Height(16)))
        {
            //mExportPath = EditorUtility.OpenFolderPanel("Export Path", mExportPath, "");
            exportOption.mPrePath = EditorUtility.OpenFolderPanel("Export Path", exportOption.mPrePath, "");
        }

        GUILayout.EndHorizontal();

        // Model settings
        GUILayout.Label("Model properties", EditorStyles.boldLabel);
        exportOption.useGLTFNameByModelName = EditorGUILayout.ToggleLeft("是否使用选择的节点名称命名导出文件(当只选中一个节点时才生效)", exportOption.useGLTFNameByModelName);

        // Model name
        GUILayout.Label("Name");
        if (exportOption.useGLTFNameByModelName)
        {
            Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel);
            if (transforms.Length == 1)
            {
                mParamName = GlTF_Writer.cleanNonAlphanumeric(transforms[0].name);
                if (mParamName.IndexOf(" ") >= 0)
                {
                    Debug.LogWarning("节点名称不规范(可能有空格) " + mParamName);
                    mParamName = "";
                }
            }
        }
        mParamName = EditorGUILayout.TextField(mParamName);
        GUILayout.Label("(" + mParamName.Length + "/" + NAME_LIMIT + ")", EditorStyles.centeredGreyMiniLabel);
        EditorStyles.textField.wordWrap = true;
        GUILayout.Space(SPACE_SIZE);

        /*GUILayout.Label("Description");
         * mParamDescription = EditorGUILayout.TextArea(mParamDescription, mTextAreaStyle);
         * GUILayout.Label("(" + mParamDescription.Length + " / 1024)", EditorStyles.centeredGreyMiniLabel);
         * GUILayout.Space(SPACE_SIZE);*/

        /*GUILayout.Label("Tags (separated by spaces)");
         * mParamTags = EditorGUILayout.TextField(mParamTags);
         * GUILayout.Label("'unity' and 'unity3D' added automatically (" + mParamTags.Length + "/50)", EditorStyles.centeredGreyMiniLabel);
         * GUILayout.Space(SPACE_SIZE);*/

        GUILayout.Label("Options", EditorStyles.largeLabel, GUILayout.MinWidth(300.0F), GUILayout.Width(300.0F));
        GUILayout.BeginVertical(GUILayout.MinWidth(300.0F));

        exportOption.creatDirectoryByModelName = EditorGUILayout.ToggleLeft("是否自动创建文件夹(存放位置:路径/模型名/模型名.gltf)", exportOption.creatDirectoryByModelName);

        exportOption.convertRightHanded = EditorGUILayout.ToggleLeft("是否转换为右手坐标系(默认否)", exportOption.convertRightHanded, GUILayout.ExpandWidth(true));

        //mExportPBR = EditorGUILayout.Toggle("Export PBR Material", mExportPBR);
        //mExportAnimation = EditorGUILayout.Toggle("Export animation (beta)", mExportAnimation);
        //mConvertImage = EditorGUILayout.Toggle("Convert Images", mConvertImage);
        //mBuildZip = EditorGUILayout.Toggle("Build Zip", mBuildZip);
        //mConvertImage = EditorGUILayout.Toggle("是否网格合并(默认不合)", mConvertImage);
        exportOption.mCombineMesh = EditorGUILayout.ToggleLeft("是否将网格数据合并为一个文件(默认合并)", exportOption.mCombineMesh);

        //mExportPBR = EditorGUILayout.Toggle("Export PBR Material", mExportPBR);
        //mExportAnimation = EditorGUILayout.Toggle("Export animation (beta)", mExportAnimation);
        //mConvertImage = EditorGUILayout.Toggle("Convert Images", mConvertImage);
        //mBuildZip = EditorGUILayout.Toggle("Build Zip", mBuildZip);
        //mExportNormal = EditorGUILayout.Toggle("是否导出法线(默认不导)", mExportNormal);
        exportOption.mNormal = EditorGUILayout.ToggleLeft("是否导出法线(默认不导)", exportOption.mNormal);

        exportOption.mMaxLightmapMultiple = EditorGUILayout.FloatField("光照图可导出的最大亮度倍数", exportOption.mMaxLightmapMultiple, EditorStyles.label, null);

        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();

        GUILayout.Space(SPACE_SIZE);

        bool enable = updateExporterStatus();

        GUILayout.Label("Status", EditorStyles.boldLabel);

        if (enable)
        {
            GUILayout.Label(string.Format("<color=#0F0F0FFF>{0}</color>", mStatus), mStatusStyle);
        }
        else
        {
            GUILayout.Label(string.Format("<color=#F00F0FFF>{0}</color>", mStatus), mStatusStyle);
        }

        if (mResult.Length > 0)
        {
            GUILayout.Label(string.Format("<color=#0F0F0FFF>{0}</color>", mResult), mStatusStyle);
        }


        GUILayout.Space(SPACE_SIZE);
        GUI.enabled = enable;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Export Selection", GUILayout.Width(180), GUILayout.Height(24)))
        {
            if (!enable)
            {
                EditorUtility.DisplayDialog("Error", mStatus, "Ok");
            }
            else
            {
                exportOption.mPath = exportOption.mPrePath;
                if (!Directory.Exists(exportOption.mPath))
                {
                    Directory.CreateDirectory(exportOption.mPath);
                }

                if (exportOption.creatDirectoryByModelName)
                {
                    exportOption.mPath = exportOption.mPrePath + "/" + mParamName;
                    if (!Directory.Exists(exportOption.mPath))
                    {
                        Directory.CreateDirectory(exportOption.mPath);
                    }
                }

                string exportFileName = Path.Combine(exportOption.mPath, mParamName + ".gltf");
                exportOption.mFileName = Path.Combine(exportOption.mPath, mParamName + ".gltf");

                Debug.ClearDeveloperConsole();
                mExporter.ExportCoroutine(exportOption);

                mResult = string.Format("Exort Finished: {0}", exportFileName);
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        // Banner
        GUILayout.Space(SPACE_SIZE * 2);
        GUI.enabled = true;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        string url = "http://192.168.31.241:8181/docs/game_render/babylonjs_build";

        if (GUILayout.Button("Document: " + url, EditorStyles.helpBox))
        {
            Application.OpenURL(url);
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.Space(SPACE_SIZE * 2);
    }
Ejemplo n.º 11
0
    void OnGUI()
    {
        if (exporterLabel == null)
        {
            exporterLabel          = new GUIStyle(GUI.skin.label);
            exporterLabel.richText = true;
        }

        if (exporterTextArea == null)
        {
            exporterTextArea             = new GUIStyle(GUI.skin.textArea);
            exporterTextArea.fixedWidth  = descSize.x;
            exporterTextArea.fixedHeight = descSize.y;
        }

        if (exporterClickableLabel == null)
        {
            exporterClickableLabel          = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
            exporterClickableLabel.richText = true;
        }
        //Header
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(header);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();


        if (latestVersion.Length == 0)
        {
            Color current = GUI.color;
            GUI.color = Color.red;
            GUILayout.Label("An error occured when looking for the latest exporter version\nYou might be using an old and not fully supported version", EditorStyles.centeredGreyMiniLabel);
            if (GUILayout.Button("Click here to be redirected to release page"))
            {
                Application.OpenURL(latestReleaseUrl);
            }
            GUI.color = current;
        }
        else if (exporterVersion != latestVersion)
        {
            Color current = GUI.color;
            GUI.color = redColor;
            GUILayout.Label("New version " + latestVersion + " available (current version is " + exporterVersion + ")", EditorStyles.centeredGreyMiniLabel);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Go to release page", GUILayout.Width(150), GUILayout.Height(25)))
            {
                Application.OpenURL(latestReleaseUrl);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUI.color = current;
        }
        else
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Exporter is up to date (version:" + exporterVersion + ")", EditorStyles.centeredGreyMiniLabel);

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("<color=" + clickableLabelColor + ">Help  -</color>", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(helpUrl);
            }

            if (GUILayout.Button("<color=" + clickableLabelColor + ">Report an issue</color>", exporterClickableLabel, GUILayout.Height(20)))
            {
                Application.OpenURL(reportAnIssueUrl);
            }
            GUILayout.EndHorizontal();
        }



        GUILayout.Space(SPACE_SIZE);



        GUILayout.Label("Options", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        opt_exportAnimation = EditorGUILayout.Toggle("Export animation", opt_exportAnimation);
        GUILayout.FlexibleSpace();

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        EditorGUIUtility.labelWidth = 310f;
        //opt_exportVariations = EditorGUILayout.Toggle("Include each selected root object as a variation", opt_exportVariations);
        //GUILayout.FlexibleSpace();

        GUILayout.EndHorizontal();



        bool enable = updateExporterStatus();

        if (enable)
        {
            GUI.color = blueColor;
        }
        else
        {
            GUI.color = greyColor;
        }


        GUI.enabled = enable;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button(status, GUILayout.Width(250), GUILayout.Height(40)))
        {
            if (!enable)
            {
                EditorUtility.DisplayDialog("Error", status, "Ok");
            }
            else
            {
                zipPath = EditorUtility.SaveFilePanel(
                    "Export object to zip",
                    exportPath,
                    param_name + "_" + System.DateTime.Now.ToString("yyyyMMdd") + ".zip",
                    "zip");

                exportPath = zipPath.Replace(".zip", ".gltf");

                if (System.IO.File.Exists(zipPath))
                {
                    System.IO.File.Delete(zipPath);
                }

                exporter.ExportCoroutine(exportPath, null, true, true, opt_exportAnimation, true);
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
    }