feat(physics): dispatch PhysX simulation events to scene scripts
This commit is contained in:
@@ -258,6 +258,28 @@ void ScriptEngine::OnLateUpdate(float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::DispatchPhysicsMessage(
|
||||
Components::GameObject* gameObject,
|
||||
ScriptPhysicsMessage message,
|
||||
Components::GameObject* other) {
|
||||
if (!m_runtimeRunning || !gameObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ScriptComponent* component : gameObject->GetComponents<ScriptComponent>()) {
|
||||
if (!component) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScriptInstanceState* state = FindState(component);
|
||||
if (!state || !ShouldScriptRun(*state) || !EnsureScriptReady(*state, true) || !state->enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
InvokePhysicsMessage(*state, message, other);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::OnScriptComponentEnabled(ScriptComponent* component) {
|
||||
if (!m_runtimeRunning || !component) {
|
||||
return;
|
||||
@@ -887,6 +909,14 @@ void ScriptEngine::InvokeLifecycleMethod(ScriptInstanceState& state, ScriptLifec
|
||||
m_runtime->SyncManagedFieldsToStorage(state.context);
|
||||
}
|
||||
|
||||
void ScriptEngine::InvokePhysicsMessage(
|
||||
ScriptInstanceState& state,
|
||||
ScriptPhysicsMessage message,
|
||||
Components::GameObject* other) {
|
||||
m_runtime->InvokePhysicsMessage(state.context, message, other);
|
||||
m_runtime->SyncManagedFieldsToStorage(state.context);
|
||||
}
|
||||
|
||||
void ScriptEngine::StopTrackingScript(ScriptInstanceState& state, bool runtimeStopping) {
|
||||
if (state.enabled) {
|
||||
InvokeLifecycleMethod(state, ScriptLifecycleMethod::OnDisable);
|
||||
|
||||
Reference in New Issue
Block a user