Add post-compile and pre-destroy events to MjScene.

PiperOrigin-RevId: 498516529
Change-Id: I52dbf135e3260ca2999069bcb9f9b9ad648595d2
This commit is contained in:
Tom Erez
2022-12-29 22:42:31 -08:00
committed by Copybara-Service
parent 95b9a0f215
commit f78ebeab96
+4
View File
@@ -78,9 +78,11 @@ public class MjScene : MonoBehaviour {
private List<MjComponent> _orderedComponents; private List<MjComponent> _orderedComponents;
public EventHandler<MjStepArgs> postInitEvent;
public EventHandler preUpdateEvent; public EventHandler preUpdateEvent;
public EventHandler<MjStepArgs> ctrlCallback; public EventHandler<MjStepArgs> ctrlCallback;
public EventHandler postUpdateEvent; public EventHandler postUpdateEvent;
public EventHandler<MjStepArgs> preDestroyEvent;
protected unsafe void Start() { protected unsafe void Start() {
CreateScene(); CreateScene();
@@ -167,6 +169,7 @@ public class MjScene : MonoBehaviour {
// Compile the scene from the Mjcf. // Compile the scene from the Mjcf.
CompileScene(sceneMjcf, _orderedComponents); CompileScene(sceneMjcf, _orderedComponents);
} }
postInitEvent?.Invoke(this, new MjStepArgs(Model, Data));
return sceneMjcf; return sceneMjcf;
} }
@@ -305,6 +308,7 @@ public class MjScene : MonoBehaviour {
// Destroys the Mujoco scene. // Destroys the Mujoco scene.
public unsafe void DestroyScene() { public unsafe void DestroyScene() {
preDestroyEvent?.Invoke(this, new MjStepArgs(Model, Data));
if (Model != null) { if (Model != null) {
MujocoLib.mj_deleteModel(Model); MujocoLib.mj_deleteModel(Model);
Model = null; Model = null;