Merge branch 'RuanLucasGD-locked_focus'
This commit is contained in:
@@ -60,6 +60,10 @@ namespace FlaxEditor.Options
|
|||||||
[EditorDisplay("Common"), EditorOrder(200)]
|
[EditorDisplay("Common"), EditorOrder(200)]
|
||||||
public InputBinding FocusSelection = new InputBinding(KeyboardKeys.F);
|
public InputBinding FocusSelection = new InputBinding(KeyboardKeys.F);
|
||||||
|
|
||||||
|
[DefaultValue(typeof(InputBinding), "Shift+F")]
|
||||||
|
[EditorDisplay("Common"), EditorOrder(200)]
|
||||||
|
public InputBinding LockFocusSelection = new InputBinding(KeyboardKeys.F, KeyboardKeys.Shift);
|
||||||
|
|
||||||
[DefaultValue(typeof(InputBinding), "Ctrl+F")]
|
[DefaultValue(typeof(InputBinding), "Ctrl+F")]
|
||||||
[EditorDisplay("Common"), EditorOrder(210)]
|
[EditorDisplay("Common"), EditorOrder(210)]
|
||||||
public InputBinding Search = new InputBinding(KeyboardKeys.F, KeyboardKeys.Control);
|
public InputBinding Search = new InputBinding(KeyboardKeys.F, KeyboardKeys.Control);
|
||||||
|
|||||||
@@ -133,6 +133,8 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _lockedFocus;
|
||||||
|
private double _lockedFocusOffset;
|
||||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||||
private StaticModel _previewStaticModel;
|
private StaticModel _previewStaticModel;
|
||||||
private int _previewModelEntryIndex;
|
private int _previewModelEntryIndex;
|
||||||
@@ -386,11 +388,43 @@ namespace FlaxEditor.Viewport
|
|||||||
InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
|
InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate);
|
||||||
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
|
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
|
||||||
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
|
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.FocusSelection, FocusSelection);
|
||||||
InputActions.Add(options => options.RotateSelection, RotateSelection);
|
InputActions.Add(options => options.RotateSelection, RotateSelection);
|
||||||
InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete);
|
InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Update(float deltaTime)
|
||||||
|
{
|
||||||
|
base.Update(deltaTime);
|
||||||
|
|
||||||
|
var selection = TransformGizmo.SelectedParents;
|
||||||
|
var requestUnlockFocus = FlaxEngine.Input.Mouse.GetButtonDown(MouseButton.Right) || FlaxEngine.Input.Mouse.GetButtonDown(MouseButton.Left);
|
||||||
|
if (TransformGizmo.SelectedParents.Count == 0 || (requestUnlockFocus && ContainsFocus))
|
||||||
|
{
|
||||||
|
UnlockFocusSelection();
|
||||||
|
}
|
||||||
|
else if (_lockedFocus)
|
||||||
|
{
|
||||||
|
var selectionBounds = BoundingSphere.Empty;
|
||||||
|
for (int i = 0; i < selection.Count; i++)
|
||||||
|
{
|
||||||
|
selection[i].GetEditorSphere(out var sphere);
|
||||||
|
BoundingSphere.Merge(ref selectionBounds, ref sphere, out selectionBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ContainsFocus)
|
||||||
|
{
|
||||||
|
var viewportFocusDistance = Vector3.Distance(ViewPosition, selectionBounds.Center) / 10f;
|
||||||
|
_lockedFocusOffset -= FlaxEngine.Input.Mouse.ScrollDelta * viewportFocusDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
var focusDistance = Mathf.Max(selectionBounds.Radius * 2d, 100d);
|
||||||
|
ViewPosition = selectionBounds.Center + (-ViewDirection * (focusDistance + _lockedFocusOffset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Overrides the selection outline effect or restored the default one.
|
/// Overrides the selection outline effect or restored the default one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -753,6 +787,23 @@ namespace FlaxEditor.Viewport
|
|||||||
FocusSelection(ref orientation);
|
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;
|
||||||
|
_lockedFocusOffset = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Focuses the viewport on the current selection of the gizmo.
|
/// Focuses the viewport on the current selection of the gizmo.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user