// Update is called once per frame
        protected void Update()
        {
            //Check if the gameobject this script is attached to is through a portal
            if (!throughPortal && currentPortal && PortalUtils.IsBehind(transform.position, currentPortal.origin.position, currentPortal.origin.forward))
            {
                //If it is, move the gameobject to the doppleganger
                //Is this script going to teleport before its primary object?
                if (teleportScriptIndependantly)
                {
                    otherTransform.SetParent(transform.parent);
                    transform.SetParent(otherTransformParent);
                    throughPortal = true;
                    ActivateInheritance(gameObject);
                    resetTransform();
                }
                OnPassthrough();
            }
            else if (throughPortal && currentPortal && PortalUtils.IsBehind(transform.position, currentPortal.targetPortal.origin.position, currentPortal.targetPortal.origin.forward))
            {
                if (teleportScriptIndependantly)
                {
                    otherTransform.SetParent(otherTransformParent);
                    transform.SetParent(originalParent);
                    throughPortal = false;

                    resetTransform();
                }
                OnPassthrough();
            }
        }
Exemple #2
0
        /// <summary>
        /// Render a portal frame, assuming that the camera is in front of the portal and all conditions are met.
        /// </summary>
        /// <param name="camera">The camera rendering the portal</param>
        /// <param name="nearClipVerts">The vertices of the camera's near clip plane</param>
        private void TryRenderPortal(Camera camera, Vector3[] nearClipVerts)
        {
            UpdateScissor();
            //Tests object occlusion
            _meshFilter = gameObject.GetComponent <MeshFilter>();
            //bool isVisible = false;
            bool isVisible = true;

            //Check if the camera itself is behind the portal, even if the frustum isn't.

            if (!PortalUtils.IsBehind(camera.gameObject.transform.position, origin.position, origin.forward))
            {
                isVisible = true;
            }
            else
            {
                //Checks to see if any part of the camera is in front of the portal
                for (int i = 0; i < nearClipVerts.Length; i++)
                {
                    if (!PortalUtils.IsBehind(nearClipVerts[i], origin.position, origin.forward))
                    {
                        isVisible = true;
                        break;
                    }
                }
            }

            //Early return if no part of the camera is in front of the camera

            if (!isVisible)
            {
                return;
            }

            if ((isVisible || _CheeseActivated))
            {
                portalCamera.RenderIntoMaterial(camera, _portalMaterial, gameObject.GetComponent <MeshRenderer>(), _targetRenderer, _meshFilter.mesh, !nonObliqueOverride ? !_CheeseActivated : false, optimize, is3d);
                _rendered = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Checks if objects are in portal, and teleports them if they are. Also handles player entry.
        /// </summary>
        /// <param name="col"></param>
        public void E_OnTriggerStay(Collider col)
        {
            Teleportable teleportScript = col.GetComponent <Teleportable>();

            AddTeleportable(teleportScript);
            //Detects when head enters portal area
            if (col == headCollider)
            {
                _headInPortalTrigger = true;
            }

            if (enterable && teleportScript)
            {
                //Updates clip planes for disappearing effect
                if (!nonObliqueOverride)
                {
                    teleportScript.SetClipPlane(origin.position, origin.forward, teleportScript.oTeleportRends);
                    teleportScript.SetClipPlane(destination.position, -destination.forward, teleportScript.dTeleportRends);
                }
                if (GlobalPortalSettings.physicsPassthrough)
                {
                    //Makes objects collide with objects on the other side of the portal
                    foreach (Tuple <Collider, Collider> c in passthroughColliders)
                    {
                        teleportScript.AddCollision(c.Item2);
                    }

                    foreach (Collider c in bufferWall)
                    {
                        teleportScript.AddCollision(c);
                    }
                }


                //Passes portal info to teleport script
                teleportScript.SetPortalInfo(this);

                //Teleports objects
                if (PortalUtils.IsBehind(col.transform.position, origin.position, origin.forward) && !teleportScript.VisOnly)
                {
                    //_nearTeleportables.Remove(teleportScript);
                    //teleportScript.ResumeAllCollision();
                    RemoveTeleportable(teleportScript);
                    PortalUtils.TeleportObject(teleportScript.root.gameObject, origin, destination, teleportScript.root);
                    targetPortal.FixedUpdate();
                    targetPortal.SendMessage("E_OnTriggerStay", col);
                    teleportScript.Teleport();
                    targetPortal.UpdateDopplegangers();
                    targetPortal.physicsPassthrough.SendMessage("UpdatePhysics");
                    //physicsPassthrough.SendMessage("UpdatePhysics");

                    if (teleportScript == playerTeleportable)
                    {
                        targetPortal.UpdateDopplegangers();
                        targetPortal.IncomingCamera();
                        _CheeseActivated     = false;
                        _headInPortalTrigger = false;
                        //Resets the vis depth of the portal volume
                        if (!is3d)
                        {
                            transform.localScale = new Vector3(1f, 1f, 0f);
                        }

                        //Flips the nearby light tables

                        ArrayList tempList = new ArrayList(passthroughLights);
                        passthroughLights = targetPortal.passthroughLights;
                        targetPortal.passthroughLights = tempList;
                        foreach (Tuple <Light, GameObject> tup in passthroughLights)
                        {
                            tup.Item2.transform.parent = destination;
                        }
                        foreach (Tuple <Light, GameObject> tup in targetPortal.passthroughLights)
                        {
                            tup.Item2.transform.parent = targetPortal.destination;
                        }
                    }
                }
            }
        }