Ejemplo n.º 1
0
        private void InternalOnUndoRedo()
        {
            transformMonitor.CheckForChange();

            Curve.PrivateUpdateFieldsValuesIndexes();

            if (BGCurve.IsGoMode(Curve.PointsMode)) BGPrivateField.Invoke(Curve, BGCurve.MethodSetPointsNames);

            foreach (var editor in editors) editor.OnUndoRedo();

            if (Math != null) Math.Recalculate();

            Repaint();
            SceneView.RepaintAll();
        }
Ejemplo n.º 2
0
        public override void OnApply()
        {
            var curve    = Editor.Curve;
            var settings = Settings;

            // ==============================================    Closed
            if (curve.Closed != closedProperty.boolValue)
            {
                Curve.FireBeforeChange(BGCurve.EventClosed);
                serializedObject.ApplyModifiedProperties();
                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.EventClosed));
            }

            if ((int)curve.ForceChangedEventMode != forceChangedEventModeProperty.enumValueIndex)
            {
                Curve.FireBeforeChange(BGCurve.EventForceUpdate);
                serializedObject.ApplyModifiedProperties();
                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Curve, BGCurve.EventForceUpdate));
            }

            // ==============================================    Points store mode
            if ((int)Curve.PointsMode != pointsModeProperty.enumValueIndex)
            {
                var newPointsMode = (BGCurve.PointsModeEnum)pointsModeProperty.enumValueIndex;

                //ask for confirmation in case changes may affect something else
                if ((Curve.PointsMode == BGCurve.PointsModeEnum.Components) && !BGEditorUtility.Confirm("Convert Points",
                                                                                                        "Are you sure you want to convert points? All existing references to these points will be lost.", "Convert"))
                {
                    return;
                }

                if ((Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsNoTransform && newPointsMode != BGCurve.PointsModeEnum.GameObjectsTransform ||
                     Curve.PointsMode == BGCurve.PointsModeEnum.GameObjectsTransform && newPointsMode != BGCurve.PointsModeEnum.GameObjectsNoTransform) &&
                    !BGEditorUtility.Confirm("Convert Points", "Are you sure you want to convert points? All existing GameObjects for points will be deleted.", "Convert"))
                {
                    return;
                }

                editorSelection.Clear();

                //invoke convert
                BGPrivateField.Invoke(Curve, BGCurve.MethodConvertPoints, newPointsMode,
                                      BGCurveEditor.GetPointProvider(newPointsMode, Curve),
                                      BGCurveEditor.GetPointDestroyer(Curve.PointsMode, Curve));

                //this call is not required
                //                serializedObject.ApplyModifiedProperties();
            }

            // ==============================================    2D mode
            if ((int)curve.Mode2D != mode2DProperty.enumValueIndex)
            {
                Curve.FireBeforeChange(BGCurve.Event2D);
                serializedObject.ApplyModifiedProperties();

                var oldEventMode = Curve.EventMode;
                Curve.EventMode = BGCurve.EventModeEnum.NoEvents;

                //force points recalc
                Curve.Apply2D(Curve.Mode2D);

                if (BGEditorUtility.Confirm("Editor handles change", "Do you want to adjust configurable Editor handles (in Scene View) to chosen mode? This affects only current curve.", "Yes"))
                {
                    if (Curve.Mode2D != BGCurve.Mode2DEnum.Off)
                    {
                        Apply2D(settings.HandlesSettings);
                        Apply2D(settings.ControlHandlesSettings);
                    }
                    else
                    {
                        Apply3D(settings.HandlesSettings);
                        Apply3D(settings.ControlHandlesSettings);
                    }
                }

                Curve.EventMode = oldEventMode;

                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.Event2D));
            }

            // ==============================================    Snapping
            if ((int)curve.SnapType != snapTypeProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapType);
            }

            if ((int)curve.SnapAxis != snapAxisProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapAxis);
            }

            if (Math.Abs((int)curve.SnapDistance - snapDistanceProperty.floatValue) > BGCurve.Epsilon)
            {
                SnappingChanged(BGCurve.EventSnapDistance);
            }

            if ((int)curve.SnapTriggerInteraction != snapTriggerInteractionProperty.enumValueIndex)
            {
                SnappingChanged(BGCurve.EventSnapTrigger);
            }

            if (curve.SnapToBackFaces != snapToBackFacesProperty.boolValue)
            {
                SnappingChanged(BGCurve.EventSnapBackfaces);
            }

            if (curve.SnapMonitoring != snapMonitoringProperty.boolValue)
            {
                SnappingChanged(BGCurve.EventSnapMonitoring);
            }

            // ==============================================    Event mode
            if ((int)curve.EventMode != eventModeProperty.enumValueIndex)
            {
                serializedObject.ApplyModifiedProperties();
            }

            // ==============================================    Control Type
            if ((int)settings.ControlType != controlTypeProperty.enumValueIndex)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
