| 78 | } |
| 79 | |
| 80 | void ScriptingSystem::Update(Timestep ts) |
| 81 | { |
| 82 | if (!Engine::IsPlayMode()) |
| 83 | return; |
| 84 | |
| 85 | auto& scriptingEngineNet = ScriptingEngineNet::Get(); |
| 86 | auto netEntities = m_Scene->m_Registry.view<NetScriptComponent>(); |
| 87 | |
| 88 | // Instance all the new entities |
| 89 | std::vector<Entity> entityJustInstanced; |
| 90 | for (auto& e : netEntities) |
| 91 | { |
| 92 | auto& netScriptComponent = netEntities.get<NetScriptComponent>(e); |
| 93 | if (!netScriptComponent.Initialized) |
| 94 | { |
| 95 | if (netScriptComponent.ScriptPath.empty()) |
| 96 | continue; |
| 97 | |
| 98 | auto entity = Entity{ e, m_Scene }; |
| 99 | |
| 100 | // Creates an instance of the entity script in C# |
| 101 | scriptingEngineNet.RegisterEntityScript(entity); |
| 102 | |
| 103 | netScriptComponent.Initialized = true; |
| 104 | entityJustInstanced.push_back(entity); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Call init on the newly created instance |
| 109 | for (auto& e : entityJustInstanced) |
| 110 | { |
| 111 | auto& netScriptComponent = e.GetComponent<NetScriptComponent>(); |
| 112 | if (e.IsValid() && scriptingEngineNet.HasEntityScriptInstance(e)) |
| 113 | { |
| 114 | // We can now call on init on it. |
| 115 | auto scriptInstance = scriptingEngineNet.GetEntityScript(e); |
| 116 | scriptInstance->InvokeMethod("OnInit"); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Then call update on all the other scripts |
| 121 | for (auto& e : netEntities) |
| 122 | { |
| 123 | NetScriptComponent& netScriptComponent = netEntities.get<NetScriptComponent>(e); |
| 124 | |
| 125 | if (netScriptComponent.ScriptPath.empty()) |
| 126 | continue; |
| 127 | |
| 128 | auto entity = Entity{ e, m_Scene }; |
| 129 | auto scriptInstance = scriptingEngineNet.GetEntityScript(entity); |
| 130 | scriptInstance->InvokeMethod("OnUpdate", ts.GetSeconds()); |
| 131 | } |
| 132 | |
| 133 | for (auto& widget : CanvasParser::Get().GetAllCustomWidgetInstance()) |
| 134 | { |
| 135 | const UUID& canvasInstanceUUID = widget.first.first; |
| 136 | const UUID& widgetInstanceUUID = widget.first.second; |
| 137 | if (scriptingEngineNet.HasCustomWidgetInstance(canvasInstanceUUID, widgetInstanceUUID)) |
nothing calls this directly
no test coverage detected