예제 #1
0
        private static void ShowSettings()
        {
            BGEditorUtility.SwapLabelWidth(300, () =>
            {
                BGEditorUtility.Vertical(new GUIStyle("Box")
                {
                    padding = new RectOffset(Padding, Padding, Padding, Padding)
                }, () =>
                {
                    EditorGUILayout.LabelField("BG Curve Editor Settings", new GUIStyle("Box")
                    {
                        fontSize = 22
                    });

                    if (GUILayout.Button(new GUIContent("Reset to defaults", "Reset all editor settings to their defaults.")) &&
                        BGEditorUtility.Confirm("Reset settings", "Reset All Editor settings to defaults? It does not affect curve's settings.", "Reset"))
                    {
                        BGCurveSettingsForEditor.Reset();
                    }

                    //coordinates for points and controls
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.PopupField(BGCurveSettingsForEditor.InspectorPointCoordinateSpace, "Point Coordinates",
                                                   b => BGCurveSettingsForEditor.InspectorPointCoordinateSpace = (BGCurveSettingsForEditor.CoordinateSpaceEnum)b);
                        EditorGUILayout.HelpBox("Coordinate Space for points (for Inspector's fields inder Points tab.)", MessageType.Info);
                    });

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.PopupField(BGCurveSettingsForEditor.InspectorControlCoordinateSpace, "Point Controls Coordinates",
                                                   b => BGCurveSettingsForEditor.InspectorControlCoordinateSpace = (BGCurveSettingsForEditor.CoordinateSpaceEnum)b);
                        EditorGUILayout.HelpBox("Coordinate Space for points controls (for Inspector's fields inder Points tab.)", MessageType.Info);
                    });


                    // disable fields
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ToggleField(BGCurveSettingsForEditor.DisableSceneViewPointMenu, "Disable SV Point Menu", b => BGCurveSettingsForEditor.DisableSceneViewPointMenu = b);
                        EditorGUILayout.HelpBox("Disable point's menu, which is activated in Scene View by holding Ctrl over a point.", MessageType.Info);
                    });

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ToggleField(BGCurveSettingsForEditor.DisableSceneViewSelectionMenu, "Disable SV Selection Menu", b => BGCurveSettingsForEditor.DisableSceneViewSelectionMenu = b);
                        EditorGUILayout.HelpBox("Disable selection's menu, which is activated in Scene View by holding Ctrl over a selection handles.", MessageType.Info);
                    });

/*
 *                                                                              BGEUtil.VerticalBox(() =>
 *                                                                              {
 *                                                                                  BGEUtil.ToggleField(BGCurveEditorSettings.DisableInspectorPointMenu, "Disable Inspector Points Menu", b => BGCurveEditorSettings.DisableInspectorPointMenu = b);
 *                                                                                  EditorGUILayout.HelpBox("Disable points menu, which is located under Points tab in Inspector.", MessageType.Info);
 *                                                                              });
 */

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ToggleField(BGCurveSettingsForEditor.DisableRectangularSelection, "Disable Rectangular Selection", b => BGCurveSettingsForEditor.DisableRectangularSelection = b);
                        EditorGUILayout.HelpBox("Disable rectangular selection in Scene View, which is activated by holding shift and mouse dragging.", MessageType.Info);
                    });


                    // colors
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ColorField("Rectangular Selection Color", BGCurveSettingsForEditor.ColorForRectangularSelection, b => BGCurveSettingsForEditor.ColorForRectangularSelection = b);
                        EditorGUILayout.HelpBox("Color for Rectangular Selection background", MessageType.Info);
                    });

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ColorField("Add and Snap 3D Handles Color", BGCurveSettingsForEditor.HandleColorForAddAndSnap3D, b => BGCurveSettingsForEditor.HandleColorForAddAndSnap3D = b);
                        EditorGUILayout.HelpBox("Color for handles, shown for 3D curve in Scene View when new point is previewed.", MessageType.Info);
                    });

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ColorField("Add and Snap 2D Handles Color", BGCurveSettingsForEditor.HandleColorForAddAndSnap2D, b => BGCurveSettingsForEditor.HandleColorForAddAndSnap2D = b);
                        EditorGUILayout.HelpBox("Color for handles, shown for 2D curve in Scene View when new point is previewed.", MessageType.Info);
                    });

                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ColorField("Points labels back color", BGCurveSettingsForEditor.ColorForLabelBackground, b => BGCurveSettingsForEditor.ColorForLabelBackground = b);
                        EditorGUILayout.HelpBox("Background color for points labels in Scene View.", MessageType.Info);
                    });
                    BGEditorUtility.VerticalBox(() =>
                    {
                        BGEditorUtility.ColorField("New section preview color", BGCurveSettingsForEditor.ColorForNewSectionPreview, b => BGCurveSettingsForEditor.ColorForNewSectionPreview = b);
                        EditorGUILayout.HelpBox("Color for new section preview in Scene View.", MessageType.Info);
                    });
                });
            });
        }
예제 #2
0
 protected void NextEnumRow(BGTableView ui, string label, string tooltip, Enum value, Action <Enum> valueSetter)
 {
     ui.NextColumn(label, tooltip);
     ui.NextColumn(rect => BGEditorUtility.PopupField(rect, value, valueSetter));
     ui.NextRow();
 }
예제 #3
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();
            }
예제 #4
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);
        }
        private BGCurveSettingsForEditor()
        {
            AddSetting(new SettingEnum(InspectorPointsCoordinatesKey,
                                       "Point's Coordinate Space",
                                       "Coordinate Space for points (for Inspector's fields inder Points tab.)",
                                       (int)CoordinateSpaceEnum.World,
                                       oldValue =>
            {
                var newValue1 = oldValue;
                BGEditorUtility.PopupField((CoordinateSpaceEnum)oldValue, "Point's Coordinate Space", b => newValue1 = Convert.ToInt32(b));
                return(newValue1);
            }
                                       ));
            AddSetting(new SettingEnum(InspectorControlsCoordinatesKey,
                                       "Point Controls Coordinates Space",
                                       "Coordinate Space for points controls (for Inspector's fields inder Points tab.)",
                                       (int)CoordinateSpaceEnum.Local,
                                       oldValue =>
            {
                var newValue1 = oldValue;
                BGEditorUtility.PopupField((CoordinateSpaceEnum)oldValue, "Point Controls Coordinates Space", b => newValue1 = Convert.ToInt32(b));
                return(newValue1);
            }
                                       ));

            AddSetting(new SettingBool(DisableRectangularSelectionKey,
                                       "Disable Rectangular Selection",
                                       "Disable rectangular selection in Scene View, which is activated by holding shift and mouse dragging.",
                                       false
                                       ));
            AddSetting(new SettingBool(DisableSceneViewPointMenuKey,
                                       "Disable SV Point Menu",
                                       "Disable point's menu, which is activated in Scene View by holding Ctrl over a point.",
                                       false
                                       ));
            AddSetting(new SettingBool(DisableSceneViewSelectionMenuKey,
                                       "Disable SV Selection Menu",
                                       "Disable selection's menu, which is activated in Scene View by holding Ctrl over a selection handles.",
                                       false
                                       ));

            AddSetting(new SettingBool(CcInspectorHandlesOffKey,
                                       null,
                                       null,
                                       false
                                       ));
            AddSetting(new SettingBool(DisableInspectorPointMenuKey,
                                       null,
                                       null,
                                       false
                                       ));
            AddSetting(new SettingBool(LockViewKey,
                                       null,
                                       null,
                                       false
                                       ));
            AddSetting(new SettingInt(CurrentTabKey,
                                      null,
                                      null,
                                      0
                                      ));

            AddSetting(new SettingColor(HandleColorForAddAndSnap3DKey,
                                        "Add and Snap 3D Handles Color",
                                        "Color for handles, shown for 3D curve in Scene View when new point is previewed.",
                                        new Color32(46, 143, 168, 20)
                                        ));
            AddSetting(new SettingColor(HandleColorForAddAndSnap2DKey,
                                        "Add and Snap 2D Handles Color",
                                        "Color for handles, shown for 2D curve in Scene View when new point is previewed.",
                                        new Color32(255, 255, 255, 10)
                                        ));
            AddSetting(new SettingColor(ColorForRectangularSelectionKey,
                                        "Rectangular Selection Color",
                                        "Color for Rectangular Selection background",
                                        new Color32(46, 143, 168, 25)
                                        ));
            AddSetting(new SettingColor(ColorForLabelBackgroundKey,
                                        "Points labels back color",
                                        "Background color for points labels in Scene View.",
                                        new Color32(255, 255, 255, 25)
                                        ));
            AddSetting(new SettingColor(ColorForNewSectionPreviewKey,
                                        "New section preview color",
                                        "Color for new section preview in Scene View.",
                                        new Color32(255, 0, 0, 255)
                                        ));
        }