mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Instancing prefab through code should instance body and scripts immediatly
This commit is contained in:
@@ -82,41 +82,10 @@ namespace Nuake
|
||||
if (!Engine::IsPlayMode())
|
||||
return;
|
||||
|
||||
InitializeNewScripts();
|
||||
|
||||
auto& scriptingEngineNet = ScriptingEngineNet::Get();
|
||||
auto netEntities = m_Scene->m_Registry.view<NetScriptComponent>();
|
||||
|
||||
// Instance all the new entities
|
||||
std::vector<Entity> entityJustInstanced;
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
auto& netScriptComponent = netEntities.get<NetScriptComponent>(e);
|
||||
if (!netScriptComponent.Initialized)
|
||||
{
|
||||
if (netScriptComponent.ScriptPath.empty())
|
||||
continue;
|
||||
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
|
||||
// Creates an instance of the entity script in C#
|
||||
scriptingEngineNet.RegisterEntityScript(entity);
|
||||
|
||||
netScriptComponent.Initialized = true;
|
||||
entityJustInstanced.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
// Call init on the newly created instance
|
||||
for (auto& e : entityJustInstanced)
|
||||
{
|
||||
auto& netScriptComponent = e.GetComponent<NetScriptComponent>();
|
||||
if (e.IsValid() && scriptingEngineNet.HasEntityScriptInstance(e))
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(e);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
|
||||
// Then call update on all the other scripts
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
@@ -187,6 +156,44 @@ namespace Nuake
|
||||
ScriptingEngineNet::Get().Uninitialize();
|
||||
}
|
||||
|
||||
void ScriptingSystem::InitializeNewScripts()
|
||||
{
|
||||
auto& scriptingEngineNet = ScriptingEngineNet::Get();
|
||||
auto netEntities = m_Scene->m_Registry.view<NetScriptComponent>();
|
||||
|
||||
// Instance all the new entities
|
||||
std::vector<Entity> entityJustInstanced;
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
auto& netScriptComponent = netEntities.get<NetScriptComponent>(e);
|
||||
if (!netScriptComponent.Initialized)
|
||||
{
|
||||
if (netScriptComponent.ScriptPath.empty())
|
||||
continue;
|
||||
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
|
||||
// Creates an instance of the entity script in C#
|
||||
scriptingEngineNet.RegisterEntityScript(entity);
|
||||
|
||||
netScriptComponent.Initialized = true;
|
||||
entityJustInstanced.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
// Call init on the newly created instance
|
||||
for (auto& e : entityJustInstanced)
|
||||
{
|
||||
auto& netScriptComponent = e.GetComponent<NetScriptComponent>();
|
||||
if (e.IsValid() && scriptingEngineNet.HasEntityScriptInstance(e))
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(e);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptingSystem::DispatchPhysicCallbacks()
|
||||
{
|
||||
auto& scriptingEngineNet = ScriptingEngineNet::Get();
|
||||
|
||||
Reference in New Issue
Block a user