protected override void InternalOnInspectorGUI()
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("distance"));

            var distanceRatio = Cursor.DistanceRatio;
            var newValue      = EditorGUILayout.Slider("Distance Ratio", distanceRatio, 0, 1);

            if (BGEditorUtility.AnyChange(distanceRatio, newValue))
            {
                Cursor.DistanceRatio = newValue;
            }
        }
        // OnSceneGui
        public void Scene(Quaternion rotation)
        {
            if (lastCurveCount != curve.PointsCount)
            {
                lastCurveCount = curve.PointsCount;
                OnUndoRedo();
            }

            if (!HasSelected())
            {
                return;
            }

            BGEditorUtility.Assign(ref settings, () => editor.Settings);

            //group operation for selected points
            var text    = " Selected points [" + points.Count + "]";
            var average = GetAveragePosition();

            Handles.Label(editor.GetLabelPosition(settings, average), text, new GUIStyle("Label")
            {
                normal = new GUIStyleState {
                    textColor = settings.LabelColorSelected
                }
            });

            var newAverage = editor.Handle(-10, settings.HandlesType, average, rotation, settings.HandlesSettings);

            if (BGEditorUtility.AnyChange(average, newAverage))
            {
                curve.Transaction(() =>
                {
                    var delta = newAverage - average;
                    foreach (var selectedPoint in points)
                    {
                        selectedPoint.PositionWorld += delta;
                    }
                });
            }
        }
        public void OnSceneGUI(BGCurvePointI point, int index, BGCurveSettings settings, Quaternion rotation, Plane[] frustum)
        {
            var math          = mathProvider();
            var positionWorld = math == null ? point.Curve[index].PositionWorld : math.GetPosition(index);

            //adjust rotation
            if (point.PointTransform != null)
            {
                rotation = BGCurveEditorPoints.GetRotation(point.PointTransform);
            }
            else if (point.Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsTransform)
            {
                rotation = BGCurveEditorPoints.GetRotation(((BGCurvePointGO)point).transform);
            }

            var isShowingGizmoz = settings.RestrictGizmozSettings.IsShowing(index);

            if (settings.ShowControlHandles && settings.ShowCurve && (editorSelection == null || !editorSelection.HasSelected() || editorSelection.SingleSelected(point)))
            {
                // ============================================== Controls Handles
                if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
                {
                    if (isShowingGizmoz)
                    {
                        var controlFirstWorld  = math == null ? point.Curve[index].ControlFirstWorld : math.GetControlFirst(index);
                        var controlSecondWorld = math == null ? point.Curve[index].ControlSecondWorld : math.GetControlSecond(index);

                        BGEditorUtility.SwapHandlesColor(settings.ControlHandlesColor, () =>
                        {
                            Handles.DrawLine(positionWorld, controlFirstWorld);
                            Handles.DrawLine(positionWorld, controlSecondWorld);

                            if (ShowingHandles)
                            {
                                // control handles different types
                                var newPositionFirst  = BGEditorUtility.Handle(GetUniqueNumber(index) - 1, settings.ControlHandlesType, controlFirstWorld, rotation, settings.ControlHandlesSettings);
                                var newPositionSecond = BGEditorUtility.Handle(GetUniqueNumber(index) - 2, settings.ControlHandlesType, controlSecondWorld, rotation, settings.ControlHandlesSettings);

                                if (BGEditorUtility.AnyChange(controlFirstWorld, newPositionFirst))
                                {
                                    point.ControlFirstWorld = newPositionFirst;
                                }
                                if (BGEditorUtility.AnyChange(controlSecondWorld, newPositionSecond))
                                {
                                    point.ControlSecondWorld = newPositionSecond;
                                }
                            }
                        });

                        if (settings.ShowControlLabels)
                        {
                            ShowControlLabel(settings, frustum, controlFirstWorld, point.ControlFirstLocal, "1");
                            ShowControlLabel(settings, frustum, controlSecondWorld, point.ControlSecondLocal, "2");
                        }
                    }
                }
            }

            //if only one point is selected and this is the selected point- do not print anything further
            if (editorSelection != null && editorSelection.HasSelected() && editorSelection.SingleSelected(point))
            {
                return;
            }

            // ============================================== Move Handles
            if ((editorSelection == null || !editorSelection.HasSelected()) && settings.ShowCurve && settings.ShowHandles && ShowingHandles && isShowingGizmoz)
            {
                var newPos = BGEditorUtility.Handle(GetUniqueNumber(index), settings.HandlesType, positionWorld, rotation, settings.HandlesSettings);

                if (BGEditorUtility.AnyChange(positionWorld, newPos))
                {
                    point.PositionWorld = newPos;
                }
            }
        }
        //OnInspectorGui for selection
        public void InspectorSelectionOperations()
        {
            BGEditorUtility.VerticalBox(() =>
            {
                // ================================================ Global operations
                BGEditorUtility.HorizontalBox(() =>
                {
                    BGEditorUtility.SwapLabelWidth(80, () => EditorGUILayout.LabelField("Selected (" + points.Count + ")"));

                    if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete selected points"))
                    {
                        if (!DeleteSelected())
                        {
                            return;
                        }
                    }

                    GUILayout.Space(4);
                    if (BGEditorUtility.ButtonWithIcon(selectAllTexture, "Select all points", 35))
                    {
                        Changed = Changed || points.Count != curve.PointsCount;

                        points.Clear();

                        foreach (var point1 in curve.Points)
                        {
                            points.Add(point1);
                        }
                    }

                    GUILayout.Space(4);

                    if (BGEditorUtility.ButtonWithIcon(deselectAllTexture, "Deselect all points", 35))
                    {
                        Clear();
                    }
                });


                // ================================================ Selections operations
                // skip mouse buttons events which change selection
                if (Changed)
                {
                    return;
                }

                GUILayout.Space(5);
                if (HasSelected())
                {
                    BGEditorUtility.SwapGuiBackgroundColor(SelectedBackgroundColor, () =>
                    {
                        BGEditorUtility.VerticalBox(() =>
                        {
                            var averagePositionSelected = GetAveragePosition();

                            // =====================================================  Control handles
                            BGEditorUtility.Horizontal(() =>
                            {
                                controlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Controls", controlType);
                                if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "Set control type for all selected points", 44))
                                {
                                    return;
                                }

                                SetControlTypeForSelected(controlType);
                            });

                            // =====================================================  Average positions & delete
                            BGEditorUtility.Vector3Field("Average position", "Average points position. Change several points positions at once, keeping distance difference intact",
                                                         averagePositionSelected,
                                                         newAverage =>
                            {
                                var delta = newAverage - averagePositionSelected;
                                curve.Transaction(() => { foreach (var point in points)
                                                          {
                                                              point.PositionWorld += delta;
                                                          }
                                                  });
                            });
                            // =====================================================  Set position directly
                            BGEditorUtility.Vector3Field("Set position", "Set points position directly",
                                                         averagePositionSelected,
                                                         newPosition =>
                            {
                                curve.Transaction(() =>
                                {
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.x, newPosition.x))
                                    {
                                        SetX(newPosition.x);
                                    }
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.y, newPosition.y))
                                    {
                                        SetY(newPosition.y);
                                    }
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.z, newPosition.z))
                                    {
                                        SetZ(newPosition.z);
                                    }
                                });
                            });

                            // =====================================================  Set control positions directly
                            var count = 0;
                            var averageControl1Sum = Vector3.zero;
                            var averageControl2Sum = Vector3.zero;
                            foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                            {
                                count++;
                                averageControl1Sum += point.ControlFirstLocal;
                                averageControl2Sum += point.ControlSecondLocal;
                            }

                            if (count == 0)
                            {
                                return;
                            }

                            //has points with bezier controls
                            BGEditorUtility.Vector3Field("Set Control 1", "Set 1st control position directly",
                                                         averageControl1Sum / count,
                                                         newPosition =>
                            {
                                curve.Transaction(
                                    () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                                            {
                                                point.ControlFirstLocal = newPosition;
                                            }
                                    });
                            });

                            BGEditorUtility.Vector3Field("Set Control 2", "Set 2nd control position directly",
                                                         averageControl2Sum / count,
                                                         newPosition =>
                            {
                                curve.Transaction(
                                    () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                                            {
                                                point.ControlSecondLocal = newPosition;
                                            }
                                    });
                            });
                        });
                    });
                }
                else
                {
                    BGEditorUtility.HelpBox("Hold shift to use rectangular selection\r\nClick or click+drag over tick icons to (de)select points", MessageType.Info, curve.PointsCount > 0);
                }
            });
        }
