/// <summary> /// Updates the transform of the corresponding MSceneObject /// </summary> public virtual void UpdateTransform(bool raiseEvent = true) { string parent = this.MSceneObject.Transform.Parent; //Set the transform to the current values this.MSceneObject.Transform.Position = this.transform.position.ToMVector3(); this.MSceneObject.Transform.Rotation = this.transform.rotation.ToMQuaternion(); this.MSceneObject.Transform.Parent = parent; if (raiseEvent) { //only transmit the changed data UnitySceneAccess.TransformationChanged(this.MSceneObject, this.MSceneObject.Transform.Position, this.MSceneObject.Transform.Rotation, this.MSceneObject.Transform.Parent); this.transform.hasChanged = false; } }
// Update is called once per frame protected virtual void Update() { //Handle physics if (this.rigidBody != null && physicsEnabled) { this.rigidBody.detectCollisions = this.UpdatePhysicsCurrentFrame; this.rigidBody.isKinematic = !this.UpdatePhysicsCurrentFrame; //Reset the value this.UpdatePhysicsCurrentFrame = true; } //Handle fixed velocity if (this.Velocity.magnitude > 0 && this.rigidBody != null) { if (this.rigidBody != null) { this.rigidBody.velocity = this.Velocity; } } //Check the transformation changes if (this.transform.hasChanged && this.transformTracker.HasChanged(this.transform)) { //Write the transform of the mscene object this.transformTracker.Update(transform); //Signalize transformation change UnitySceneAccess.TransformationChanged(this.MSceneObject, this.MSceneObject.Transform.Position, this.MSceneObject.Transform.Rotation, this.MSceneObject.Transform.Parent); } //Also track the changes in terms of physics if (this.rigidBody != null) { List <MPhysicsInteraction> physicsChanges = this.physicsTracker.GetChanges(this.rigidBody); //If some changes occur -> Update the phsysics properties and inform the UnitySceneAccess if (physicsChanges.Count > 0) { this.physicsTracker.Update(this.rigidBody); UnitySceneAccess.PhysicsPropertiesChanged(this.MSceneObject, this.MSceneObject.PhysicsProperties); } } }