Ejemplo n.º 1
0
        private void importLevel()
        {
            // check to see if there was an existing level, as we'll have to overwrite it
            GameObject existingLevel = GameObject.Find("Level");

            if (existingLevel)
            {
                bool yes = EditorUtility.DisplayDialog("Existing level",
                                                       "There is an existing level loaded. Are you sure you " +
                                                       "want to import another level? Any unsaved changes will " +
                                                       "be lost.", "Yes", "Cancel");
                if (!yes)
                {
                    return;
                }
            }

            string levelPath = CommonGUI.BrowseForFile("Import level...",
                                                       new[] { "Level files", "tmap,json" }, null);

            if (levelPath == null)
            {
                return;
            }

            EditLevel(levelPath);
        }
Ejemplo n.º 2
0
        private void drawFirstDream(int i)
        {
            EditorGUILayout.BeginHorizontal();
            _journal.FirstDream[i] = EditorGUILayout.TextField(
                new GUIContent("", "The path to a dream that you should start on in this journal."),
                _journal.FirstDream[i]);
            if (GUILayout.Button("Browse", GUILayout.Width(60)))
            {
                _journal.FirstDream[i] = CommonGUI.BrowseForFile("Browse for dream", new[] { "Dream JSON file", "json" },
                                                                 _journal.FirstDream[i]);
            }

            if (GUILayout.Button("Remove", GUILayout.Width(60)))
            {
                _firstDreamsToRemove.Push(i);
            }

            EditorGUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        static void OnGUIContents(bool isSceneGUI, MeshEditBrushTool tool)
        {
            CommonGUI.StartToolGUI();

            var filteredSelection = CSGBrushEditorManager.FilteredSelection;

            var defaultMaterial = CSGSettings.DefaultMaterial;

            GUILayout.BeginVertical(isSceneGUI ? InSceneWidth : GUIStyleUtility.ContentEmpty);
            {            /*
                          *     GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                          *     {
                          *
                          *             GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                          *             {
                          *                     //GUILayout.Label(Keys.VerticalMoveMode.ToString() + " to dragging brush up/down", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Control (hold) to drag polygon on it's plane", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Shift (hold) to drag extrude polygon", EditorStyles.miniLabel);
                          *                     GUILayout.Label("Shift (hold) to chamfer edges and vertices", EditorStyles.miniLabel);
                          *             }
                          *             GUILayout.EndVertical();
                          *     }
                          *     GUILayout.EndHorizontal();*/
                ChooseCSGOperation(filteredSelection, isSceneGUI, tool);
                GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                {
                    if (isSceneGUI)
                    {
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: true);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                    {
                        bool have_nodes = tool != null && (filteredSelection.NodeTargets.Length > 0);

                        EditorGUI.BeginDisabledGroup(!have_nodes);
                        {
                            GUIStyle left   = EditorStyles.miniButtonLeft;
                            GUIStyle middle = EditorStyles.miniButtonMid;
                            GUIStyle right  = EditorStyles.miniButtonRight;

                            GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                            {
                                if (isSceneGUI)
                                {
                                    EditorGUILayout.LabelField(ContentFlip, labelWidth);
                                }
                                else
                                {
                                    EditorGUILayout.LabelField(ContentFlip, largeLabelWidth);
                                }
                                if (GUILayout.Button(ContentFlipX, left))
                                {
                                    tool.FlipX();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipX);
                                if (GUILayout.Button(ContentFlipY, middle))
                                {
                                    tool.FlipY();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipY);
                                if (GUILayout.Button(ContentFlipZ, right))
                                {
                                    tool.FlipZ();
                                }
                                TooltipUtility.SetToolTip(TooltipFlipZ);
                            }
                            GUILayout.EndHorizontal();

                            /*
                             * EditorGUILayout.LabelField(ContentEdgesLabel);
                             * GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                             * {
                             *      EditorGUI.BeginDisabledGroup(!tool.CanSmooth());
                             *      {
                             *              if (GUILayout.Button("Smooth"))		{ tool.Smooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             *      EditorGUI.BeginDisabledGroup(!tool.CanUnSmooth());
                             *      {
                             *              if (GUILayout.Button("Un-smooth"))	{ tool.UnSmooth(); }
                             *      }
                             *      EditorGUI.EndDisabledGroup();
                             * }
                             * GUILayout.EndHorizontal();
                             */

                            if (GUILayout.Button(ContentSnapToGrid))
                            {
                                tool.SnapToGrid();
                            }
                            TooltipUtility.SetToolTip(TooltipSnapToGrid);
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(2);
                if (!isSceneGUI)
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: false);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                    }
                    if (EditorGUI.EndChangeCheck() && defaultMaterial)
                    {
                        CSGSettings.DefaultMaterial = defaultMaterial;
                        CSGSettings.Save();
                    }
                }
            }
            GUILayout.EndVertical();
            EditorGUI.showMixedValue = false;
        }
Ejemplo n.º 4
0
        public void OnSceneGUI(SceneView sceneView)
        {
            if (_levelObj == null)
            {
                return;
            }

            Handles.BeginGUI();

            Rect controlsArea = new Rect(POS_PADDING, POS_PADDING,
                                         CONTROLS_WIDTH, sceneView.position.height - (POS_PADDING * 10));

            GUILayout.BeginArea(controlsArea);

            GUILayout.BeginVertical();

            if (CommonGUI.ColorButton(new GUIContent("Entity"), _placingEntities ? Color.green : Color.grey,
                                      GUILayout.Height(50)))
            {
                _placingEntities           = !_placingEntities;
                Selection.activeGameObject = null;
            }

            if (_placingEntities)
            {
                handlePlaceEntity(sceneView);
            }

            GUILayout.EndVertical();

            GUILayout.EndArea();

            Rect bottomArea = new Rect(POS_PADDING, sceneView.position.height - 50 - (POS_PADDING * 4),
                                       sceneView.position.width - (POS_PADDING * 2), 50);

            GUILayout.BeginArea(bottomArea);
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (SnapToGrid.Enabled)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("-"))
                {
                    SnapToGrid.Resolution /= 2;
                }
                GUILayout.Label(SnapToGrid.Resolution.ToString(CultureInfo.InvariantCulture));
                if (GUILayout.Button("+"))
                {
                    SnapToGrid.Resolution *= 2;
                }
                GUILayout.EndHorizontal();
            }

            SnapToGrid.Enabled = GUILayout.Toggle(SnapToGrid.Enabled, "Snap to grid");

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndArea();

            Handles.EndGUI();

            sceneView.Repaint();
        }