Ejemplo n.º 3
0
        private void InspectorTopSection()
        {
            if (Curve.PointsCount == 0)
            {
                EditorGUILayout.HelpBox(
                    "1) Ctrl + LeftClick in scene view to add a point and snap it to  "
                    + "\r\n    a) 3D mode: mesh with collider"
                    + "\r\n    b) 2D mode: curve's 2D plane."
                    + "\r\n"
                    + "\r\n2) Ctrl + Shift + LeftClick in Scene View to add a point unconditionally at some distance, specified in the settings."
                    + "\r\n"
                    + "\r\n3) Hold control over existing point or selection to access Scene View menu"
                    + "\r\n"
                    + "\r\n4) Hold shift + drag to use rectangular selection in Scene View"
                    + "\r\n"
                    + "\r\n5) Ctrl + LeftClick over existing spline to insert a point"
                    , MessageType.Info);
            }


            try
            {
                // Curve's block
                BGEditorUtility.VerticalBox(() =>
                {
                    //closed
                    EditorGUILayout.PropertyField(closedProperty);


                    //point's store mode
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(pointsModeProperty);

                        BGEditorUtility.DisableGui(() =>
                        {
                            BGEditorUtility.Assign(ref syncContent, () => new GUIContent("Sync", "Sort points Game Objects and update names"));

                            if (!GUILayout.Button(syncContent))
                            {
                                return;
                            }

                            BGPrivateField.Invoke(Curve, BGCurve.MethodSetPointsNames);
                        }, !BGCurve.IsGoMode(Curve.PointsMode));
                    });


                    //2D mode
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(mode2DProperty);
                        BGEditorUtility.DisableGui(() =>
                        {
                            if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80)))
                            {
                                return;
                            }

                            Curve.FireBeforeChange(BGCurve.Event2D);
                            Curve.Apply2D(Curve.Mode2D);
                            Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points, BGCurve.Event2D));
                        }, mode2DProperty.enumValueIndex == 0);
                    });

                    //snapping
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.Horizontal(() =>
                        {
                            EditorGUILayout.PropertyField(snapTypeProperty);

                            BGEditorUtility.DisableGui(() =>
                            {
                                if (!GUILayout.Button("Apply", GUI.skin.button, GUILayout.Width(80)))
                                {
                                    return;
                                }

                                Curve.FireBeforeChange(BGCurve.EventSnapType);
                                Curve.ApplySnapping();
                                Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapType));
                            }, snapTypeProperty.enumValueIndex == 0);
                        });

                        if (snapTypeProperty.enumValueIndex == 0)
                        {
                            return;
                        }

                        EditorGUILayout.PropertyField(snapAxisProperty);
                        EditorGUILayout.PropertyField(snapDistanceProperty);
                        EditorGUILayout.PropertyField(snapTriggerInteractionProperty);
                        EditorGUILayout.PropertyField(snapToBackFacesProperty);

                        BGEditorUtility.LayerMaskField("Snap Layer Mask", Curve.SnapLayerMask, i =>
                        {
                            Curve.FireBeforeChange(BGCurve.EventSnapTrigger);
                            Curve.SnapLayerMask = i;
                            Curve.ApplySnapping();
                            Curve.FireChange(BGCurveChangedArgs.GetInstance(Curve, BGCurveChangedArgs.ChangeTypeEnum.Snap, BGCurve.EventSnapTrigger));
                        });

                        EditorGUILayout.PropertyField(snapMonitoringProperty);
                        if (Curve.SnapMonitoring && Curve.SnapType != BGCurve.SnapTypeEnum.Off)
                        {
                            EditorGUILayout.HelpBox("You enabled snap monitoring, which monitor environment every frame and snap to it. Be aware, this is a very costly function", MessageType.Warning);
                        }
                    });

                    //event mode
                    EditorGUILayout.PropertyField(eventModeProperty);

                    //force update
                    EditorGUILayout.PropertyField(forceChangedEventModeProperty);

                    //convert control type
                    BGEditorUtility.Horizontal(() =>
                    {
                        EditorGUILayout.PropertyField(controlTypeProperty);

                        if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGConvertAll123, "Convert control types for all existing points ", 44))
                        {
                            return;
                        }

                        var settings = Settings;

                        foreach (var point in Curve.Points.Where(point => point.ControlType != settings.ControlType))
                        {
                            point.ControlType = settings.ControlType;
                        }
                    });
                });
            }
            catch (BGEditorUtility.ExitException)
            {
                GUIUtility.ExitGUI();
            }
        }
