add locked focus
This commit is contained in:
@@ -60,6 +60,10 @@ namespace FlaxEditor.Options
|
||||
[EditorDisplay("Common"), EditorOrder(200)]
|
||||
public InputBinding FocusSelection = new InputBinding(KeyboardKeys.F);
|
||||
|
||||
[DefaultValue(typeof(InputBinding), "F")]
|
||||
[EditorDisplay("Common"), EditorOrder(200)]
|
||||
public InputBinding LockFocusSelection = new InputBinding(KeyboardKeys.F, KeyboardKeys.Shift);
|
||||
|
||||
[DefaultValue(typeof(InputBinding), "Ctrl+F")]
|
||||
[EditorDisplay("Common"), EditorOrder(210)]
|
||||
public InputBinding Search = new InputBinding(KeyboardKeys.F, KeyboardKeys.Control);
|
||||
|
||||
@@ -133,6 +133,7 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
}
|
||||
|
||||
private bool _lockedFocus;
|
||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||
private StaticModel _previewStaticModel;
|
||||
private int _previewModelEntryIndex;
|
||||
@@ -386,11 +387,40 @@ namespace FlaxEditor.Viewport
|
||||
InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
|
||||
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
|
||||
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
|
||||
|
||||
InputActions.Add(options => options.LockFocusSelection, LockFocusSelection);
|
||||
InputActions.Add(options => options.FocusSelection, FocusSelection);
|
||||
InputActions.Add(options => options.RotateSelection, RotateSelection);
|
||||
InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
var hasSelections = TransformGizmo.SelectedParents.Count != 0;
|
||||
var requestUnlockFocus = FlaxEngine.Input.Mouse.GetButtonDown(MouseButton.Right) || FlaxEngine.Input.Mouse.GetButtonDown(MouseButton.Left);
|
||||
|
||||
if ((IsFocused && requestUnlockFocus) || !hasSelections)
|
||||
{
|
||||
UnlockFocusSelection();
|
||||
}
|
||||
|
||||
if (_lockedFocus)
|
||||
{
|
||||
BoundingSphere selectionBounds = BoundingSphere.Empty;
|
||||
for (int i = 0; i < TransformGizmo.SelectedParents.Count; i++)
|
||||
{
|
||||
TransformGizmo.SelectedParents[i].GetEditorSphere(out var sphere);
|
||||
BoundingSphere.Merge(ref selectionBounds, ref sphere, out selectionBounds);
|
||||
}
|
||||
|
||||
var focusDistance = Mathf.Max(selectionBounds.Radius * 2f, 100f);
|
||||
var viewportPosition = selectionBounds.Center + (-ViewDirection * focusDistance);
|
||||
ViewPosition = viewportPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the selection outline effect or restored the default one.
|
||||
/// </summary>
|
||||
@@ -753,6 +783,22 @@ namespace FlaxEditor.Viewport
|
||||
FocusSelection(ref orientation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lock focus on the current selection gizmo.
|
||||
/// </summary>
|
||||
public void LockFocusSelection()
|
||||
{
|
||||
_lockedFocus = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unlock focus on the current selection.
|
||||
/// </summary>
|
||||
public void UnlockFocusSelection()
|
||||
{
|
||||
_lockedFocus = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses the viewport on the current selection of the gizmo.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user