Ejemplo n.º 5
0
        static void OnGUIContents(bool isSceneGUI, ClipBrushTool tool)
        {
            CommonGUI.StartToolGUI();

            if (tool.ClipBrushCount == 0)
            {
                GUILayout.Label(string.Format("no brushes selected", tool.ClipBrushCount), GUIStyleUtility.redTextArea);
            }
            else
            {
                if (tool.ClipBrushCount == 1)
                {
                    GUILayout.Label(string.Format("{0} brush selected", tool.ClipBrushCount));
                }
                else
                {
                    GUILayout.Label(string.Format("{0} brushes selected", tool.ClipBrushCount));
                }
            }
            EditorGUILayout.Space();
            EditorGUI.BeginDisabledGroup(tool == null);
            {
                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    var newClipMode = (tool != null) ? tool.clipMode : ((ClipMode)999);
                    var skin        = GUIStyleUtility.Skin;
                    for (int i = 0; i < clipModeValues.Length; i++)
                    {
                        var        selected = newClipMode == clipModeValues[i];
                        GUIContent content;
                        GUIStyle   style;
                        if (selected)
                        {
                            style = GUIStyleUtility.selectedIconLabelStyle;   content = skin.clipNamesOn[i];
                        }
                        else
                        {
                            style = GUIStyleUtility.unselectedIconLabelStyle; content = skin.clipNames[i];
                        }
                        if (GUILayout.Toggle(selected, content, style))
                        {
                            newClipMode = clipModeValues[i];
                        }
                        TooltipUtility.SetToolTip(GUIStyleUtility.clipTooltips[i]);
                    }
                    if (tool != null && tool.clipMode != newClipMode)
                    {
                        tool.SetClipMode(newClipMode);
                    }
                }
                GUILayout.EndVertical();
                if (!isSceneGUI)
                {
                    GUILayout.Space(10);
                }

                bool disabled = (tool == null || tool.editMode != ClipBrushTool.EditMode.EditPoints);

                var defaultMaterial = CSGSettings.DefaultMaterial;
                GUILayout.BeginVertical(isSceneGUI ? MaterialSceneWidth : GUIStyleUtility.ContentEmpty);
                {
                    GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                    {
                        if (isSceneGUI)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                            GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        }
                        {
                            EditorGUI.BeginDisabledGroup(disabled);
                            {
                                if (GUILayout.Button(ContentCancel))
                                {
                                    doCancel = true;
                                }
                                TooltipUtility.SetToolTip(CancelTooltip);
                                if (GUILayout.Button(ContentCommit))
                                {
                                    doCommit = true;
                                }
                                TooltipUtility.SetToolTip(CommitTooltip);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        if (isSceneGUI)
                        {
                            GUILayout.EndVertical();
                        }
                    }
                    GUILayout.EndHorizontal();
                    if (isSceneGUI)
                    {
                        GUILayout.Space(2);
                        EditorGUI.BeginChangeCheck();
                        {
                            defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                        }
                        if (EditorGUI.EndChangeCheck() && defaultMaterial)
                        {
                            CSGSettings.DefaultMaterial = defaultMaterial;
                            CSGSettings.Save();
                        }
                    }
                }
                if (!isSceneGUI)
                {
                    EditorGUILayout.Space();
                    GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: false);
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
Ejemplo n.º 6
0
        public static void OnInspectorGUI(UnityEngine.Object[] targets)
        {
            InitReflection();
            if (!localStyles)
            {
                popupStyle = new GUIStyle(EditorStyles.popup);
                //popupStyle.padding.top += 2;
                popupStyle.margin.top += 2;
                localStyles            = true;
            }


            bool updateMeshes = false;

            var models = new CSGModel[targets.Length];

            for (int i = targets.Length - 1; i >= 0; i--)
            {
                models[i] = targets[i] as CSGModel;
                if (!models[i])
                {
                    ArrayUtility.RemoveAt(ref models, i);
                }
            }

            if (models.Length == 0)
            {
                return;
            }


            var               settings                    = models[0].Settings;
            var               vertexChannels              = models[0].VertexChannels;
            ExportType?       exportType                  = models[0].exportType;
            bool?             VertexChannelColor          = (vertexChannels & VertexChannelFlags.Color) == VertexChannelFlags.Color;
            bool?             VertexChannelTangent        = (vertexChannels & VertexChannelFlags.Tangent) == VertexChannelFlags.Tangent;
            bool?             VertexChannelNormal         = (vertexChannels & VertexChannelFlags.Normal) == VertexChannelFlags.Normal;
            bool?             VertexChannelUV0            = (vertexChannels & VertexChannelFlags.UV0) == VertexChannelFlags.UV0;
            bool?             InvertedWorld               = (settings & ModelSettingsFlags.InvertedWorld) == ModelSettingsFlags.InvertedWorld;
            bool?             NoCollider                  = (settings & ModelSettingsFlags.NoCollider) == ModelSettingsFlags.NoCollider;
            bool?             IsTrigger                   = (settings & ModelSettingsFlags.IsTrigger) == ModelSettingsFlags.IsTrigger;
            bool?             SetToConvex                 = (settings & ModelSettingsFlags.SetColliderConvex) == ModelSettingsFlags.SetColliderConvex;
            bool?             AutoGenerateRigidBody       = (settings & ModelSettingsFlags.AutoUpdateRigidBody) == ModelSettingsFlags.AutoUpdateRigidBody;
            bool?             DoNotRender                 = (settings & ModelSettingsFlags.DoNotRender) == ModelSettingsFlags.DoNotRender;
            bool?             ReceiveShadows              = !((settings & ModelSettingsFlags.DoNotReceiveShadows) == ModelSettingsFlags.DoNotReceiveShadows);
            bool?             AutoRebuildUVs              = (settings & ModelSettingsFlags.AutoRebuildUVs) == ModelSettingsFlags.AutoRebuildUVs;
            bool?             PreserveUVs                 = (settings & ModelSettingsFlags.PreserveUVs) == ModelSettingsFlags.PreserveUVs;
            bool?             ShowGeneratedMeshes         = models[0].ShowGeneratedMeshes;
            ShadowCastingMode?ShadowCastingMode           = (ShadowCastingMode)(settings & ModelSettingsFlags.ShadowCastingModeFlags);
            var               defaultPhysicsMaterial      = models[0].DefaultPhysicsMaterial;
            var               defaultPhysicsMaterialMixed = false;

            for (int i = 1; i < models.Length; i++)
            {
                settings       = models[i].Settings;
                vertexChannels = models[i].VertexChannels;
                ExportType        currExportType             = models[i].exportType;
                bool              currVertexChannelColor     = (vertexChannels & VertexChannelFlags.Color) == VertexChannelFlags.Color;
                bool              currVertexChannelTangent   = (vertexChannels & VertexChannelFlags.Tangent) == VertexChannelFlags.Tangent;
                bool              currVertexChannelNormal    = (vertexChannels & VertexChannelFlags.Normal) == VertexChannelFlags.Normal;
                bool              currVertexChannelUV0       = (vertexChannels & VertexChannelFlags.UV0) == VertexChannelFlags.UV0;
                bool              currInvertedWorld          = (settings & ModelSettingsFlags.InvertedWorld) == ModelSettingsFlags.InvertedWorld;
                bool              currNoCollider             = (settings & ModelSettingsFlags.NoCollider) == ModelSettingsFlags.NoCollider;
                bool              currIsTrigger              = (settings & ModelSettingsFlags.IsTrigger) == ModelSettingsFlags.IsTrigger;
                bool              currSetToConvex            = (settings & ModelSettingsFlags.SetColliderConvex) == ModelSettingsFlags.SetColliderConvex;
                bool              currAutoGenerateRigidBody  = (settings & ModelSettingsFlags.AutoUpdateRigidBody) == ModelSettingsFlags.AutoUpdateRigidBody;
                bool              currDoNotRender            = (settings & ModelSettingsFlags.DoNotRender) == ModelSettingsFlags.DoNotRender;
                bool              currReceiveShadows         = !((settings & ModelSettingsFlags.DoNotReceiveShadows) == ModelSettingsFlags.DoNotReceiveShadows);
                bool              currAutoRebuildUVs         = (settings & ModelSettingsFlags.AutoRebuildUVs) == ModelSettingsFlags.AutoRebuildUVs;
                bool              currPreserveUVs            = (settings & ModelSettingsFlags.PreserveUVs) == ModelSettingsFlags.PreserveUVs;
                bool              currShowGeneratedMeshes    = models[i].ShowGeneratedMeshes;
                var               currdefaultPhysicsMaterial = models[i].DefaultPhysicsMaterial;
                ShadowCastingMode currShadowCastingMode      = (ShadowCastingMode)(settings & ModelSettingsFlags.ShadowCastingModeFlags);

                if (VertexChannelColor.HasValue && VertexChannelColor.Value != currVertexChannelColor)
                {
                    VertexChannelColor = null;
                }
                if (VertexChannelTangent.HasValue && VertexChannelTangent.Value != currVertexChannelTangent)
                {
                    VertexChannelTangent = null;
                }
                if (VertexChannelNormal.HasValue && VertexChannelNormal.Value != currVertexChannelNormal)
                {
                    VertexChannelNormal = null;
                }
                if (VertexChannelUV0.HasValue && VertexChannelUV0.Value != currVertexChannelUV0)
                {
                    VertexChannelUV0 = null;
                }

                if (exportType.HasValue && exportType.Value != currExportType)
                {
                    exportType = null;
                }

                if (InvertedWorld.HasValue && InvertedWorld.Value != currInvertedWorld)
                {
                    InvertedWorld = null;
                }
                if (NoCollider.HasValue && NoCollider.Value != currNoCollider)
                {
                    NoCollider = null;
                }
                if (IsTrigger.HasValue && IsTrigger.Value != currIsTrigger)
                {
                    IsTrigger = null;
                }
                if (SetToConvex.HasValue && SetToConvex.Value != currSetToConvex)
                {
                    SetToConvex = null;
                }
                if (AutoGenerateRigidBody.HasValue && AutoGenerateRigidBody.Value != currAutoGenerateRigidBody)
                {
                    AutoGenerateRigidBody = null;
                }
                if (DoNotRender.HasValue && DoNotRender.Value != currDoNotRender)
                {
                    DoNotRender = null;
                }
                if (ReceiveShadows.HasValue && ReceiveShadows.Value != currReceiveShadows)
                {
                    ReceiveShadows = null;
                }
                if (ShadowCastingMode.HasValue && ShadowCastingMode.Value != currShadowCastingMode)
                {
                    ShadowCastingMode = null;
                }
                if (AutoRebuildUVs.HasValue && AutoRebuildUVs.Value != currAutoRebuildUVs)
                {
                    AutoRebuildUVs = null;
                }
                if (PreserveUVs.HasValue && PreserveUVs.Value != currPreserveUVs)
                {
                    PreserveUVs = null;
                }
                if (ShowGeneratedMeshes.HasValue && ShowGeneratedMeshes.Value != currShowGeneratedMeshes)
                {
                    ShowGeneratedMeshes = null;
                }

                if (defaultPhysicsMaterial != currdefaultPhysicsMaterial)
                {
                    defaultPhysicsMaterialMixed = true;
                }
            }

            GUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Behaviour");
                EditorGUI.indentLevel++;
                {
                    bool inverted_world = InvertedWorld.HasValue ? InvertedWorld.Value : false;
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = !InvertedWorld.HasValue;
                        inverted_world           = EditorGUILayout.Toggle(InvertedWorldContent, inverted_world);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            if (inverted_world)
                            {
                                models[i].Settings |= ModelSettingsFlags.InvertedWorld;
                            }
                            else
                            {
                                models[i].Settings &= ~ModelSettingsFlags.InvertedWorld;
                            }
                        }
                        GUI.changed   = true;
                        InvertedWorld = inverted_world;
                    }
                }
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            if (models != null && models.Length == 1)
            {
                GUILayout.Space(10);
                GUILayout.BeginVertical(GUI.skin.box);
                {
                    EditorGUILayout.LabelField("Export");
                    GUILayout.BeginHorizontal();
                    {
                        EditorGUI.BeginDisabledGroup(!exportType.HasValue);
                        {
                            if (GUILayout.Button("Export to ...") && exportType.HasValue)
                            {
#if !DEMO
                                MeshInstanceManager.Export(models[0], exportType.Value);
#else
                                Debug.LogWarning("Export is disabled in demo version");
#endif
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !exportType.HasValue;
                            exportType = (ExportType)EditorGUILayout.EnumPopup(exportType ?? ExportType.FBX, popupStyle);
                            EditorGUI.showMixedValue = false;
                        }
                        if (EditorGUI.EndChangeCheck() && exportType.HasValue)
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                models[i].exportType = exportType.Value;
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();
            }
            GUILayout.Space(10);
            GUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Physics");
                EditorGUI.indentLevel++;
                {
                    bool collider_value = NoCollider.HasValue ? NoCollider.Value : false;
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = !NoCollider.HasValue;
                        collider_value           = !EditorGUILayout.Toggle(GenerateColliderContent, !collider_value);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            if (collider_value)
                            {
                                models[i].Settings |= ModelSettingsFlags.NoCollider;
                            }
                            else
                            {
                                models[i].Settings &= ~ModelSettingsFlags.NoCollider;
                            }
                        }
                        GUI.changed  = true;
                        NoCollider   = collider_value;
                        updateMeshes = true;
                    }
                }
                var have_no_collider = NoCollider.HasValue && NoCollider.Value;
                EditorGUI.BeginDisabledGroup(have_no_collider);
                {
                    bool trigger_value_mixed = have_no_collider ? true : !IsTrigger.HasValue;
                    bool trigger_value       = IsTrigger.HasValue ? IsTrigger.Value : false;
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = trigger_value_mixed;
                            trigger_value            = EditorGUILayout.Toggle(ModelIsTriggerContent, trigger_value);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (trigger_value)
                                {
                                    models[i].Settings |= ModelSettingsFlags.IsTrigger;
                                }
                                else
                                {
                                    models[i].Settings &= ~ModelSettingsFlags.IsTrigger;
                                }
                            }
                            GUI.changed  = true;
                            IsTrigger    = trigger_value;
                            updateMeshes = true;
                        }
                    }
                    bool set_convex_value_mixed = have_no_collider ? true : !SetToConvex.HasValue;
                    bool set_convex_value       = have_no_collider ? false : (SetToConvex.HasValue ? SetToConvex.Value : false);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = set_convex_value_mixed;
                            var prevColor = GUI.color;
                            if (!set_convex_value && trigger_value)
                            {
                                var color = new Color(1, 0.25f, 0.25f);
                                GUI.color = color;
                            }
                            set_convex_value = EditorGUILayout.Toggle(ColliderSetToConvexContent, set_convex_value);
                            GUI.color        = prevColor;
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (set_convex_value)
                                {
                                    models[i].Settings |= ModelSettingsFlags.SetColliderConvex;
                                }
                                else
                                {
                                    models[i].Settings &= ~ModelSettingsFlags.SetColliderConvex;
                                }
                            }
                            GUI.changed  = true;
                            SetToConvex  = set_convex_value;
                            updateMeshes = true;
                        }
                    }
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = defaultPhysicsMaterialMixed;
                            GUILayout.BeginHorizontal();
                            EditorGUILayout.PrefixLabel(DefaultPhysicsMaterialContent);
                            defaultPhysicsMaterial = EditorGUILayout.ObjectField(defaultPhysicsMaterial, typeof(PhysicMaterial), true) as PhysicMaterial;
                            GUILayout.EndHorizontal();
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                models[i].DefaultPhysicsMaterial = defaultPhysicsMaterial;
                            }
                            GUI.changed = true;
                            //MeshInstanceManager.Clear();
                            updateMeshes = true;
                        }
                    }
                    if (!have_no_collider && !set_convex_value && trigger_value)
                    {
                        var prevColor = GUI.color;
                        var color     = new Color(1, 0.25f, 0.25f);
                        GUI.color = color;
                        GUILayout.Label("Warning:\r\nFor performance reasons colliders need to\r\nbe convex!");

                        GUI.color = prevColor;
                    }
                }
                EditorGUI.EndDisabledGroup();
                {
                    bool autoRigidbody = (AutoGenerateRigidBody.HasValue ? AutoGenerateRigidBody.Value : false);
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = !AutoGenerateRigidBody.HasValue;
                        autoRigidbody            = !EditorGUILayout.Toggle(ColliderAutoRigidBodyContent, !autoRigidbody);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            if (autoRigidbody)
                            {
                                models[i].Settings |= ModelSettingsFlags.AutoUpdateRigidBody;
                            }
                            else
                            {
                                models[i].Settings &= ~ModelSettingsFlags.AutoUpdateRigidBody;
                            }
                        }
                        GUI.changed           = true;
                        AutoGenerateRigidBody = autoRigidbody;
                    }
                }
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.BeginVertical(GUI.skin.box);
            {
                ShadowCastingMode shadowcastingValue = ShadowCastingMode.HasValue ? ShadowCastingMode.Value : UnityEngine.Rendering.ShadowCastingMode.On;
                var castOnlyShadow = (shadowcastingValue == UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly);
                EditorGUILayout.LabelField("Rendering");
                EditorGUI.indentLevel++;
                EditorGUI.BeginDisabledGroup(castOnlyShadow);
                {
                    bool donotrender_value = castOnlyShadow ? true : (DoNotRender.HasValue ? DoNotRender.Value : false);
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = castOnlyShadow ? true : !DoNotRender.HasValue;
                        donotrender_value        = EditorGUILayout.Toggle(DoNotRenderContent, donotrender_value);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            if (donotrender_value)
                            {
                                models[i].Settings |= ModelSettingsFlags.DoNotRender;
                            }
                            else
                            {
                                models[i].Settings &= ~ModelSettingsFlags.DoNotRender;
                            }
                        }
                        GUI.changed  = true;
                        DoNotRender  = donotrender_value;
                        updateMeshes = true;
                    }
                }
                EditorGUI.EndDisabledGroup();
                GUILayout.Space(10);
                EditorGUI.BeginDisabledGroup(DoNotRender.HasValue && DoNotRender.Value);
                {
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = !ShadowCastingMode.HasValue;
                        shadowcastingValue       = (ShadowCastingMode)EditorGUILayout.EnumPopup(CastShadows, shadowcastingValue);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            settings           = models[i].Settings;
                            settings          &= ~ModelSettingsFlags.ShadowCastingModeFlags;
                            settings          |= (ModelSettingsFlags)(((int)shadowcastingValue) & (int)ModelSettingsFlags.ShadowCastingModeFlags);
                            models[i].Settings = settings;
                        }
                        GUI.changed       = true;
                        ShadowCastingMode = shadowcastingValue;
                        updateMeshes      = true;
                    }

                    var isUsingDeferredRenderingPath = false;                    //IsUsingDeferredRenderingPath();
                    EditorGUI.BeginDisabledGroup(castOnlyShadow || isUsingDeferredRenderingPath);
                    {
                        var receiveshadowsValue = !castOnlyShadow && (isUsingDeferredRenderingPath || (ReceiveShadows ?? false));
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = (castOnlyShadow || !ReceiveShadows.HasValue) && !isUsingDeferredRenderingPath;
                            receiveshadowsValue      = EditorGUILayout.Toggle(ModelInspectorGUI.ReceiveShadowsContent, receiveshadowsValue || isUsingDeferredRenderingPath);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (receiveshadowsValue)
                                {
                                    models[i].Settings &= ~ModelSettingsFlags.DoNotReceiveShadows;
                                }
                                else
                                {
                                    models[i].Settings |= ModelSettingsFlags.DoNotReceiveShadows;
                                }
                            }
                            GUI.changed    = true;
                            ReceiveShadows = receiveshadowsValue;
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(castOnlyShadow);
                EditorGUI.showMixedValue = false;
                UpdateTargets(models);
                if (_probesInstance != null &&
                    _probesOnGUIMethod != null &&
                    _probesTargets != null &&
                    _probesInitialized)
                {
                    GUILayout.Space(10);
                    try
                    {
#if UNITY_5_6_OR_NEWER
                        _probesSerializedObject.UpdateIfRequiredOrScript();
#else
                        _probesSerializedObject.UpdateIfDirtyOrScript();
#endif
                        _probesOnGUIMethod.Invoke(_probesInstance, new System.Object[] { _probesTargets, (Renderer)_probesTargets[0], false });
                        _probesSerializedObject.ApplyModifiedProperties();
                    }
                    catch { }
                }
                EditorGUI.EndDisabledGroup();
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Lighting");
                EditorGUI.indentLevel++;
                {
                    EditorGUI.indentLevel++;
                    CommonGUI.GenerateLightmapUVButton(models);
                    EditorGUI.indentLevel--;

                    EditorGUILayout.LabelField("UV Settings");
                    EditorGUI.indentLevel++;
                    {
                        var autoRebuildUvs = AutoRebuildUVs ?? false;
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !AutoRebuildUVs.HasValue;
                            autoRebuildUvs           = EditorGUILayout.Toggle(AutoRebuildUVsContent, autoRebuildUvs);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (autoRebuildUvs)
                                {
                                    models[i].Settings |= ModelSettingsFlags.AutoRebuildUVs;
                                }
                                else
                                {
                                    models[i].Settings &= ~ModelSettingsFlags.AutoRebuildUVs;
                                }
                            }
                            GUI.changed    = true;
                            AutoRebuildUVs = autoRebuildUvs;
                            updateMeshes   = true;
                        }
                    }
                    {
                        var preserveUVs = PreserveUVs ?? false;
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !PreserveUVs.HasValue;
                            preserveUVs = EditorGUILayout.Toggle(PreserveUVsContent, preserveUVs);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (preserveUVs)
                                {
                                    models[i].Settings |= ModelSettingsFlags.PreserveUVs;
                                }
                                else
                                {
                                    models[i].Settings &= ~ModelSettingsFlags.PreserveUVs;
                                }
                            }
                            GUI.changed  = true;
                            PreserveUVs  = preserveUVs;
                            updateMeshes = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Mesh (advanced)");
                EditorGUI.indentLevel++;
                {
                    var showGeneratedMeshes = ShowGeneratedMeshes ?? false;
                    EditorGUI.BeginChangeCheck();
                    {
                        EditorGUI.showMixedValue = !ShowGeneratedMeshes.HasValue;
                        showGeneratedMeshes      = EditorGUILayout.Toggle(ShowGeneratedMeshesContent, showGeneratedMeshes);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < models.Length; i++)
                        {
                            models[i].ShowGeneratedMeshes = showGeneratedMeshes;
                            MeshInstanceManager.UpdateGeneratedMeshesVisibility(models[i]);
                        }
                    }
                    GUILayout.Space(10);

                    EditorGUILayout.LabelField("Used Vertex Channels");
                    EditorGUI.indentLevel++;
                    {
                        var vertex_channel_color   = VertexChannelColor ?? false;
                        var vertex_channel_tangent = VertexChannelTangent ?? false;
                        var vertex_channel_normal  = VertexChannelNormal ?? false;
                        var vertex_channel_UV0     = VertexChannelUV0 ?? false;
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = !VertexChannelColor.HasValue;
                            vertex_channel_color     = EditorGUILayout.Toggle(VertexChannelColorContent, vertex_channel_color);

                            EditorGUI.showMixedValue = !VertexChannelTangent.HasValue;
                            vertex_channel_tangent   = EditorGUILayout.Toggle(VertexChannelTangentContent, vertex_channel_tangent);

                            EditorGUI.showMixedValue = !VertexChannelNormal.HasValue;
                            vertex_channel_normal    = EditorGUILayout.Toggle(VertexChannelNormalContent, vertex_channel_normal);

                            EditorGUI.showMixedValue = !VertexChannelUV0.HasValue;
                            vertex_channel_UV0       = EditorGUILayout.Toggle(VertexChannelUV1Content, vertex_channel_UV0);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            for (int i = 0; i < models.Length; i++)
                            {
                                var vertexChannel = models[i].VertexChannels;
                                vertexChannel &= ~(VertexChannelFlags.Color |
                                                   VertexChannelFlags.Tangent |
                                                   VertexChannelFlags.Normal |
                                                   VertexChannelFlags.UV0);

                                if (vertex_channel_color)
                                {
                                    vertexChannel |= VertexChannelFlags.Color;
                                }
                                if (vertex_channel_tangent)
                                {
                                    vertexChannel |= VertexChannelFlags.Tangent;
                                }
                                if (vertex_channel_normal)
                                {
                                    vertexChannel |= VertexChannelFlags.Normal;
                                }
                                if (vertex_channel_UV0)
                                {
                                    vertexChannel |= VertexChannelFlags.UV0;
                                }
                                models[i].VertexChannels = vertexChannel;
                            }
                            GUI.changed = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            if (models != null && models.Length == 1)
            {
                GUILayout.Space(10);

                GUILayout.BeginVertical(GUI.skin.box);
                _showDetails = EditorGUILayout.BeginToggleGroup("Statistics", _showDetails);
                if (_showDetails)
                {
                    var model_cache = InternalCSGModelManager.GetModelCache(models[0]);
                    if (model_cache == null ||
                        model_cache.GeneratedMeshes == null ||
                        !model_cache.GeneratedMeshes)
                    {
                        GUILayout.Label("Could not find model cache for this model.");
                    }
                    else
                    {
                        var meshContainer = model_cache.GeneratedMeshes;


                        var totalTriangles = 0;
                        var totalVertices  = 0;
                        var totalMeshes    = 0;

                        var materialMeshes = new Dictionary <Material, List <MeshData> >();
                        foreach (var instance in meshContainer.meshInstances.Values)
                        {
                            var mesh = instance.SharedMesh;
                            if (!MeshInstanceManager.HasVisibleMeshRenderer(instance))
                            {
                                continue;
                            }

                            List <MeshData> meshes;
                            if (!materialMeshes.TryGetValue(instance.RenderMaterial, out meshes))
                            {
                                meshes = new List <MeshData>();
                                materialMeshes[instance.RenderMaterial] = meshes;
                            }

                            var meshData = new MeshData();
                            meshData.Mesh          = mesh;
                            meshData.VertexCount   = mesh.vertexCount;
                            meshData.TriangleCount = mesh.triangles.Length / 3;
                            meshes.Add(meshData);

                            totalVertices += meshData.VertexCount;
                            totalTriangles = meshData.TriangleCount;
                            totalMeshes++;
                        }
                        EditorGUI.indentLevel++;
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("total:");
                        EditorGUILayout.LabelField("vertices: " + totalVertices + "  triangles: " + totalTriangles + "  materials: " + materialMeshes.Count + "  meshes: " + totalMeshes);
                        GUILayout.Space(10);
                        EditorGUILayout.LabelField("meshes:");
                        foreach (var item in materialMeshes)
                        {
                            var material = item.Key;
                            var meshes   = item.Value;

                            GUILayout.BeginHorizontal();
                            {
                                EditorGUI.BeginDisabledGroup(true);
                                {
                                    EditorGUILayout.ObjectField(material, typeof(Material), true);
                                }
                                GUILayout.BeginVertical();
                                {
                                    if (meshes.Count == 1)
                                    {
                                        EditorGUILayout.ObjectField(meshes[0].Mesh, typeof(Mesh), true);
                                        EditorGUILayout.LabelField("vertices " + meshes[0].VertexCount + "  triangles " + meshes[0].TriangleCount);
                                    }
                                    else
                                    {
                                        for (int i = 0; i < meshes.Count; i++)
                                        {
                                            EditorGUILayout.ObjectField(meshes[i].Mesh, typeof(Mesh), true);
                                            EditorGUILayout.LabelField("vertices " + meshes[i].VertexCount + "  triangles " + meshes[i].TriangleCount);
                                        }
                                    }
                                }
                                GUILayout.EndVertical();
                                EditorGUI.EndDisabledGroup();
                            }
                            GUILayout.EndHorizontal();
                            EditorGUILayout.Space();
                        }
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUILayout.EndToggleGroup();
                GUILayout.EndVertical();
            }
            EditorGUI.showMixedValue = false;
            if (updateMeshes)
            {
                InternalCSGModelManager.DoForcedMeshUpdate();
                SceneViewEventHandler.ResetUpdateRoutine();
            }
        }
Ejemplo n.º 7
0
        public void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            _showEntireMenu = EditorGUILayout.Foldout(_showEntireMenu, "LSDR Dream Editor",
                                                      new GUIStyle("foldout")
            {
                fontStyle = FontStyle.Bold
            });
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Import", GUILayout.Width(100)))
            {
                importExistingDream();
            }
            if (GUILayout.Button("Export", GUILayout.Width(100)))
            {
                var path = EditorUtility.SaveFilePanel("Export dream", "", _dream.Name + ".json", "json");

                if (!string.IsNullOrEmpty(path))
                {
                    _serializer.Serialize(_dream, path);
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel++;

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            if (_showEntireMenu)
            {
                EditorGUILayout.LabelField("Metadata", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                _dream.Name = EditorGUILayout.TextField(new GUIContent("Name", "The name of this dream"),
                                                        _dream.Name);
                _dream.Author = EditorGUILayout.TextField(new GUIContent("Author", "The author of this dream"),
                                                          _dream.Author);
                _dream.Type = (DreamType)EditorGUILayout.EnumPopup(
                    new GUIContent("Type", "The type of this dream, used to determine how to load the dream"),
                    _dream.Type);
                if (_dream.Type == DreamType.Legacy)
                {
                    _dream.LegacyTileMode = (LegacyTileMode)EditorGUILayout.EnumPopup(
                        new GUIContent("Tile mode", "The tiling mode of this dream"), _dream.LegacyTileMode);
                }

                if (_dream.LegacyTileMode == LegacyTileMode.Horizontal)
                {
                    _dream.TileWidth = EditorGUILayout.IntField(
                        new GUIContent("Tile width", "The width of the tile map"),
                        _dream.TileWidth);
                }

                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("Graph", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                _dream.Upperness = EditorGUILayout.IntSlider(
                    new GUIContent("Upperness",
                                   "What effect this dream has on the 'upper' axis of the graph, when visited"), _dream.Upperness,
                    -9,
                    9);

                _dream.Dynamicness = EditorGUILayout.IntSlider(
                    new GUIContent("Dynamicness",
                                   "What effect this dream has on the 'dynamic' axis of the graph, when visited"),
                    _dream.Dynamicness,
                    -9,
                    9);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;

                _dream.Level = CommonGUI.BrowseFileField(new GUIContent("Level",
                                                                        "The path to the raw level file within the game's data to load for this dream."), _dream.Level,
                                                         "Choose a level file", new[] { "Torii map files", "tmap" });

                if (_dream.Type == DreamType.Legacy)
                {
                    _dream.LBDFolder = CommonGUI.BrowseFolderField(
                        new GUIContent("LBD folder", "The path to the LBD folder to load for this Dream."),
                        _dream.LBDFolder, "Choose an LBD folder.");
                }

                // only enable the button if the dream level has a value
                using (new EditorGUI.DisabledScope(string.IsNullOrWhiteSpace(_dream.Level)))
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Edit level", GUILayout.Width(200)))
                    {
                        var editor = LevelEditor.Create();
                        editor.EditLevel(_dream.Level);
                        if (_dream.Type == DreamType.Legacy)
                        {
                            editor.LoadLBD(_dream);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("Gameplay", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                _dream.GreyMan =
                    EditorGUILayout.Toggle(
                        new GUIContent("Grey man", "Whether or not this dream can spawn the grey man"),
                        _dream.GreyMan);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Environment", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add"))
                {
                    addNewDreamEnvironment();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel++;
                for (int i = 0; i < _dream.Environments.Count; i++)
                {
                    drawDreamEnvironmentGUI(i);
                }

                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndScrollView();

            EditorGUI.indentLevel--;
        }
Ejemplo n.º 8
0
        static void OnGUIContents(bool isSceneGUI, ObjectEditBrushTool tool)
        {
            CommonGUI.StartToolGUI();

            var filteredSelection   = CSGBrushEditorManager.FilteredSelection;
            var defaultMoveOffset   = CSGSettings.DefaultMoveOffset;
            var defaultRotateOffset = CSGSettings.DefaultRotateOffset;
            var displayNewCenter    = GridUtility.CleanPosition((Tools.pivotRotation == PivotRotation.Local) ?
                                                                tool.LocalSpacePivotCenter :
                                                                tool.WorldSpacePivotCenter);

            GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
            {
                GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                {
                    HandleCSGOperations(isSceneGUI, tool, filteredSelection);
                    GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUI.BeginDisabledGroup(!tool.HaveSelection);
                        {
                            if (Tools.current == Tool.Move)
                            {
                                EditorGUI.BeginDisabledGroup(defaultMoveOffset.sqrMagnitude < MathConstants.EqualityEpsilonSqr);
                                {
                                    if (GUILayout.Button(MoveByOffsetContent))
                                    {
                                        tool.MoveByOffset(RealtimeCSG.CSGSettings.DefaultMoveOffset);
                                    }
                                    TooltipUtility.SetToolTip(MoveByOffsetTooltip);
                                    if (GUILayout.Button(CloneMoveByOffsetContent))
                                    {
                                        tool.CloneMoveByOffset(RealtimeCSG.CSGSettings.DefaultMoveOffset);
                                    }
                                    TooltipUtility.SetToolTip(CloneMoveByOffsetTooltip);
                                }
                                EditorGUI.EndDisabledGroup();
                            }
                            else
                            if (Tools.current == Tool.Rotate)
                            {
                                EditorGUI.BeginDisabledGroup(defaultMoveOffset.sqrMagnitude < MathConstants.EqualityEpsilonSqr);
                                {
                                    if (GUILayout.Button(RotateByOffsetContent))
                                    {
                                        tool.RotateByOffset(Quaternion.Euler(RealtimeCSG.CSGSettings.DefaultRotateOffset));
                                    }
                                    TooltipUtility.SetToolTip(RotateByOffsetTooltip);
                                    if (GUILayout.Button(CloneRotateByOffsetContent))
                                    {
                                        tool.CloneRotateByOffset(Quaternion.Euler(RealtimeCSG.CSGSettings.DefaultRotateOffset));
                                    }
                                    TooltipUtility.SetToolTip(CloneRotateByOffsetTooltip);
                                }
                                EditorGUI.EndDisabledGroup();
                                if (GUILayout.Button(RecenterPivotContent))
                                {
                                    tool.RecenterPivot();
                                }
                                TooltipUtility.SetToolTip(RecenterPivotTooltip);
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(5);
                if (Tools.current == Tool.Move)
                {
                    var doubleFieldOptions = isSceneGUI ? MaxWidth150 : GUIStyleUtility.ContentEmpty;
                    EditorGUI.BeginDisabledGroup(!tool.HaveSelection);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label("Offset");
                            defaultMoveOffset = GUIStyleUtility.DistanceVector3Field(defaultMoveOffset, false, doubleFieldOptions);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            RealtimeCSG.CSGSettings.DefaultMoveOffset = defaultMoveOffset;
                            RealtimeCSG.CSGSettings.Save();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                if (Tools.current == Tool.Rotate)
                {
                    var doubleFieldOptions = isSceneGUI ? MaxWidth150 : GUIStyleUtility.ContentEmpty;
                    EditorGUI.BeginDisabledGroup(Tools.pivotMode == PivotMode.Center || !tool.HaveSelection);
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label("Offset");
                            defaultRotateOffset = GUIStyleUtility.EulerDegreeField(defaultRotateOffset);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            RealtimeCSG.CSGSettings.DefaultRotateOffset = defaultRotateOffset;
                            RealtimeCSG.CSGSettings.Save();
                        }

                        EditorGUI.BeginChangeCheck();
                        {
                            GUILayout.Label("Pivot");
                            displayNewCenter = GUIStyleUtility.DistanceVector3Field(displayNewCenter, false, doubleFieldOptions);
                            TooltipUtility.SetToolTip(PivotVectorTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Tools.pivotRotation == PivotRotation.Local)
                            {
                                tool.LocalSpacePivotCenter = displayNewCenter;
                            }
                            else
                            {
                                tool.WorldSpacePivotCenter = displayNewCenter;
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }

                /*
                 * if (Tools.current != Tool.Rotate)
                 * {
                 *      if (!isSceneGUI || !SceneView.currentDrawingSceneView.camera.orthographic)
                 *      {
                 *              if (!isSceneGUI)
                 *              {
                 *                      GUILayout.Space(10);
                 *                      GUILayout.Label("Tips", EditorStyles.miniLabel);
                 *              }
                 *
                 *              GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                 *              {
                 *                      GUILayout.Label(Keys.VerticalMoveMode.ToString() + " to drag brush up/down", EditorStyles.miniLabel);
                 *              }
                 *              GUILayout.EndVertical();
                 *      }
                 * }
                 */
            }
            GUILayout.EndVertical();
            EditorGUI.showMixedValue = false;
        }
Ejemplo n.º 9
0
        static void OnGUIContents(GenerateBrushTool tool, bool isSceneGUI, float height)
        {
            if (!isSceneGUI)
            {
                Rect shapeModeBounds;
                var  csg_skin = GUIStyleUtility.Skin;
                tool.BuilderMode = (ShapeMode)GUIStyleUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: GUIStyleUtility.shapeModeTooltips, yOffset: height, areaWidth: EditorGUIUtility.currentViewWidth - 4);
                GUILayout.Space(shapeModeBounds.height);

                CommonGUI.StartToolGUI();

                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                {
                    ChooseOperation(tool, isSceneGUI);
                    tool.CurrentGenerator.OnShowGUI(isSceneGUI);
                    CommitOrCancel(isSceneGUI, tool);
                    EditorGUILayout.Space();
                    var defaultMaterial = CSGSettings.DefaultMaterial;
                    GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                    {
                        EditorGUILayout.LabelField(ContentDefaultMaterial, largeLabelWidth);
                        GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = EditorGUILayout.ObjectField(defaultMaterial, typeof(Material), true) as Material;
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                tool.CurrentGenerator.OnDefaultMaterialModified();
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty);
                        {
                            GUILayout.Space(5);
                            EditorGUI.BeginChangeCheck();
                            {
                                defaultMaterial = GUIStyleUtility.MaterialImage(defaultMaterial, small: false);
                            }
                            if (EditorGUI.EndChangeCheck() && defaultMaterial)
                            {
                                CSGSettings.DefaultMaterial = defaultMaterial;
                                tool.CurrentGenerator.OnDefaultMaterialModified();
                                CSGSettings.Save();
                            }
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();

                    /*
                     * // Unity won't let us do this
                     * GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                     * OnGUIContentsMaterialInspector(first_material, multiple_materials);
                     * GUILayout.EndVertical();
                     */
                }
                EditorGUILayout.EndScrollView();
            }
            if (isSceneGUI)
            {
                GUILayout.BeginHorizontal(GUILayout.MinHeight(100));
                {
                    GUILayout.BeginVertical(GUILayout.Width(100));
                    {
                        GUILayout.FlexibleSpace();

                        var rect = GUILayoutUtility.GetLastRect();

                        var  csg_skin = GUIStyleUtility.Skin;
                        Rect shapeModeBounds;
                        tool.BuilderMode = (ShapeMode)GUIStyleUtility.ToolbarWrapped((int)tool.BuilderMode, ref shapeModeRects, out shapeModeBounds, csg_skin.shapeModeNames, tooltips: GUIStyleUtility.shapeModeTooltips, yOffset: rect.y, areaWidth: 100);
                        GUILayout.Space(shapeModeBounds.height);

                        ChooseOperation(tool, isSceneGUI);
                    }
                    GUILayout.EndVertical();
                    GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty);
                    {
                        tool.CurrentGenerator.OnShowGUI(isSceneGUI);
                        GUILayout.FlexibleSpace();
                        CommitOrCancel(isSceneGUI, tool);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
        }
Ejemplo n.º 10
0
		private void retractableBar_StateChanged(object sender, CommonGUI.RetractableBar.StateChangedEventArgs e)
		{
			if (!_selectedOutput.AllowToSave) return;
			_selectedOutput.ShowOptions = e.Expaned;
			_selectedOutput.SaveView();
		}