Add Engine.FocusGameViewport to implement game menu with camera focus gather
This commit is contained in:
@@ -1301,6 +1301,17 @@ namespace FlaxEditor
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void Internal_FocusGameViewport()
|
||||
{
|
||||
if (Windows.GameWin != null)
|
||||
{
|
||||
if (StateMachine.IsPlayMode && !StateMachine.PlayingState.IsPaused)
|
||||
{
|
||||
Windows.GameWin.FocusGameViewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Internal_ScreenToGameViewport(ref Float2 pos)
|
||||
{
|
||||
var win = Windows.GameWin?.Root;
|
||||
|
||||
@@ -27,6 +27,7 @@ MMethod* Internal_LightmapsBake = nullptr;
|
||||
MMethod* Internal_CanReloadScripts = nullptr;
|
||||
MMethod* Internal_CanAutoBuildCSG = nullptr;
|
||||
MMethod* Internal_CanAutoBuildNavMesh = nullptr;
|
||||
MMethod* Internal_FocusGameViewport = nullptr;
|
||||
MMethod* Internal_HasGameViewportFocus = nullptr;
|
||||
MMethod* Internal_ScreenToGameViewport = nullptr;
|
||||
MMethod* Internal_GameViewportToScreen = nullptr;
|
||||
@@ -372,6 +373,19 @@ bool ManagedEditor::HasGameViewportFocus() const
|
||||
return result;
|
||||
}
|
||||
|
||||
void ManagedEditor::FocusGameViewport() const
|
||||
{
|
||||
if (HasManagedInstance())
|
||||
{
|
||||
if (Internal_FocusGameViewport == nullptr)
|
||||
{
|
||||
Internal_FocusGameViewport = GetClass()->GetMethod("Internal_FocusGameViewport");
|
||||
ASSERT(Internal_FocusGameViewport);
|
||||
}
|
||||
Internal_FocusGameViewport->Invoke(GetManagedInstance(), nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
Float2 ManagedEditor::ScreenToGameViewport(const Float2& screenPos) const
|
||||
{
|
||||
Float2 result = screenPos;
|
||||
|
||||
@@ -100,6 +100,11 @@ public:
|
||||
/// <returns>True if game viewport is focused, otherwise false.</returns>
|
||||
bool HasGameViewportFocus() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gives focus to the game viewport (game can receive input).
|
||||
/// </summary>
|
||||
void FocusGameViewport() const;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the screen-space position to the game viewport position.
|
||||
/// </summary>
|
||||
|
||||
@@ -191,16 +191,7 @@ namespace FlaxEditor.Modules
|
||||
// Show Game widow if hidden
|
||||
if (gameWin != null && gameWin.FocusOnPlay)
|
||||
{
|
||||
if (!gameWin.IsDocked)
|
||||
{
|
||||
gameWin.ShowFloating();
|
||||
}
|
||||
else if (!gameWin.IsSelected)
|
||||
{
|
||||
gameWin.SelectTab(false);
|
||||
gameWin.RootWindow?.Window?.Focus();
|
||||
FlaxEngine.GUI.RootControl.GameRoot.Focus();
|
||||
}
|
||||
gameWin.FocusGameViewport();
|
||||
}
|
||||
|
||||
Editor.Log("[PlayMode] Enter");
|
||||
|
||||
@@ -471,6 +471,23 @@ namespace FlaxEditor.Windows
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses the game viewport. Shows the window if hidden or unselected.
|
||||
/// </summary>
|
||||
public void FocusGameViewport()
|
||||
{
|
||||
if (!IsDocked)
|
||||
{
|
||||
ShowFloating();
|
||||
}
|
||||
else if (!IsSelected)
|
||||
{
|
||||
SelectTab(false);
|
||||
RootWindow?.Window?.Focus();
|
||||
}
|
||||
Focus();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes the screenshot of the current viewport.
|
||||
/// </summary>
|
||||
|
||||
@@ -409,6 +409,19 @@ JsonAsset* Engine::GetCustomSettings(const StringView& key)
|
||||
return Content::LoadAsync<JsonAsset>(assetId);
|
||||
}
|
||||
|
||||
void Engine::FocusGameViewport()
|
||||
{
|
||||
#if USE_EDITOR
|
||||
Editor::Managed->FocusGameViewport();
|
||||
#else
|
||||
if (MainWindow)
|
||||
{
|
||||
MainWindow->BringToFront();
|
||||
MainWindow->Focus();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Engine::HasGameViewportFocus()
|
||||
{
|
||||
#if USE_EDITOR
|
||||
|
||||
@@ -153,6 +153,11 @@ public:
|
||||
|
||||
static Window* MainWindow;
|
||||
|
||||
/// <summary>
|
||||
/// Brings focused to the game viewport (game can receive input).
|
||||
/// </summary>
|
||||
API_FUNCTION() static void FocusGameViewport();
|
||||
|
||||
/// <summary>
|
||||
/// Checks whenever the game viewport is focused by the user (eg. can receive input).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user