public override void OnApply() { if (closeChanged) { Curve.FireChange(Curve.UseEventsArgs ? new BGCurveChangedArgs(Curve, BGCurveChangedArgs.ChangeTypeEnum.Points) : null); } if (mode2DChanged) { //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")) { var settings = Settings; if (Curve.Mode2D != BGCurve.Mode2DEnum.Off) { Apply2D(settings.HandlesSettings); Apply2D(settings.ControlHandlesSettings); } else { Apply3D(settings.HandlesSettings); Apply3D(settings.ControlHandlesSettings); } } } }
public bool DeleteSelected() { if (points.Count == 0) { BGEditorUtility.Inform("Error", "Chose at least one point to delete"); return(false); } if (!BGEditorUtility.Confirm("Delete points confirmation", "Are you sure you want to remove " + points.Count + " point(s)?", "Delete")) { return(false); } BGCurveEditor.DeletePoints(curve, points.ToArray()); Clear(); return(true); }
public bool DeleteSelected() { if (points.Count == 0) { BGEditorUtility.Inform("Error", "Chose at least one point to delete"); return(false); } if (!BGEditorUtility.Confirm("Delete points confirmation", "Are you sure you want to remove " + points.Count + " point(s)?", "Delete")) { return(false); } curve.Transaction(() => { foreach (var point in points) { curve.Delete(point); } }); Clear(); return(true); }
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); }); }); }); }
// ================================================================================ Inspector public override void OnInspectorGui() { var settings = Settings; editorSelection.Reset(); // ======================================== Top section InspectorTopSection(); // ======================================== Points GUILayout.Space(5); if (Curve.PointsCount > 0) { BGEditorUtility.VerticalBox(() => { var temp = BGCurveSettingsForEditor.DisableInspectorPointMenu; BGCurveSettingsForEditor.DisableInspectorPointMenu = BGEditorUtility.ButtonOnOff(ref temp, "Points menu [" + Curve.PointsCount + "]", "Show points in Editor inspector", HiddenPointMenuColor, new GUIContent("Show", "Click to show points menu"), new GUIContent("Hide", "Click to hide points menu"), () => { const string title = "Reverse points"; if (!GUILayout.Button(new GUIContent(title, "Reverse all points, but keep curve intact"))) { return; } if (Curve.PointsCount < 2) { BGEditorUtility.Inform(title, "There should be at least 2 points. Curve has " + Curve.PointsCount); return; } if (!BGEditorUtility.Confirm(title, "Are you sure you want to reverse the order of " + Curve.PointsCount + " points? Curve will remain intact.", "Reverse")) { return; } Curve.Reverse(); }); //show points! if (!BGCurveSettingsForEditor.DisableInspectorPointMenu) { SwapVector2Labels(Curve.Mode2D, () => Curve.ForEach((point, index, count) => editorPoint.OnInspectorGui(point, index, settings))); } }); // ======================================== Selections operations editorSelection.InspectorSelectionOperations(); //warning BGEditorUtility.HelpBox("Selection mode is on", MessageType.Warning, !editorSelection.Changed && editorSelection.HasSelected()); } else { BGEditorUtility.HorizontalBox(() => { EditorGUILayout.LabelField("No points!"); if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new point at (0,0,0) local coordinates")) { BGCurveEditor.AddPoint(Curve, new BGCurvePoint(Curve, Vector3.zero, settings.ControlType, Vector3.right, Vector3.left), 0); } }); } if (!editorSelection.Changed) { return; } Editor.Repaint(); SceneView.RepaintAll(); }
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(); } }
// ================================================================================ Inspector public override void OnInspectorGui() { BGEditorUtility.Assign(ref whiteTexture, () => BGEditorUtility.Texture1X1(Color.white)); components = Curve.GetComponents <BGCc>(); var length = components.Length; tree.Refresh(components); if (tree.InitException != null) { EditorGUILayout.HelpBox("There was an error initializing editors for component's Tree View: " + tree.InitException.Message + "\r\n\r\nYou still can use default Unity's editors for components below.", MessageType.Error); return; } var hasError = HasError; var hasWarning = HasWarning; BGEditorUtility.HorizontalBox(() => { EditorGUILayout.LabelField("Components: " + length + " (" + (hasError ? "Error" : "Ok") + ")"); GUILayout.FlexibleSpace(); // turn on/off handles var handlesOff = BGCurveSettingsForEditor.CcInspectorHandlesOff; if (BGEditorUtility.ButtonWithIcon( handlesOff ? BGBinaryResources.BGHandlesOff123 : BGBinaryResources.BGHandlesOn123, "Turn on/off handles settings in Inspector")) { BGCurveSettingsForEditor.CcInspectorHandlesOff = !BGCurveSettingsForEditor.CcInspectorHandlesOff; } EditorGUILayout.Separator(); // turn on/off colored tree if (BGEditorUtility.ButtonWithIcon(customEditorsOn ? BGBinaryResources.BGOn123: BGBinaryResources.BGOff123, "Use custom UI for components (colored tree) and hide standard unity editors for components")) { customEditorsOn = !customEditorsOn; tree.Refresh(null, true); } EditorGUILayout.Separator(); if (length > 0) { // collapse/expand if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCollapseAll123, "Collapse all components")) { tree.ExpandCollapseAll(true); } EditorGUILayout.Separator(); if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGExpandAll123, "Expand all components")) { tree.ExpandCollapseAll(false); } EditorGUILayout.Separator(); // delete all Ccs if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Delete all components") && BGEditorUtility.Confirm("Delete", "Are you sure you want to delete " + length + " component(s)?", "Delete")) { tree.Delete(); } EditorGUILayout.Separator(); } //add new Cc if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new component")) { BGCcAddWindow.Open(Curve, type => AddComponent(Curve, type)); } }); if (length > 0) { // warnings/errors if (hasWarning || hasError) { for (var i = 0; i < components.Length; i++) { var component = components[i]; var name = (component.Descriptor != null ? component.Descriptor.Name + " " : "") + component.CcName; var error = component.Error; if (!string.IsNullOrEmpty(error)) { BGEditorUtility.HelpBox("Component error [" + name + "]: " + error, MessageType.Error); } var warning = component.Warning; if (!string.IsNullOrEmpty(warning)) { BGEditorUtility.HelpBox("Component warning [" + name + "]: " + warning, MessageType.Warning); } } } else { BGEditorUtility.HelpBox("No warnings or errors", MessageType.Info); } // tree GUI tree.OnInspectorGui(); } else { EditorGUILayout.HelpBox( "Hit the Plus icon to add a component" + "\r\n" + "\r\n" + "Components allows to add functionality without any scripting." , MessageType.Info); } if (hasError ^ HasError || hasWarning ^ HasWarning) { EditorApplication.RepaintHierarchyWindow(); } }
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(); }
private static void ShowSettings() { BGEditorUtility.SwapLabelWidth(300, () => { BGEditorUtility.Vertical(new GUIStyle("Box") { padding = new RectOffset(Padding, Padding, Padding, Padding) }, () => { EditorGUILayout.LabelField(settings.Name, 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 local settings.", "Reset")) { settings.Reset(); } var keys = settings.Keys; foreach (var key in keys) { var descriptor = settings.GetSetting(key); if (descriptor.Name == null) { continue; } Action ui; if (descriptor is BGAbstractSettingsForEditor.SettingEnum) { var setting = (BGAbstractSettingsForEditor.SettingEnum)descriptor; ui = () => { setting.Value = setting.Ui(setting.Value); }; } else if (descriptor is BGAbstractSettingsForEditor.SettingBool) { var setting = (BGAbstractSettingsForEditor.SettingBool)descriptor; ui = () => { BGEditorUtility.ToggleField(setting.Value, descriptor.Name, b => setting.Value = b); }; } else if (descriptor is BGAbstractSettingsForEditor.SettingInt) { var setting = (BGAbstractSettingsForEditor.SettingInt)descriptor; ui = () => { BGEditorUtility.IntField(descriptor.Name, setting.Value, b => setting.Value = b); }; } else if (descriptor is BGAbstractSettingsForEditor.SettingString) { var setting = (BGAbstractSettingsForEditor.SettingString)descriptor; ui = () => { BGEditorUtility.TextField(descriptor.Name, setting.Value, b => setting.Value = b, false); }; } else if (descriptor is BGAbstractSettingsForEditor.SettingFloat) { var setting = (BGAbstractSettingsForEditor.SettingFloat)descriptor; ui = () => { BGEditorUtility.FloatField(descriptor.Name, setting.Value, b => setting.Value = b); }; } else if (descriptor is BGAbstractSettingsForEditor.SettingColor) { var setting = (BGAbstractSettingsForEditor.SettingColor)descriptor; ui = () => { BGEditorUtility.ColorField(descriptor.Name, setting.Value, b => setting.Value = b); }; } else { throw new UnityException("Unsupported type"); } BGEditorUtility.VerticalBox(() => { ui(); EditorGUILayout.HelpBox(descriptor.Description, MessageType.Info); }); } }); }); }