Ejemplo n.º 4
0
 public static void DeletePoints(BGCurve curve, BGCurvePointI[] points)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodDeletePoint, new[] { typeof(BGCurvePointI[]), typeof(Action <BGCurvePointI>) }, points, GetPointDestroyer(curve.PointsMode, curve));
 }
Ejemplo n.º 5
0
 public static void DeletePoint(BGCurve curve, int index)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodDeletePoint, new[] { typeof(int), typeof(Action <BGCurvePointI>) }, index, GetPointDestroyer(curve.PointsMode, curve));
 }
Ejemplo n.º 6
0
 public static void AddPoint(BGCurve curve, BGCurvePoint point, int index)
 {
     BGPrivateField.Invoke(curve, BGCurve.MethodAddPoint, point, index, GetPointProvider(curve.PointsMode, curve));
 }
Ejemplo n.º 7
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            // Custom fields
            var warning = "";

            BGEditorUtility.Assign(ref customUi, () => new BGTableView("Custom fields", new[] { "#", "Name", "Type", "?", "Delete" }, new[] { 5, 40, 40, 5, 10 }, () =>
            {
                //add row
                customUi.NextColumn(rect => EditorGUI.LabelField(rect, "Name"), 12);
                customUi.NextColumn(rect => newFieldName = EditorGUI.TextField(rect, newFieldName), 28);
                customUi.NextColumn(rect => BGEditorUtility.PopupField(rect, newFieldType, @enum => newFieldType = (BGCurvePointField.TypeEnum)@enum), 50);
                customUi.NextColumn(rect =>
                {
                    if (!GUI.Button(rect, BGBinaryResources.BGAdd123))
                    {
                        return;
                    }

                    if (NameHasError(Curve, newFieldName))
                    {
                        return;
                    }

                    BGPrivateField.Invoke(Curve, BGCurve.MethodAddField, newFieldName, newFieldType, (Func <BGCurvePointField>)(() => Undo.AddComponent <BGCurvePointField>(Curve.gameObject)));
                    GUIUtility.hotControl = 0;
                    GUIUtility.ExitGUI();
                }, 10);

                customUi.NextRow();

                if (customFields == null || customFields.Length == 0)
                {
                    customUi.NextRow("Name should be 16 chars max, starts with a letter and contain English chars and numbers only.");
                }
                else
                {
                    //header
                    customUi.DrawHeaders();

                    //fields
                    var quaternionWithHandlesCount = 0;

                    BGEditorUtility.ChangeCheck(() =>
                    {
                        foreach (var customField in customFields)
                        {
                            if (customField.Field.Type == BGCurvePointField.TypeEnum.Quaternion && BGPrivateField.GetHandlesType(customField.Field) != 0)
                            {
                                quaternionWithHandlesCount++;
                            }
                            customField.Ui(customUi);
                        }
                    }, SceneView.RepaintAll);

                    if (quaternionWithHandlesCount > 1)
                    {
                        warning = "You have more than one Quaternion field with Handles enabled. Only first field will be shown in Scene View";
                    }
                    //footer
                    customUi.NextRow("?- Show in Points Menu/Scene View");
                }
            }));

            // System fields
            BGEditorUtility.Assign(ref systemUi, () => new BGTableView("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }, () =>
            {
                BGEditorUtility.ChangeCheck(() =>
                {
                    foreach (var field in systemFields)
                    {
                        field.Ui(systemUi);
                    }
                }, SceneView.RepaintAll);
            }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
                new SystemFieldTransform(settings),
            });

            var fields    = Curve.Fields;
            var hasFields = fields != null && fields.Length > 0;

            if (hasFields && (customFields == null || customFields.Length != fields.Length) || !hasFields && customFields != null && customFields.Length != fields.Length)
            {
                customFields = new PointField[fields.Length];

                for (var i = 0; i < fields.Length; i++)
                {
                    customFields[i] = new PointField(fields[i], i, BGBinaryResources.BGDelete123);
                }
            }


            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            //====================== Custom fields
            customUi.OnGui();

            //warnings
            BGEditorUtility.HelpBox(warning, MessageType.Warning, warning.Length > 0);

            //====================== System fields
            systemUi.OnGui();
            GUILayout.Space(4);
        }
