public void OnRecvRotation(Vector3 rotation, double time) { //Debug.Log("OnRecvRotation rot:" + rotation.ToString() + "time:" + time); RotBean pr = new RotBean(); pr.rot = rotation; pr.time = time; headRotationQueue.Enqueue(pr); }
void Update() { if (!IsLocolPlayer) { // 更新位置 if (headPisitionQueue.Count() > 0) { // 包过多则丢包 if (headPisitionQueue.Count() > 60) { while (headPisitionQueue.Count() > 5) { headPisitionQueue.Dequeue(); } _lastUpdatePosTime = 0; } PosBean pr = headPisitionQueue.Peek(); while ((pr.time - _lastUpdatePosTime) < 0 && headPisitionQueue.Count() > 0) { Debug.Log("错误顺序 curTime:" + pr.time + " lastTime:" + _lastUpdatePosTime); headPisitionQueue.Dequeue(); pr = headPisitionQueue.Peek(); } if (_lastUpdatePosTime == 0) { _lastUpdatePosTime = pr.time - 0.04; } double curTime = TimeHelper.GetTimestamp(); if ((curTime - _lastUpdatePosLocalTime) > ((pr.time - _lastUpdatePosTime) - 10)) { // Debug.Log("VirtualManPlayer qeuelen:" + headPisitionQueue.Count() + " curTime:" + curTime + " prTime:" + pr.time // + " localLerp:" + (curTime - _lastUpdateTime) + " reomteLerp:" + (pr.time - _lastPosTime) + " curPos:" + head.position); pr = headPisitionQueue.Dequeue(); if (Math.Abs(FF(_lastPos.x) - FF(pr.pos.x)) < 0.2 && Math.Abs(FF(_lastPos.y) - FF(pr.pos.y)) < 0.2 && Math.Abs(FF(_lastPos.z) - FF(pr.pos.z)) < 0.2) { } else { iTween.MoveTo(gameObject, MrShareData._instance.RelativeTransform.TransformPoint(pr.pos), (float)(pr.time - _lastUpdatePosTime) / 1000); } _lastPos = pr.pos; _lastUpdatePosTime = pr.time; _lastUpdatePosLocalTime = curTime; } } // 更新姿态 if (headRotationQueue.Count() > 0) { // 包过多则丢包 if (headRotationQueue.Count() > 60) { while (headRotationQueue.Count() > 5) { headRotationQueue.Dequeue(); } _lastUpdateRotTime = 0; } RotBean r = headRotationQueue.Peek(); while ((r.time - _lastUpdateRotTime) < 0 && headRotationQueue.Count() > 0) { Debug.Log("错误顺序 curTime:" + r.time + " lastTime:" + _lastUpdateRotTime); headRotationQueue.Dequeue(); r = headRotationQueue.Peek(); } if (_lastUpdateRotTime == 0) { _lastUpdateRotTime = r.time - 0.04; } double curTime = TimeHelper.GetTimestamp(); if ((curTime - _lastUpdateRotLocalTime) > ((r.time - _lastUpdateRotTime) - 10)) { r = headRotationQueue.Dequeue(); if (FFR(_lastRot.x) == FFR(r.rot.x) && FFR(_lastRot.y) == FFR(r.rot.y) && FFR(_lastRot.z) == FFR(r.rot.z)) { } else { head.localEulerAngles = r.rot; } _lastRot = r.rot; _lastUpdateRotTime = r.time; _lastUpdateRotLocalTime = curTime; } } } }
void Update() { if (!IsLocolPlayer) { // 更新位置 if (headPisitionQueue.Count() > 0) { // 包过多则丢包 if (headPisitionQueue.Count() > 60) { while (headPisitionQueue.Count() > 5) { headPisitionQueue.Dequeue(); } _lastUpdatePosTime = 0; } PosBean pr = headPisitionQueue.Peek(); while ((pr.time - _lastUpdatePosTime) < 0 && headPisitionQueue.Count() > 0) { Debug.Log("错误顺序 curTime:" + pr.time + " lastTime:" + _lastUpdatePosTime); headPisitionQueue.Dequeue(); pr = headPisitionQueue.Peek(); } if (_lastUpdatePosTime == 0) { _lastUpdatePosTime = pr.time - 0.04; } double curTime = TimeHelper.GetTimestamp(); if ((curTime - _lastUpdatePosLocalTime) > ((pr.time - _lastUpdatePosTime) - 10)) { // Debug.Log("VirtualManPlayer qeuelen:" + headPisitionQueue.Count() + " curTime:" + curTime + " prTime:" + pr.time // + " localLerp:" + (curTime - _lastUpdateTime) + " reomteLerp:" + (pr.time - _lastPosTime) + " curPos:" + head.position); pr = headPisitionQueue.Dequeue(); Vector3 posHead = HoloWorldSync.Instance.WorldRoot.transform.TransformPoint(pr.pos);//MrShareData._instance.RelativeTransform.TransformPoint(pr.pos); #if !UNITY_EDITOR && UNITY_IPHONE posHead = new Vector3(posHead.x, MrShareData._instance.FloorY * 2, posHead.z); #else posHead = new Vector3(posHead.x, MrShareData._instance.FloorY, posHead.z); #endif iTween.MoveTo(head.gameObject, posHead, (float)(pr.time - _lastUpdatePosTime) / 1000); body.localEulerAngles = new Vector3(0, head.localEulerAngles.y, 0); #if !UNITY_EDITOR && UNITY_IPHONE body.localPosition = new Vector3(head.localPosition.x, MrShareData._instance.FloorY * 2, head.localPosition.z); #else body.localPosition = new Vector3(head.localPosition.x, MrShareData._instance.FloorY, head.localPosition.z); #endif // Debug.Log ("VirtualManPlayer position:" + head.position.ToString() + " worldposition:" + HoloWorldSync.Instance.WorldRoot.transform.position.ToString() + //" localScale:" + head.localScale.ToString() + " recvposition:" + pr.pos.ToString()); _lastPos = pr.pos; _lastUpdatePosTime = pr.time; _lastUpdatePosLocalTime = curTime; } } // 更新姿态 if (headRotationQueue.Count() > 0) { // 包过多则丢包 if (headRotationQueue.Count() > 60) { while (headRotationQueue.Count() > 5) { headRotationQueue.Dequeue(); } _lastUpdateRotTime = 0; } RotBean r = headRotationQueue.Peek(); while ((r.time - _lastUpdateRotTime) < 0 && headRotationQueue.Count() > 0) { Debug.Log("错误顺序 curTime:" + r.time + " lastTime:" + _lastUpdateRotTime); headRotationQueue.Dequeue(); r = headRotationQueue.Peek(); } if (_lastUpdateRotTime == 0) { _lastUpdateRotTime = r.time - 0.04; } double curTime = TimeHelper.GetTimestamp(); if ((curTime - _lastUpdateRotLocalTime) > ((r.time - _lastUpdateRotTime) - 10)) { r = headRotationQueue.Dequeue(); head.localEulerAngles = r.rot; body.localEulerAngles = new Vector3(0, head.localEulerAngles.y, 0); _lastUpdateRotTime = r.time; _lastUpdateRotLocalTime = curTime; //Debug.Log ("VirtualManPlayer localEulerAngles:" + head.localEulerAngles.ToString() // + " body.localEulerAngles:" + body.localEulerAngles.ToString() // + " recvrotation:" + r.rot.ToString()); } } // 更新动画 if (animQueue.Count() > 0) { AnimBean anim = animQueue.Dequeue(); VirtualManAnimatorChange(anim.animId); } } else { //走路动画 if (canCheck) { StartCoroutine(WalkCheck()); } } }