예제 #5
0
        public void OnSceneGUI(BGCurvePoint point, int index, BGCurveSettings settings, Quaternion rotation, Plane[] frustum)
        {
            var math          = editor.Editor.Math;
            var positionWorld = math.GetPosition(index);

            if (settings.ShowControlHandles && settings.ShowCurve && (!editorSelection.HasSelected() || editorSelection.SingleSelected(point)))
            {
                // ============================================== Controls Handles
                if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
                {
                    var controlFirstWorld  = math.GetControlFirst(index);
                    var controlSecondWorld = math.GetControlSecond(index);

                    BGEditorUtility.SwapHandlesColor(settings.ControlHandlesColor, () =>
                    {
                        Handles.DrawLine(positionWorld, controlFirstWorld);
                        Handles.DrawLine(positionWorld, controlSecondWorld);

                        // control handles different types
                        var newPositionFirst  = editor.Handle(GetUniqueNumber(index) - 1, settings.ControlHandlesType, controlFirstWorld, rotation, settings.ControlHandlesSettings);
                        var newPositionSecond = editor.Handle(GetUniqueNumber(index) - 2, settings.ControlHandlesType, controlSecondWorld, rotation, settings.ControlHandlesSettings);

                        if (BGEditorUtility.AnyChange(controlFirstWorld, newPositionFirst))
                        {
                            point.ControlFirstWorld = newPositionFirst;
                        }
                        if (BGEditorUtility.AnyChange(controlSecondWorld, newPositionSecond))
                        {
                            point.ControlSecondWorld = newPositionSecond;
                        }
                    });

                    if (settings.ShowControlLabels)
                    {
                        ShowControlLabel(settings, frustum, controlFirstWorld, point.ControlFirstLocal, "1");
                        ShowControlLabel(settings, frustum, controlSecondWorld, point.ControlSecondLocal, "2");
                    }
                }
            }

            //if only one point is selected and this is the selected point- do not print anything further
            if (editorSelection.HasSelected() && editorSelection.SingleSelected(point))
            {
                return;
            }

            // ============================================== Labels & Positions
            if (settings.ShowLabels && GeometryUtility.TestPlanesAABB(frustum, new Bounds(positionWorld, Vector3.one)))
            {
                Handles.Label(editor.GetLabelPosition(settings, positionWorld), "Point " + index + (settings.ShowPositions ? " " + positionWorld : ""),
                              editorSelection.Contains(point) ? selectedPositionLabelStyle : positionLabelStyle);
            }

            // ============================================== Move Handles
            if (!editorSelection.HasSelected() && settings.ShowCurve && settings.ShowHandles)
            {
                var newPos = editor.Handle(GetUniqueNumber(index), settings.HandlesType, positionWorld, rotation, settings.HandlesSettings);

                if (BGEditorUtility.AnyChange(positionWorld, newPos))
                {
                    point.PositionWorld = newPos;
                }
            }
        }