Fixed scripts OnUpdate not being called in play mode

This commit is contained in:
Simon Lübeß
2023-12-13 14:01:23 +01:00
parent 4a2635a8c3
commit ed756f5847
2 changed files with 11 additions and 25 deletions
+3 -3
View File
@@ -379,9 +379,9 @@ namespace GlitchyEditor
switch (_sceneState)
{
case .Edit:
updateMode = .Editor;
updateMode = .Scripts | .EditMode;
case .Play:
updateMode = .Runtime;
updateMode = .Scripts | .Physics;
case .Simulate:
updateMode = .Physics;
}
@@ -398,7 +398,7 @@ namespace GlitchyEditor
*/
GameTime gt = null;
if (updateMode == .Editor)
if (updateMode.HasFlag(.EditMode))
{
gt = gameTime;
}
+7 -21
View File
@@ -599,10 +599,11 @@ namespace GlitchyEngine.World
Physics = 0x01,
/// Execute scripts.
Scripts = 0x02,
/// Update editor-specific stuff
EditMode = 0x04,
/// 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,
//RuntimeMode = Scripts | Physics,
}
private append List<Entity> _destroyQueue = .();
@@ -628,14 +629,14 @@ namespace GlitchyEngine.World
// 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))
if (script.Instance == null || (mode.HasFlag(.EditMode) && !script.Instance.ScriptClass.RunInEditMode))
continue;
if (mode.HasFlag(.Runtime))
script.Instance.InvokeOnCreate();
script.Instance.InvokeOnCreate();
}
if (mode.HasFlag(.Runtime))
// Update the script, if we aren't in editor or it has RunInEditMode-Attribute
if (!mode.HasFlag(.EditMode) || script.Instance.ScriptClass.RunInEditMode)
{
if (_updateBlockList.Contains(entity))
_updateBlockList.Remove(entity);
@@ -645,21 +646,6 @@ namespace GlitchyEngine.World
}
}
/*if (mode.HasFlag(.Editor))
{
// Run editor scripts
for (var (entity, script) in _ecsWorld.Enumerate<ScriptComponent>())
{
if (!script.InInstantiated)
{
ScriptEngine.InitializeInstance(Entity(entity, this), script);
}
// TODO: Editor update
//script.Instance.InvokeOnUpdate(gameTime.DeltaTime);
}
}*/
if (mode.HasFlag(.Physics))
{
// Update 2D physics