コード例 #1
0
        protected virtual void OnEnable()
        {
            point = Point;

            pointEditor = new BGCurveEditorPoint(() => null, null);

            if (curveEditor != null)
            {
                curveEditor.OnDestroy();
            }

            curveEditor = (BGCurveEditor)CreateEditor(point.Curve);

            PointSelected = true;
        }
コード例 #2
0
        protected virtual void OnEnable()
        {
            point = Point;

            pointEditor = new BGCurveEditorPoint(() => null, null);

            if (curveEditor != null)
            {
                curveEditor.OnDestroy();
            }

            curveEditor = (BGCurveEditor)CreateEditor(point.Curve);

            pointSelectedTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointSelected123);

            PointSelected = true;
        }
コード例 #3
0
        public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject serializedObject, BGCurveEditorPointsSelection editorSelection)
            : base(editor, serializedObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123))
        {
            this.serializedObject = serializedObject;
            this.editorSelection  = editorSelection;

            //textures
            convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123);
            addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);

            //point
            editorPoint = new BGCurveEditorPoint(() => Editor.Math, editorSelection);

            //closed or not
            closedProperty = serializedObject.FindProperty("closed");

            //how points are stored
            pointsModeProperty = serializedObject.FindProperty("pointsMode");

            //2d mode
            mode2DProperty = serializedObject.FindProperty("mode2D");

            //snapping
            snapTypeProperty               = serializedObject.FindProperty("snapType");
            snapAxisProperty               = serializedObject.FindProperty("snapAxis");
            snapDistanceProperty           = serializedObject.FindProperty("snapDistance");
            snapTriggerInteractionProperty = serializedObject.FindProperty("snapTriggerInteraction");
            snapToBackFacesProperty        = serializedObject.FindProperty("snapToBackFaces");
            snapMonitoringProperty         = serializedObject.FindProperty("snapMonitoring");

            //force update
            forceChangedEventModeProperty = serializedObject.FindProperty("forceChangedEventMode");

            //event type
            eventModeProperty = serializedObject.FindProperty("eventMode");

            //settings
            controlTypeProperty = serializedObject.FindProperty("settings").FindPropertyRelative("controlType");

            //Context menu
            overlay = new BGSceneViewOverlay(this, editorSelection);

            //for GameObjects points which use transforms
            UpdatePointsTrackers();
        }
コード例 #4
0
        public BGCurveEditorPoints(BGCurveEditor editor, SerializedObject curveObject) : base(editor, curveObject, BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPoints123))
        {
            //textures
            convertAll2D = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGConvertAll123);
            addPointIcon = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);

            //selection
            editorSelection = new BGCurveEditorPointsSelection(Curve, this);

            //point
            editorPoint = new BGCurveEditorPoint(this, editorSelection);

            //closed or not
            closedProperty = curveObject.FindProperty("closed");

            //2d mode
            mode2DProperty = curveObject.FindProperty("mode2D");

            //settings
            controlTypeProperty = curveObject.FindProperty("settings").FindPropertyRelative("controlType");

            //Context menu
            overlay = new BGSceneViewOverlay(this, editorSelection);
        }
コード例 #5
0
        //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(convertAllTexture, "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)
                            {
                                //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;
                                        }
                                    });
                                });
                            }


                            // =====================================================  Custom fields
                            if (curve.FieldsCount > 0)
                            {
                                var fields = curve.Fields;
                                pointsContainer.UpdateFields();
                                foreach (var field in fields)
                                {
                                    BGCurveEditorPoint.ShowField(pointsContainer, field, pointsContainer.AnimationCurveChanged);
                                }
                            }
                        });
                    });
                }
                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);
                }
            });
        }