예제 #1
0
        // OnSceneGui
        public void Scene(Quaternion rotation)
        {
            if (lastCurveCount != curve.PointsCount)
            {
                lastCurveCount = curve.PointsCount;
                OnUndoRedo();
            }

            if (!HasSelected())
            {
                return;
            }

            BGEditorUtility.Assign(ref settings, () => BGPrivateField.GetSettings(curve));

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

            Handles.Label(average + BGEditorUtility.GetHandleSize(average) * Vector3.up * .25f, text, new GUIStyle("Label")
            {
                normal = new GUIStyleState {
                    textColor = settings.LabelColorSelected
                }
            });

            var newAverage = BGEditorUtility.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;
                }
            }
        }