// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Platform/Window.h" #include "Engine/ShadowsOfMordor/Types.h" #include "Engine/Tools/TextureTool/TextureTool.h" #include "Engine/Tools/ModelTool/ModelTool.h" #include "Engine/Tools/AudioTool/AudioTool.h" namespace CSG { class Brush; } /// /// The main managed editor class. Editor root object. /// API_CLASS(Namespace="FlaxEditor", Name="Editor", NoSpawn, NoConstructor) class ManagedEditor : private ScriptingObject { DECLARE_SCRIPTING_TYPE_NO_SPAWN(ManagedEditor); static Guid ObjectID; struct InternalOptions { byte AutoReloadScriptsOnMainWindowFocus = 1; byte ForceScriptCompilationOnStartup = 1; byte UseAssetImportPathRelative = 1; byte AutoRebuildCSG = 1; float AutoRebuildCSGTimeoutMs = 50; byte AutoRebuildNavMesh = 1; float AutoRebuildNavMeshTimeoutMs = 100; }; static InternalOptions ManagedEditorOptions; public: /// /// Initializes a new instance of the class. /// ManagedEditor(); /// /// Finalizes an instance of the class. /// ~ManagedEditor(); public: /// /// Initializes managed editor. /// void Init(); void BeforeRun(); /// /// Updates managed editor. /// void Update(); /// /// Exits managed editor. /// void Exit(); /// /// Gets the main window created by the c# editor. /// /// The main window Window* GetMainWindow(); /// /// Determines whether this managed editor allows reload scripts (based on editor state). /// bool CanReloadScripts(); /// /// Determines whether this managed editor allows to reload scripts by auto (based on editor options). /// bool CanAutoReloadScripts() const { return ManagedEditorOptions.AutoReloadScriptsOnMainWindowFocus != 0; } /// /// Determines whether this managed editor allows auto build CSG mesh on brush modification (based on editor state and settings). /// bool CanAutoBuildCSG(); /// /// Determines whether this managed editor allows auto build navigation mesh on scene modification (based on editor state and settings). /// bool CanAutoBuildNavMesh(); public: /// /// Checks whenever the game viewport is focused by the user (eg. can receive input). /// /// True if game viewport is focused, otherwise false. bool HasGameViewportFocus() const; /// /// Gives focus to the game viewport (game can receive input). /// void FocusGameViewport() const; /// /// Converts the screen-space position to the game viewport position. /// /// The screen-space position. /// The game viewport position. Float2 ScreenToGameViewport(const Float2& screenPos) const; /// /// Converts the game viewport position to the screen-space position. /// /// The game viewport position. /// The screen-space position. Float2 GameViewportToScreen(const Float2& viewportPos) const; /// /// Gets the game window used to simulate game in editor. Can be used to capture input for the game scripts. /// /// True if always get the window, otherwise only if focused. /// The window or null if hidden. Window* GetGameWindow(bool forceGet = false); /// /// Gets the size of the game window output. /// /// The size. Float2 GetGameWindowSize(); /// /// Called when application code calls exit. Editor may end play mode or exit normally. /// /// True if exit engine, otherwise false. bool OnAppExit(); /// /// Requests play mode when the editor is in edit mode ( once ). /// void RequestStartPlayOnEditMode(); public: /// /// Imports the asset file to the target location. /// /// The source file path. /// The result asset file path. /// The custom argument 9native data). /// True if importing failed, otherwise false. API_FUNCTION() static bool Import(String inputPath, String outputPath, void* arg = nullptr); #if COMPILE_WITH_TEXTURE_TOOL /// /// Imports the texture asset file to the target location. /// /// The source file path. /// The result asset file path. /// The import settings. /// True if importing failed, otherwise false. API_FUNCTION() static bool Import(const String& inputPath, const String& outputPath, const TextureTool::Options& options); /// /// Tries the restore the asset import options from the target resource file. /// /// The options. /// The asset path. /// True settings has been restored, otherwise false. API_FUNCTION() static bool TryRestoreImportOptions(API_PARAM(Ref) TextureTool::Options& options, String assetPath); #endif #if COMPILE_WITH_MODEL_TOOL /// /// Imports the model asset file to the target location. /// /// The source file path. /// The result asset file path. /// The import settings. /// True if importing failed, otherwise false. API_FUNCTION() static bool Import(const String& inputPath, const String& outputPath, const ModelTool::Options& options); /// /// Tries the restore the asset import options from the target resource file. /// /// The options. /// The asset path. /// True settings has been restored, otherwise false. API_FUNCTION() static bool TryRestoreImportOptions(API_PARAM(Ref) ModelTool::Options& options, String assetPath); #endif #if COMPILE_WITH_AUDIO_TOOL /// /// Imports the audio asset file to the target location. /// /// The source file path. /// The result asset file path. /// The import settings. /// True if importing failed, otherwise false. API_FUNCTION() static bool Import(const String& inputPath, const String& outputPath, const AudioTool::Options& options); /// /// Tries the restore the asset import options from the target resource file. /// /// The options. /// The asset path. /// True settings has been restored, otherwise false. API_FUNCTION() static bool TryRestoreImportOptions(API_PARAM(Ref) AudioTool::Options& options, String assetPath); #endif /// /// Creates a new asset at the target location. /// /// New asset type. /// Output asset path. API_FUNCTION() static bool CreateAsset(const String& tag, String outputPath); public: API_STRUCT(Internal, NoDefault) struct VisualScriptStackFrame { DECLARE_SCRIPTING_TYPE_MINIMAL(VisualScriptStackFrame); API_FIELD() class VisualScript* Script; API_FIELD() uint32 NodeId; API_FIELD() int32 BoxId; }; API_STRUCT(Internal, NoDefault) struct VisualScriptLocal { DECLARE_SCRIPTING_TYPE_MINIMAL(VisualScriptLocal); API_FIELD() String Value; API_FIELD() String ValueTypeName; API_FIELD() uint32 NodeId; API_FIELD() int32 BoxId; }; API_FUNCTION(Internal) static Array GetVisualScriptStackFrames(); API_FUNCTION(Internal) static VisualScriptStackFrame GetVisualScriptPreviousScopeFrame(); API_FUNCTION(Internal) static Array GetVisualScriptLocals(); API_FUNCTION(Internal) static bool EvaluateVisualScriptLocal(VisualScript* script, API_PARAM(Ref) VisualScriptLocal& local); API_FUNCTION(Internal) static void WipeOutLeftoverSceneObjects(); private: void OnEditorAssemblyLoaded(MAssembly* assembly); public: // [ScriptingObject] void DestroyManaged() override; };