} //Update end. /// <summary> /// Compares an objects current transform values to the saved ones in order to detect transform/position changes. /// </summary> /// <param name="objNum">Array position of the object we seek.</param> private bool HasTransformChanged(int objNum) { // Pull out the struct we compare against. RemoteObjectInfoStruct structToCompareAgainst = GetRemoteObjectInfo(objNum); if (structToCompareAgainst.oldPos != listOfGameObjToKeepSynced[objNum].transform.localPosition) { Debug.Log("Position change detected @ listOfGameObjToKeepSynced[" + objNum + "]"); return(true); } // Rotation is double checked due to problems at small angles. // aaRotation.Equals(bbRotation) == false && (aaRotation != bbRotation) if (structToCompareAgainst.oldRota != listOfGameObjToKeepSynced[objNum].transform.localRotation && structToCompareAgainst.oldRota.Equals(listOfGameObjToKeepSynced[objNum].transform.localRotation) == false) { Debug.Log("Rotation change detected @ listOfGameObjToKeepSynced[" + objNum + "]"); return(true); } if (structToCompareAgainst.oldScale != listOfGameObjToKeepSynced[objNum].transform.localScale) { Debug.Log("Scale change detected @ listOfGameObjToKeepSynced[" + objNum + "]"); return(true); } return(false); }
/// <summary> /// Saves a copy of current object positions, which will then be compared against to detect position changes of said objects. /// </summary> /// <param name="objNumber">Array position of the object we seek.</param> private void AssignOldTransform(int objNum) { // Pull out the struct which we want to update. RemoteObjectInfoStruct structToUpdate = GetRemoteObjectInfo(objNum); structToUpdate.oldPos = listOfGameObjToKeepSynced[objNum].transform.localPosition; structToUpdate.oldRota = listOfGameObjToKeepSynced[objNum].transform.localRotation; structToUpdate.oldScale = listOfGameObjToKeepSynced[objNum].transform.localScale; }
private void Start() { SyncMessaging.Instance.MessageHandlers[SyncMessaging.TestMessageID.HeadTransform] = UpdateHeadTransform; SyncMessaging.Instance.MessageHandlers[SyncMessaging.TestMessageID.ObjectTransform] = UpdateObjectTransform; // SharingStage should be valid at this point. SharingStage.Instance.SharingManagerConnected += Connected; // Loop through all gameObjects that gotta stay synched, create structs for them and save their transform. for (int i = 0; i < listOfGameObjToKeepSynced.Count; i++) { RemoteObjectInfoStruct objInfoStruct; objInfoStruct = new RemoteObjectInfoStruct(); objInfoStruct.objNumber = i; // Now add this to the Dict. remoteObjectDict.Add(i, objInfoStruct); // After struct creation, init values. AssignOldTransform(i); } }