private void Update() { if (IsHotkeyEnabled && UnityEngine.Input.GetKey(KeyCode.LeftShift) && UnityEngine.Input.GetKey(KeyCode.LeftAlt) && UnityEngine.Input.GetKeyDown(KeyCode.B)) { CreateUserReport(); } UnityUserReporting.CurrentClient.IsSelfReporting = IsSelfReporting; UnityUserReporting.CurrentClient.SendEventsToAnalytics = SendEventsToAnalytics; if (UserReportButton != null) { UserReportButton.interactable = (State == UserReportingState.Idle); } if (UserReportForm != null) { UserReportForm.enabled = (State == UserReportingState.ShowingForm); } if (SubmittingPopup != null) { SubmittingPopup.enabled = (State == UserReportingState.SubmittingForm); } if (ErrorPopup != null) { ErrorPopup.enabled = isShowingError; } unityUserReportingUpdater.Reset(); StartCoroutine(unityUserReportingUpdater); }
// Update is called once per frame void Update() { // Ping everyone every 5 seconds float now = Time.time; if ((Time.time - lastPingTime) > 5) { foreach (var connection in remoteConnectionStates) { if (connection.Value.networkState == ConnectionState.Connected) { Net.Ping(connection.Key); } } lastPingTime = now; } if (OVRInput.GetDown(OVRInput.RawButton.B) || Input.GetKeyDown(KeyCode.Space)) { var caemraRig = GameObject.Find("OVRCameraRig"); caemraRig.transform.RotateAround(new Vector3(0, 0, 0), new Vector3(0, 1, 0), 90); } if (ReadyToPlay()) { if (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > 0.55) { if ((rightHandHeld == null) && (rightHandGrabber.otherCollider != null)) { if (rightHandGrabber.otherCollider == deckCollider) { rightHandHeld = deckController.getNextCard( deckController.transform.position, deckController.transform.rotation); } else { rightHandHeld = rightHandGrabber.otherCollider.gameObject; } // Might not be in the hand, but it's as costly to check and no harm in trying if (cardHandController.isCardInHand(rightHandHeld)) { cardHandController.ReleaseCard(rightHandHeld); } rightHandHeld.transform.parent = rightHandAnchor.transform; rightHandHeld.GetComponent <Rigidbody>().isKinematic = true; rightHandHeld.GetComponent <SimpleGrabbable>().isGrabbed = true; } } if (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) < 0.35) { if (rightHandHeld != null) { rightHandHeld.transform.parent = null; rightHandHeld.GetComponent <Rigidbody>().isKinematic = false; rightHandHeld.GetComponent <SimpleGrabbable>().isGrabbed = false; if ((rightHandHeld.GetComponent <CardController>() != null) && cardHandController.isHighlighting) { cardHandController.AddCard(rightHandHeld); } else { // Notify remote users that we are dropping the card OnRigidBodyUpdate(rightHandHeld.GetComponent <Rigidbody>()); } rightHandHeld = null; } } } Packet packet; while ((packet = Net.ReadPacket()) != null) { byte[] packetBuf = new byte[packet.Size]; packet.ReadBytes(packetBuf); packet.Dispose(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(packetBuf))) { var type = (PacketType)binaryReader.ReadByte(); var userID = binaryReader.ReadUInt64(); switch (type) { case PacketType.AVATAR_UPDATE: var position = binaryReader.ReadVector3(); var orientation = binaryReader.ReadQuaternion(); var avatarPacketSequence = binaryReader.ReadInt32(); var avatar = remoteAvatars.ContainsKey(userID) ? remoteAvatars[userID] : null; if (avatar != null) { OvrAvatarPacket avatarPacket = null; int size = binaryReader.ReadInt32(); byte[] sdkData = binaryReader.ReadBytes(size); IntPtr tempPacket = Oculus.Avatar.CAPI.ovrAvatarPacket_Read((UInt32)sdkData.Length, sdkData); avatarPacket = new OvrAvatarPacket { ovrNativePacket = tempPacket }; avatar.transform.position = position; avatar.transform.rotation = orientation; avatar.GetComponent <OvrAvatarRemoteDriver>().QueuePacket(avatarPacketSequence, avatarPacket); } break; case PacketType.TRACKED_OBJECT_UPDATE: var objName = binaryReader.ReadString(); var objPosition = binaryReader.ReadVector3(); var objOrientation = binaryReader.ReadQuaternion(); var obj = getTrackedObject(objName); if (obj != null) { obj.transform.parent = null; var rigidBody = obj.GetComponent <Rigidbody>(); if (rigidBody) { rigidBody.isKinematic = true; } obj.transform.position = objPosition; obj.transform.rotation = objOrientation; } break; case PacketType.DECK_UPDATE: var cardCount = binaryReader.ReadByte(); var cardIndex = binaryReader.ReadByte(); var cards = binaryReader.ReadBytes(cardCount); UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Received - deck update from " + userID.ToString() + " - " + cardIndex); deckController.updateDeck(new List <byte>(cards), cardIndex); break; case PacketType.CARD_HAND_UPDATE: var cardHandCount = binaryReader.ReadByte(); var cardHand = binaryReader.ReadBytes(cardHandCount); if (remoteCardHands.ContainsKey(userID)) { remoteCardHands[userID].updateCardHand(cardHand); } else if (userID != localUser.ID) // Can happen on state updates { if (pendingCardHandUpdates.ContainsKey(userID)) { pendingCardHandUpdates[userID] = cardHand; } else { pendingCardHandUpdates.Add(userID, cardHand); } } break; case PacketType.RIGID_BODY_UPDATE: var rigidObjName = binaryReader.ReadString(); var rigidBodyPostion = binaryReader.ReadVector3(); var rigidBodyRotation = binaryReader.ReadQuaternion(); // TO DO - This isn't really an exciting implementation var rigidObj = getTrackedObject(rigidObjName); if (rigidObj != null) { rigidObj.transform.position = rigidBodyPostion; rigidObj.transform.rotation = rigidBodyRotation; rigidObj.GetComponent <Rigidbody>().isKinematic = false; } break; case PacketType.RESET: UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Received - reset from " + userID.ToString()); resetGame(); break; case PacketType.STATE_UPDATE_REQUEST: UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Received - state update request from " + userID.ToString()); deckController.SendUpdate(); cardHandController.SendUpdate(); foreach (var remoteCardHand in remoteCardHands.Values) { remoteCardHand.SendUpdate(); } // Cards without a parent won't be captured otherwise var allCards = GameObject.FindGameObjectsWithTag("PlayingCard"); foreach (var card in allCards) { if (card.transform.parent == null) { OnRigidBodyUpdate(card.GetComponent <Rigidbody>()); } } break; default: UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Error, "Unexpected packete received " + type.ToString()); Debug.LogError("Unexpected case"); break; } } } var mouthsAttached = new List <ulong>(); foreach (var id in pendingMouthAnchorAttach) { if (remoteAvatars.ContainsKey(id) && remoteAvatars[id].MouthAnchor != null) { if (remoteAvatars[id].MouthAnchor.GetComponent <VoipAudioSourceHiLevel>() != null) { UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Warning, "Attempted to add second voip audio source for " + id.ToString()); } else { var source = remoteAvatars[id].MouthAnchor.AddComponent <VoipAudioSourceHiLevel>(); source.senderID = id; UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Adding voip audio source for " + id.ToString()); } mouthsAttached.Add(id); } } foreach (var id in mouthsAttached) { pendingMouthAnchorAttach.Remove(id); } var handsAttached = new List <ulong>(); foreach (var id in pendingLeftCardHandAttach) { if (remoteAvatars.ContainsKey(id) && remoteAvatars[id].HandLeft != null) { if (remoteAvatars[id].HandLeft.gameObject.GetComponent <CardHandController>() != null) { UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Warning, "Attempted to add second card hand for " + id.ToString()); } else { var newCardHand = remoteAvatars[id].HandLeft.gameObject.AddComponent <CardHandController>(); newCardHand.canastyController = this; remoteCardHands.Add(id, newCardHand); UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Adding remote hand object for " + id.ToString()); } if (pendingCardHandUpdates.ContainsKey(id)) { UnityUserReporting.CurrentClient.LogEvent(UserReportEventLevel.Info, "Updating pending card hand for " + id.ToString()); remoteCardHands[id].updateCardHand(pendingCardHandUpdates[id]); } handsAttached.Add(id); } } foreach (var id in handsAttached) { pendingLeftCardHandAttach.Remove(id); pendingCardHandUpdates.Remove(id); } // Update unity user reporting reportingUpdater.Reset(); this.StartCoroutine(this.reportingUpdater); }
private void Update() { m_unityUserReportingUpdater.Reset(); this.StartCoroutine((IEnumerator)m_unityUserReportingUpdater); }