/// <summary> /// Sends packets to peers. /// Takes events regarding incoming packets and handles them. /// </summary> private void Update() { manager.PollEvents(); SetPacketRotation(); SetPacketPosition(); BuildDebug.Log("Raw Vector: ", Input.compass.rawVector); BuildDebug.Log("Gyro: ", Input.gyro.attitude.eulerAngles); BuildDebug.Log("Compass magnetic: ", Input.compass.magneticHeading); BuildDebug.Log("Compass true: ", Input.compass.trueHeading); BuildDebug.Log("Compass accuracy: ", Input.compass.headingAccuracy); var peer = manager.FirstPeer; if (peer == null || peer.ConnectionState != ConnectionState.Connected) { discoveryTimer += Time.deltaTime; if (discoveryTimer > 2f) { SendAndResetDiscoveryRequest(); } return; } SendPacketSerializable(PacketType.Transform, transformPacket, DeliveryMethod.Unreliable); }
/// <summary> /// Sets the position to send in the packet, calculates the positional difference from the anchor to the client and sends. /// </summary> private void SetPacketPosition() { Vector3 localDiff = CompassAlignedScene.instance.alignedLocalPeer.transform.localPosition - CompassAlignedScene.instance.alignedAnchor.transform.localPosition; transformPacket.position = localDiff; BuildDebug.Log("Sent Packet: ", transformPacket.position); }
/// <summary> /// Updates the transform of the aligned local peer according to the original local peer. /// </summary> private void UpdateAlignLocalPeer() { if (localPeer != null) { alignedLocalPeer.transform.SetPositionAndRotation(localPeer.transform.position, localPeer.transform.rotation); BuildDebug.Log("Local World Pos: ", alignedLocalPeer.transform.position); BuildDebug.Log("CliLocalent Align Pos: ", alignedLocalPeer.transform.localPosition); } }
/// <summary> /// Updates the transform of the aligned anchor according to the original anchor. /// </summary> private void UpdateAlignAnchor() { if (anchor != null) { alignedAnchor.transform.position = anchor.transform.position; BuildDebug.Log("Anchor World Pos: ", alignedAnchor.transform.position); BuildDebug.Log("Anchor Align Pos: ", alignedAnchor.transform.localPosition); } }
private void Update() { BuildDebug.Log("Start Compass: "******"Diff World Peer - Anchor: ", (alignedLocalPeer.transform.position - alignedAnchor.transform.position)); BuildDebug.Log("Diff Align Peer - Anchor: ", (alignedLocalPeer.transform.localPosition - alignedAnchor.transform.localPosition)); }