Beispiel #1
0
        private void OnGUI()
        {
            //if (labelFieldRichText == null)
            {
                labelFieldRichText          = new GUIStyle("Label");
                labelFieldRichText.richText = true;
            }

            GUILayout.BeginVertical("HelpBox");
            EditorGUILayout.HelpBox("The LB Manager will help you optimise your landscapes prior to shipping your game. It will remove all unneeded LB components. [Technical Preview]", MessageType.Info, true);

            EditorGUI.BeginChangeCheck();
            landscape = (LBLandscape)EditorGUILayout.ObjectField(landscapeGUIContent, landscape, typeof(LBLandscape), true);
            if (EditorGUI.EndChangeCheck() && landscape != null)
            {
                landscapeTemplateName = "LB_Backup_" + landscape.name + "_Template";
            }

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            EditorGUIUtility.labelWidth += labelWidthOffset;

            #region Start of Phase 1
            currentBgndColor    = GUI.backgroundColor;
            GUI.backgroundColor = GUI.backgroundColor * (EditorGUIUtility.isProSkin ? 0.7f : 1.3f);
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUI.backgroundColor = currentBgndColor;
            EditorGUILayout.LabelField("<color=" + txtColourName + "><b>Phase 1 - Backup</b></color>", labelFieldRichText);

            EditorGUILayout.HelpBox("You need to: Backup each landscape in each scene to a template.", MessageType.Info, true);
            EditorGUIUtility.labelWidth -= labelWidthOffset;
            landscapeTemplateName        = EditorGUILayout.TextField(saveTemplateNameContent, landscapeTemplateName);
            EditorGUIUtility.labelWidth += labelWidthOffset;

            if (GUILayout.Button("Backup Template", GUILayout.MaxWidth(130f)))
            {
                bool isSceneSaveRequired = false;

                if (landscape != null)
                {
                    LBEditorCommon.SaveTemplate(landscape, LBEditorCommon.LBVersion,
                                                landscapeTemplateName,
                                                ref isSceneSaveRequired,
                                                createTemplatePackage,
                                                addMapTexturesToTemplatePackage,
                                                addLayerHeightmapTexturesToTemplatePackage,
                                                addLBLightingToTemplate,
                                                addPathsToTemplate,
                                                addStencilsToTemplate,
                                                addPathMeshMaterialsToTemplate);
                }
                else
                {
                    EditorUtility.DisplayDialog("Backup Template", "Select a landscape above so that you can back it up to a template", "Got it!");
                }
            }

            GUILayout.EndVertical(); // End of Phase 1
            #endregion End Phase 1

            EditorGUILayout.Space();

            #region Start of Phase 2
            currentBgndColor    = GUI.backgroundColor;
            GUI.backgroundColor = GUI.backgroundColor * (EditorGUIUtility.isProSkin ? 0.7f : 1.3f);
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUI.backgroundColor = currentBgndColor;
            EditorGUILayout.LabelField("<color=" + txtColourName + "><b>Phase 2 - Optimise</b></color>", labelFieldRichText);

            EditorGUILayout.HelpBox("You need to: Optimise each landscape in EACH scene by removing unnecessary scripts. You will need to open each scene one at a time.", MessageType.Info, true);

            isRemovePrefabItems = EditorGUILayout.Toggle(removePrefabItemContent, isRemovePrefabItems);
            isRemoveMapPaths    = EditorGUILayout.Toggle(removeMapPathContent, isRemoveMapPaths);
            isRemoveStencils    = EditorGUILayout.Toggle(removeStencilContent, isRemoveStencils);
            isRemoveLBLandscape = EditorGUILayout.Toggle(removeLBLandscapeContent, isRemoveLBLandscape);

            if (GUILayout.Button(finaliseBtnContent, GUILayout.MaxWidth(130f)))
            {
                if (landscape != null)
                {
                    if (EditorUtility.DisplayDialog("Finalise Landscape", "This action will clear all LB Editor data based on your preferences above.\n\nWARNING: There is NO UNDO.", "FINALISE", "Cancel"))
                    {
                        if (isRemovePrefabItems)
                        {
                            RemovePrefabItems();
                        }
                        if (isRemoveMapPaths)
                        {
                            RemoveMapPaths();
                        }
                        if (isRemoveStencils)
                        {
                            RemoveStencils();
                        }
                        if (isRemoveLBLandscape)
                        {
                            RemoveLBLandscape();
                        }
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Finalise Landscape", "Select a landscape above so that you can finalise it", "Got it!");
                }
            }

            GUILayout.EndVertical(); // End of Phase 2
            #endregion End Phase 2

            EditorGUILayout.Space();

            #region Start of Phase 3
            currentBgndColor    = GUI.backgroundColor;
            GUI.backgroundColor = GUI.backgroundColor * (EditorGUIUtility.isProSkin ? 0.7f : 1.3f);
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUI.backgroundColor = currentBgndColor;
            EditorGUILayout.LabelField("<color=" + txtColourName + "><b>Phase 3 - Uninstall</b></color>", labelFieldRichText);

            EditorGUILayout.HelpBox("You need to: Selectively remove unnecessary Landscape Builder scripts in the project. Re-import LB package to re-install them.", MessageType.Info, true);

            isRemoveDemoScene      = EditorGUILayout.Toggle(removeDemoSceneContent, isRemoveDemoScene);
            isRemoveDemoAssets     = EditorGUILayout.Toggle(removeDemoAssetsContent, isRemoveDemoAssets);
            isRemoveUnityWater     = EditorGUILayout.Toggle(removeUnityWaterContent, isRemoveUnityWater);
            isRemoveRuntimeSamples = EditorGUILayout.Toggle(removeRuntimeSamplesContent, isRemoveRuntimeSamples);
            isRemoveEditorScripts  = EditorGUILayout.Toggle(removeEditorScriptsContent, isRemoveEditorScripts);
            isRemoveSRP            = EditorGUILayout.Toggle(removeSRPContent, isRemoveSRP);

            if (GUILayout.Button(uninstallBtnContent, GUILayout.MaxWidth(130f)))
            {
                if (EditorUtility.DisplayDialog("Uninstall components", "This action will uninstall all selected components. Make sure you have Finalised all landscape in all scenes before proceeding. If you are unsure Cancel.\n\nWARNING: There is NO UNDO.", "DO IT!", "Cancel"))
                {
                    // Close the LB Editor if it is open
                    var lbW = LBEditorHelper.GetLBW();
                    if (lbW != null)
                    {
                        lbW.Close();
                    }

                    if (isRemoveDemoAssets)
                    {
                        UninstallDemoAssets();
                    }
                    else if (isRemoveDemoScene)
                    {
                        UninstallDemoScene();
                    }
                    if (isRemoveUnityWater)
                    {
                        UninstallUnityWater();
                    }
                    if (isRemoveRuntimeSamples)
                    {
                        UinstallRuntimeSamples();
                    }
                    if (isRemoveEditorScripts)
                    {
                        UninstallEditorScripts();
                    }
                    if (isRemoveSRP)
                    {
                        UninstallSRP();
                    }
                }
            }

            GUILayout.EndVertical(); // End of Phase 3
            #endregion End Phase 3

            EditorGUIUtility.labelWidth -= 10f;
            EditorGUILayout.EndScrollView();

            GUILayout.EndVertical();
        }