Exemplo n.º 1
0
        public static Bounds OnGetFrameBounds(FilteredSelection filteredSelection)
        {
            var brushes = filteredSelection.GetAllContainedBrushes();
            var bounds  = new Bounds();

            if (brushes.Count == 0)
            {
                foreach (var node in filteredSelection.NodeTargets)
                {
                    bounds.Encapsulate(node.transform.position);
                }
            }
            else
            {
                foreach (var brush in brushes)
                {
                    var transform   = brush.GetComponent <Transform>();
                    var controlMesh = brush.ControlMesh;
                    bounds.center = transform.TransformPoint(controlMesh.Vertices[0]);
                    bounds.size   = MathConstants.zeroVector3;
                    for (int i = 1; i < controlMesh.Vertices.Length; i++)
                    {
                        bounds.Encapsulate(transform.TransformPoint(controlMesh.Vertices[i]));
                    }
                }
            }
            // TODO: how to get bounds of random selected objects??
            //foreach (var other in filteredSelection.targetOthers)
            //{
            //	bounds.Encapsulate(...);
            //}
            return(bounds);
        }
Exemplo n.º 2
0
 public void SetTargets(FilteredSelection filteredSelection)
 {
     hideTool = filteredSelection.NodeTargets.Length > 0;
     brushes  = filteredSelection.GetAllContainedBrushes().ToArray();
     lastLineMeshGeneration--;
     if (isEnabled)
     {
         Tools.hidden = hideTool;
     }
 }
Exemplo n.º 3
0
        static void ShowCSGOperations(bool isSceneGUI, EditModePlace tool, FilteredSelection filteredSelection)
        {
            bool operations_enabled = (tool != null &&
                                       filteredSelection.NodeTargets.Length > 0 &&
                                       filteredSelection.NodeTargets.Length == (filteredSelection.BrushTargets.Length + filteredSelection.OperationTargets.Length));

            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 (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues))
                        {
                            Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes");
                            foreach (var operation in filteredSelection.OperationTargets)
                            {
                                operation.PassThrough = true;
                            }
                            InternalCSGModelManager.CheckForChanges();
                            EditorApplication.RepaintHierarchyWindow();
                        }

                        if (passThroughValue)
                        {
                            operationType = (CSGOperationType)255;
                        }
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        operationType = CSG_EditorGUIUtility.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.CheckForChanges();
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
Exemplo n.º 4
0
 public static bool HasFrameBounds(FilteredSelection filteredSelection)
 {
     return(filteredSelection.NodeTargets.Length > 0);
 }