Start of edit mode scripts

- Initialize script instances in edit mode
- Run OnCreate and OnUpdate for Entities with RunInEditMode-Attribute
This commit is contained in:
Simon Lübeß
2023-12-02 00:28:04 +01:00
parent 23b38a7a31
commit 5852e11ccb
5 changed files with 48 additions and 5 deletions
+8 -5
View File
@@ -600,12 +600,12 @@ namespace GlitchyEngine.World
{
/// No special update configuration (this does NOT mean nothing will be updated!)
None = 0x00,
/// Update editor-specific stuff
Editor = 0x01,
/// Update the physics related stuff
Physics = 0x02,
Physics = 0x01,
/// Execute scripts.
Scripts = 0x04,
Scripts = 0x02,
/// Update editor-specific stuff and also scripts (most only ever initialize, but some update!)
Editor = 0x04 | Scripts,
/// Update the runtume related stuff (e.g. execute scripts). Also run physics!
Runtime = Scripts | Physics,
}
@@ -630,7 +630,10 @@ namespace GlitchyEngine.World
if (!script.IsInitialized)
ScriptEngine.InitializeInstance(Entity(entity, this), script);
if (script.Instance == null)
// Skip OnCreate and OnUpdate invocation if we didn't create an instance
// (happens, if script component has no script class associated)
// Also skip if we are in edit mode and the class doesn't have the RunInEditMode-Attribute
if (script.Instance == null || (mode.HasFlag(.Editor) && !script.Instance.ScriptClass.RunInEditMode))
continue;
if (mode.HasFlag(.Runtime))