public void OnSceneGUI() { var settings = BGPrivateField.GetSettings(Curve); AdjustMath(settings, Math); if (Curve.ForceChangedEventMode != BGCurve.ForceChangedEventModeEnum.Off) { Math.Recalculate(true); } if (settings.HandlesSettings != null && settings.HandlesType == BGCurveSettings.HandlesTypeEnum.Configurable || settings.ControlHandlesSettings != null && settings.ControlHandlesType == BGCurveSettings.HandlesTypeEnum.Configurable) { BGEditorUtility.ReloadSnapSettings(); } OverlayMessage.OnSceneGui(); var frustum = GeometryUtility.CalculateFrustumPlanes(SceneView.currentDrawingSceneView.camera); // process all editors foreach (var editor in editors) { editor.OnSceneGui(frustum); } editorSelection.Process(Event.current); transformMonitor.CheckForChange(); }
public virtual void DrawCurve() { if (transformMonitor != null) { transformMonitor.Check(); } var settings = BGPrivateField.GetSettings(Math.Curve); BGEditorUtility.SwapGizmosColor(settings.LineColor, () => { //======================================== Draw section for (var i = 0; i < Math.SectionsCount; i++) { DrawSection(Math[i]); } }); //======================================== Draw spheres if (settings.ShowSpheres) { BGEditorUtility.SwapGizmosColor(settings.SphereColor, () => { BeforeDrawingSpheres(settings); for (var i = 0; i < Math.Curve.PointsCount; i++) { DrawSphere(settings, Math.GetPosition(i), settings.SphereRadius); } AfterDrawingSpheres(); }); } }
protected override void AdditionalMenuItems() { Add(new MenuSeparator()); //add before Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertBefore123), "Insert a point before this point", () => { var curve = point.Curve; var settings = BGPrivateField.GetSettings(curve); var index = curve.IndexOf(point); curve.AddPoint(BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index); })); //add after Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertAfter123), "Insert a point after this point", () => { var curve = point.Curve; var settings = BGPrivateField.GetSettings(curve); var index = curve.IndexOf(point); curve.AddPoint(BGNewPointPositionManager.InsertAfter(curve, index, settings.ControlType, settings.Sections), index + 1); })); //add remove to selection addToSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionAdd123), "Add this point to selection", () => EditorSelection.Add(point)); removeFromSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection", () => EditorSelection.Remove(point)); Add(addToSelectionItem); Add(removeFromSelectionItem); }
public override void OnInspectorGUI() { //adjust math if needed AdjustMath(BGPrivateField.GetSettings(Curve), Math); //styles BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") {fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {textColor = Color.white}}); serializedObject.Update(); // =========== Header DrawLogo(); // =========== lock view BGEditorUtility.Horizontal(() => { var temp = BGCurveSettingsForEditor.LockView; BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of any object in the scene, except points", LockViewActiveColor, new GUIContent("Turn Off", "Click to turn this mode off"), new GUIContent("Turn On", "Click to turn this mode on")); if (GUILayout.Button(BGBinaryResources.BGSettingsIcon123, GUILayout.MaxWidth(24), GUILayout.MaxHeight(24))) BGCurveSettingsForEditorWindow.Open(BGCurveSettingsForEditor.I); }); //warning BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8)); // =========== Tabs var currentTab = BGCurveSettingsForEditor.CurrentTab; if (currentTab < 0 || currentTab > headers.Length - 1) currentTab = 0; var newTab = GUILayout.Toolbar(currentTab, headers, GUILayout.Height(ToolBarHeight)); //do not move this method(GUILayoutUtility.GetLastRect() is used) ShowStickers(); if (currentTab != newTab) GUI.FocusControl(""); BGCurveSettingsForEditor.CurrentTab = newTab; editors[newTab].OnInspectorGui(); if (!GUI.changed) return; // if no change- return foreach (var editor in editors) editor.OnApply(); transformMonitor.CheckForChange(); }
public static void DrawGizmos(BGCurve curve, GizmoType gizmoType) { var playMode = EditorApplication.isPlaying; if (lastPlayMode != playMode) { lastPlayMode = playMode; foreach (var painterGizmo in curve2Painter) { painterGizmo.Value.Dispose(); } curve2Painter.Clear(); } var settings = BGPrivateField.GetSettings(curve); if (!ComplyForDrawGizmos(curve, gizmoType, settings)) { return; } if (CurrentCurve != null && curve.GetInstanceID() == CurrentCurve.GetInstanceID()) { if (CurrentGizmoPainter != null) { CurrentGizmoPainter.DrawCurve(); } } else { //curve is not selected in hierarchy var painter = BGEditorUtility.Ensure(curve2Painter, curve, () => new BGCurvePainterGizmo(NewMath(curve, settings), true)); AdjustMath(settings, painter.Math); if (curve.ForceChangedEventMode != BGCurve.ForceChangedEventModeEnum.Off && !Application.isPlaying) { painter.Math.Recalculate(); } painter.DrawCurve(); } }
// 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() { var settings = BGPrivateField.GetSettings(Curve); AdjustMath(settings, Math); if (settings.HandlesSettings != null && settings.HandlesType == BGCurveSettings.HandlesTypeEnum.Configurable || settings.ControlHandlesSettings != null && settings.ControlHandlesType == BGCurveSettings.HandlesTypeEnum.Configurable) { BGEditorUtility.ReloadSnapSettings(); } OverlayMessage.OnSceneGui(); // process all editors foreach (var editor in editors) { editor.OnSceneGui(); } transformMonitor.Check(); }
// ================================================================================ 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); BGEditorUtility.Assign(ref systemUi, () => new TableUi("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth })); BGEditorUtility.Assign(ref customUi, () => new TableUi("Custom fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth })); BGEditorUtility.Assign(ref systemFields, () => new[] { (SystemField) new SystemFieldPosition(settings), new SystemFieldControls(settings), new SystemFieldControlsType(settings), }); //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); systemUi.Init(); foreach (var field in systemFields) { field.Ui(systemUi); } //inform layout manager GUILayoutUtility.GetRect(systemUi.Width, systemUi.Height); customUi.Init(); customUi.NextRow("Custom fields are not supported in this version."); GUILayoutUtility.GetRect(customUi.Width, customUi.Height); GUILayout.Space(4); }
public void Reset() { Changed = false; settings = BGPrivateField.GetSettings(curve); }
protected void OnEnable() { Curve = (BGCurve)target; //wth if (Curve == null) { return; } CurrentCurve = Curve; transformMonitor = BGTransformMonitor.GetMonitor(Curve); var settings = BGPrivateField.GetSettings(Curve); //painter and math if (curve2Painter.ContainsKey(Curve)) { curve2Painter[Curve].Dispose(); curve2Painter.Remove(Curve); } Math = NewMath(Curve, settings); CurrentGizmoPainter = new BGCurvePainterGizmo(Math); AllCurves = FindObjectsOfType <BGCurve>(); //overlay BGEditorUtility.Assign(ref OverlayMessage, () => new BGOverlayMessage()); //probably we do not need it for play mode.. probably if (!Application.isPlaying) { //they are not persistent Curve.ImmediateChangeEvents = true; Curve.BeforeChange += BeforeCurveChange; Curve.Changed += CurveChanged; } if (!settings.Existing) { //newly created settings.Existing = true; var defaultSettings = BGCurveSettingsOperations.LoadDefault(); if (defaultSettings != null) { BGPrivateField.SetSettings(Curve, defaultSettings); } } //load textures BGEditorUtility.Assign(ref headerTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCurveLogo123)); stickerTextureOk = BGEditorUtility.Texture1X1(new Color32(46, 143, 168, 255)); stickerTextureError = BGEditorUtility.Texture1X1(new Color32(255, 0, 0, 255)); stickerTextureWarning = BGEditorUtility.Texture1X1(new Color32(255, 206, 92, 255)); stickerTextureActive = BGEditorUtility.Texture1X1(new Color32(44, 160, 90, 255)); //selection editorSelection = new BGCurveEditorPointsSelection(Curve, this); // editors editors = new BGCurveEditorTab[] { new BGCurveEditorPoints(this, serializedObject, editorSelection), new BGCurveEditorComponents(this, serializedObject), new BGCurveEditorFields(this, serializedObject, editorSelection), new BGCurveEditorSettings(this, serializedObject) }; headers = editors.Select(editor => editor.Header2D).ToArray(); foreach (var editor in editors) { editor.OnEnable(); } //do it every frame EditorApplication.update -= OverlayMessage.Check; EditorApplication.update += OverlayMessage.Check; Undo.undoRedoPerformed -= InternalOnUndoRedo; Undo.undoRedoPerformed += InternalOnUndoRedo; }
public override void OnInspectorGUI() { //adjust math if needed AdjustMath(BGPrivateField.GetSettings(Curve), Math); //styles BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") { fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState { textColor = Color.white } }); BGEditorUtility.Assign(ref settingsTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSettingsIcon123)); serializedObject.Update(); // =========== Header DrawLogo(); // =========== lock view BGEditorUtility.Horizontal(() => { var temp = BGCurveSettingsForEditor.LockView; BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of other objects in the scene", LockViewActiveColor, new GUIContent("Turn Off", "Click to turn this mode off"), new GUIContent("Turn On", "Click to turn this mode on")); if (BGEditorUtility.ButtonWithIcon(settingsTexture, "Open BGCurve Editor Settings", 24, 24)) { BGCurveSettingsForEditorWindow.Open(); } }); //warning BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.\r\n Use rectangular selection without pressing shift", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8)); // =========== Tabs if (BGCurveSettingsForEditor.CurrentTab < 0 || BGCurveSettingsForEditor.CurrentTab > headers.Length - 1) { BGCurveSettingsForEditor.CurrentTab = 0; } BGCurveSettingsForEditor.CurrentTab = GUILayout.Toolbar(BGCurveSettingsForEditor.CurrentTab, headers, GUILayout.Height(ToolBarHeight)); //do not move this method(GUILayoutUtility.GetLastRect() is used) ShowStickers(); editors[BGCurveSettingsForEditor.CurrentTab].OnInspectorGui(); if (!GUI.changed) { return; // if no change- return } foreach (var editor in editors) { editor.OnBeforeApply(); } serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(Curve); foreach (var editor in editors) { editor.OnApply(); } transformMonitor.Check(); }
// ================================================================================ 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); }
public override void DrawCurve() { BGEditorUtility.SwapHandlesColor(BGPrivateField.GetSettings(Math.Curve).LineColor, () => base.DrawCurve()); }
public override void OnInspectorGUI() { var curve = point.Curve; BGCurveEditorPoints.SwapVector2Labels(curve.Mode2D, () => pointEditor.OnInspectorGui(point, curve.IndexOf(point), BGPrivateField.GetSettings(curve))); }