Add custom editor for buttons that allow listening for them inside the editor.
This commit is contained in:
37
Source/Editor/CustomEditors/Editors/MouseButtonEditor.cs
Normal file
37
Source/Editor/CustomEditors/Editors/MouseButtonEditor.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom editor for <see cref="MouseButton"/>.
|
||||
/// Allows capturing mouse button presses and assigning them
|
||||
/// to the edited value.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(MouseButton))]
|
||||
public class MouseButtonEditor : BindableButtonEditor
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
base.Initialize(layout);
|
||||
Window.MouseUp += WindowOnMouseUp;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Deinitialize()
|
||||
{
|
||||
Window.MouseUp -= WindowOnMouseUp;
|
||||
base.Deinitialize();
|
||||
}
|
||||
|
||||
private void WindowOnMouseUp(ref Float2 mouse, MouseButton button, ref bool handled)
|
||||
{
|
||||
if (!IsListeningForInput)
|
||||
return;
|
||||
IsListeningForInput = false;
|
||||
|
||||
SetValue(button);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user