Modified how scripts are added and updated to support runtime adding of scripts

This commit is contained in:
Kah Wei 2022-11-13 16:07:14 +08:00
parent 23320863e3
commit af361062e7
1 changed files with 26 additions and 12 deletions

View File

@ -73,8 +73,16 @@ namespace SHADE
// Add the script in
entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script);
if (Application::IsPlaying)
{
script->Awake();
script->Start();
}
else
{
awakeList.Add(script);
startList.Add(script);
}
script->OnAttached();
return script;
@ -451,9 +459,10 @@ namespace SHADE
continue;
// Update each script
for each (Script^ script in entity.Value)
ScriptList^ scripts = entity.Value;
for (int i = 0; i < scripts->Count; ++i)
{
script->FixedUpdate();
scripts[i]->FixedUpdate();
}
}
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
@ -468,9 +477,10 @@ namespace SHADE
continue;
// Update each script
for each (Script^ script in entity.Value)
ScriptList^ scripts = entity.Value;
for (int i = 0; i < scripts->Count; ++i)
{
script->Update();
scripts[i]->Update();
}
}
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
@ -485,9 +495,10 @@ namespace SHADE
continue;
// Update each script
for each (Script^ script in entity.Value)
ScriptList^ scripts = entity.Value;
for (int i = 0; i < scripts->Count; ++i)
{
script->LateUpdate();
scripts[i]->LateUpdate();
}
}
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
@ -503,9 +514,10 @@ namespace SHADE
continue;
// Update each script
for each (Script^ script in entity.Value)
ScriptList^ scripts = entity.Value;
for (int i = 0; i < scripts->Count; ++i)
{
script->OnDrawGizmos();
scripts[i]->OnDrawGizmos();
}
}
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
@ -537,8 +549,9 @@ namespace SHADE
auto entityScripts = scripts[entity.first];
if (entityScripts->Count > 0)
{
for each (Script ^ script in entityScripts)
for (int i = 0; i < entityScripts->Count; ++i)
{
Script^ script = entityScripts[i];
switch (collisionInfo.GetCollisionState())
{
case SHCollisionEvent::State::ENTER:
@ -578,8 +591,9 @@ namespace SHADE
auto entityScripts = scripts[entity.first];
if (entityScripts->Count > 0)
{
for each (Script ^ script in entityScripts)
for (int i = 0; i < entityScripts->Count; ++i)
{
Script^ script = entityScripts[i];
switch (triggerInfo.GetCollisionState())
{
case SHCollisionEvent::State::ENTER: