Ejemplo n.º 1
0
        /// <summary>
        /// Unity engine object Update() hook
        /// </summary>
        private void Update()
        {
            if (!isClosing)
            {
                if (!IsStereo)
                {
                    LeftEye.transform.position = location;
                    LeftEye.transform.LookAt(lookAt, up);
                    this.LeftEye.Render();
                    StartCoroutine(SendFrame(false));
                }
                else if (cameraNeedUpdated)
                {
                    this.LeftEye.projectionMatrix  = stereoLeftProjectionMatrix;
                    this.RightEye.projectionMatrix = stereoRightProjectionMatrix;
                    this.LeftEye.Render();
                    this.RightEye.Render();
                    StartCoroutine(SendFrame(true));
                }
            }

            // if the eye config changes, reconfigure
            if (this.lastSetupVisibleEyes.HasValue &&
                this.lastSetupVisibleEyes.Value != this.IsStereo)
            {
                SetupActiveEyes();
            }

            // check if we're in the editor, and fail out if we aren't loading the plugin in editor
            if (Application.isEditor && !UseEditorNativePlugin)
            {
                return;
            }

            // if we got an offer, track that we're connected to them
            // in a way that won't trip our connection logic (we don't
            // want to accidently make them an offer, just an answer)
            if (offerPeer.HasValue && offerSucceeded)
            {
                previousPeer          = PeerList.Peers.First(p => p.Id == offerPeer.Value);
                PeerList.SelectedPeer = previousPeer;
            }

            // check if we need to connect to a peer, and if so, do it
            if ((previousPeer == null && PeerList.SelectedPeer != null) ||
                (previousPeer != null && PeerList.SelectedPeer != null && !previousPeer.Equals(PeerList.SelectedPeer)))
            {
                Plugin.ConnectToPeer(PeerList.SelectedPeer.Id);
                previousPeer = PeerList.SelectedPeer;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Unity engine object Update() hook
        /// </summary>
        private void Update()
        {
            if (!isClosing)
            {
                transform.position = location;
                transform.LookAt(lookAt, up);

                // apply stereo projection if needed
                if (this.IsStereo &&
                    !stereoLeftProjection.isIdentity &&
                    !stereoRightProjection.isIdentity)
                {
                    this.LeftEye.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, stereoLeftProjection * this.LeftEye.worldToCameraMatrix);
                    this.RightEye.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, stereoRightProjection * this.RightEye.worldToCameraMatrix);
                }
            }

            // if the eye config changes, reconfigure
            if (this.lastSetupVisibleEyes.HasValue &&
                this.lastSetupVisibleEyes.Value != this.IsStereo)
            {
                SetupActiveEyes();
            }

            // check if we're in the editor, and fail out if we aren't loading the plugin in editor
            if (Application.isEditor && !UseEditorNativePlugin)
            {
                return;
            }

            // encode the entire render texture at the end of the frame
            StartCoroutine(Plugin.EncodeAndTransmitFrame());

            // if we got an offer, track that we're connected to them
            // in a way that won't trip our connection logic (we don't
            // want to accidently make them an offer, just an answer)
            if (offerPeer.HasValue && offerSucceeded)
            {
                previousPeer          = PeerList.Peers.First(p => p.Id == offerPeer.Value);
                PeerList.SelectedPeer = previousPeer;
            }

            // check if we need to connect to a peer, and if so, do it
            if ((previousPeer == null && PeerList.SelectedPeer != null) ||
                (previousPeer != null && PeerList.SelectedPeer != null && !previousPeer.Equals(PeerList.SelectedPeer)))
            {
                Plugin.ConnectToPeer(PeerList.SelectedPeer.Id);
                previousPeer = PeerList.SelectedPeer;
            }
        }