Ejemplo n.º 8
0
            public void Ui(BGTableView ui)
            {
                var cursor = 0;

                // ==========================   First row
                //number
                ui.NextColumn("" + index, "Field's index", GetWidth(ui, ref cursor));

                //name
                ui.NextColumn(rect =>
                {
                    BGEditorUtility.TextField(rect, field.FieldName, s =>
                    {
                        if (NameHasError(field.Curve, s))
                        {
                            return;
                        }
                        Change(() => field.FieldName = s);
                    }, true);
                }, GetWidth(ui, ref cursor));

                //type
                ui.NextColumn(field.Type.ToString(), "Field's Type", GetWidth(ui, ref cursor));

                //show in Points menu
                ui.NextColumn(rect => BGEditorUtility.BoolField(rect, BGPrivateField.GetShowInPointsMenu(field), b => Change(() => BGPrivateField.SetShowInPointsMenu(field, b))),
                              GetWidth(ui, ref cursor));

                //delete icon
                ui.NextColumn(rect =>
                {
                    if (!GUI.Button(rect, deleteIcon) || !BGEditorUtility.Confirm("Delete", "Are you sure you want to delete '" + field.FieldName + "' field?", "Delete"))
                    {
                        return;
                    }

                    BGPrivateField.Invoke(field.Curve, BGCurve.MethodDeleteField, field, (Action <BGCurvePointField>)Undo.DestroyObjectImmediate);

                    GUIUtility.ExitGUI();
                }, GetWidth(ui, ref cursor));

                //\r\n
                ui.NextRow();

                // ==========================   Second row
                //does not support
                if (!SupportHandles(field.Type))
                {
                    return;
                }

                ui.NextColumn("      Handles", "Field's index", 25);

                //handles type
                ui.NextColumn(
                    rect => BGEditorUtility.PopupField(rect, (HandlesType)BGPrivateField.GetHandlesType(field), Type2Handles[field.Type],
                                                       b => Change(() => BGPrivateField.SetHandlesType(field, (int)((HandlesType)b)))), 30);

                //Handles color
                ui.NextColumn(rect => BGEditorUtility.ColorField(rect, BGPrivateField.GetHandlesColor(field), b => Change(() => BGPrivateField.SetHandlesColor(field, b))), 30);

                //show handles in Scene View
                ui.NextColumn(rect => BGEditorUtility.BoolField(rect, BGPrivateField.GetShowHandles(field), b => Change(() => BGPrivateField.SetShowHandles(field, b))), 5);

                //empty column under delete button
                ui.NextColumn(rect => EditorGUI.LabelField(rect, ""), 10);

                //\r\n
                ui.NextRow();
            }