Пример #1
0
        static void ChooseOperation(GenerateBrushTool tool, bool isSceneGUI)
        {
            var  generator = tool.CurrentGenerator;
            bool enabled   = generator.HaveBrushes;

            EditorGUI.BeginDisabledGroup(!enabled);
            {
                if (isSceneGUI)
                {
                    GUILayout.BeginVertical(GUI.skin.box, Width100);
                }
                else
                {
                    GUILayout.BeginVertical(GUIStyle.none);
                }
                {
                    bool             mixedValues = !enabled;
                    CSGOperationType operation   = generator.CurrentCSGOperationType;
                    EditorGUI.BeginChangeCheck();
                    operation = GUIStyleUtility.ChooseOperation(operation, mixedValues);
                    if (EditorGUI.EndChangeCheck())
                    {
                        generator.CurrentCSGOperationType = operation;
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
Пример #2
0
        static void ChooseCSGOperation(FilteredSelection filteredSelection, bool isSceneGUI, MeshEditBrushTool tool)
        {
            bool operations_enabled = tool != null &&
                                      (filteredSelection.NodeTargets.Length > 0 && filteredSelection.ModelTargets.Length == 0);

            EditorGUI.BeginDisabledGroup(!operations_enabled);
            {
                bool             mixedValues   = tool == null || ((filteredSelection.BrushTargets.Length == 0) && (filteredSelection.OperationTargets.Length == 0));
                CSGOperationType operationType = CSGOperationType.Additive;
                if (tool != null)
                {
                    if (filteredSelection.BrushTargets.Length > 0)
                    {
                        operationType = filteredSelection.BrushTargets[0].OperationType;
                        for (int i = 1; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            if (filteredSelection.BrushTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                    else
                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        operationType = filteredSelection.OperationTargets[0].OperationType;
                    }

                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (filteredSelection.OperationTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                }

                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    bool passThroughValue = false;
                    if (tool != null &&
                        //filteredSelection.BrushTargets.Length == 0 &&
                        filteredSelection.OperationTargets.Length > 0 &&
                        filteredSelection.OperationTargets.Length == filteredSelection.NodeTargets.Length)                         // only operations
                    {
                        bool?passThrough = filteredSelection.OperationTargets[0].PassThrough;
                        for (int i = 1; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (passThrough.HasValue && passThrough.Value != filteredSelection.OperationTargets[i].PassThrough)
                            {
                                passThrough = null;
                                break;
                            }
                        }

                        mixedValues = !passThrough.HasValue || passThrough.Value;

                        var ptMixedValues = !passThrough.HasValue;
                        passThroughValue = passThrough.HasValue ? passThrough.Value : false;
                        if (GUIStyleUtility.PassThroughButton(passThroughValue, ptMixedValues))
                        {
                            Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes");
                            foreach (var operation in filteredSelection.OperationTargets)
                            {
                                operation.PassThrough = true;
                            }
                            InternalCSGModelManager.Refresh();
                            EditorApplication.RepaintHierarchyWindow();
                        }

                        if (passThroughValue)
                        {
                            operationType = (CSGOperationType)255;
                        }
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        operationType = GUIStyleUtility.ChooseOperation(operationType, mixedValues);
                    }
                    if (EditorGUI.EndChangeCheck() && tool != null)
                    {
                        Undo.RecordObjects(filteredSelection.NodeTargets, "Changed CSG operation of nodes");
                        for (int i = 0; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            filteredSelection.BrushTargets[i].OperationType = operationType;
                        }
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            filteredSelection.OperationTargets[i].PassThrough   = false;
                            filteredSelection.OperationTargets[i].OperationType = operationType;
                        }
                        InternalCSGModelManager.Refresh();
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }