protected void Start() { if (MiddleVR.VRClusterMgr.IsCluster() && !MiddleVR.VRClusterMgr.IsServer()) { enabled = false; return; } if (MiddleVR.VRPhysicsMgr == null) { MiddleVRTools.Log(0, "[X] No PhysicsManager found when creating a planar constraint."); enabled = false; return; } vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine(); if (physicsEngine == null) { return; } if (m_PhysicsConstraint == null) { m_PhysicsConstraint = physicsEngine.CreateConstraintPlanarWithUniqueName(name); if (m_PhysicsConstraint == null) { MiddleVRTools.Log(0, "[X] Could not create a planar physics constraint '" + name + "'."); } else { GC.SuppressFinalize(m_PhysicsConstraint); m_MVREventListener = new vrEventListener(OnMVRNodeDestroy); m_PhysicsConstraint.AddEventListener(m_MVREventListener); m_PhysicsConstraintName = m_PhysicsConstraint.GetName(); AddConstraint(); } } }
protected void OnDestroy() { if (m_PhysicsConstraint == null) { return; } if (MiddleVR.VRPhysicsMgr == null) { return; } vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine(); if (physicsEngine == null) { return; } physicsEngine.DestroyConstraint(m_PhysicsConstraintName); m_PhysicsConstraint = null; m_PhysicsConstraintName = ""; }