/// <summary> /// Updates the "dopplegangers", the visual counterparts, to all teleportable objects near portals. /// </summary> private void UpdateDopplegangers() { //Updates dopplegangers foreach (Teleportable tp in _nearTeleportables) { PortalUtils.TeleportObject(tp.doppleganger, origin, destination, tp.doppleganger.transform, tp.root); //PortalUtils.TeleportObject(tp.doppleganger, origin, destination, tp.doppleganger.transform); StartCoroutine(tp.UpdateDoppleganger()); } //Updates duplicate lights for (int i = 0; i < passthroughLights.Count; i++) { ((Tuple <Light, GameObject>)passthroughLights[i]).Item2.GetComponent <Light>().GetCopyOf(((Tuple <Light, GameObject>)passthroughLights[i]).Item1); (((Tuple <Light, GameObject>)passthroughLights[i])).Item2.transform.localPosition = origin.InverseTransformPoint(((Tuple <Light, GameObject>)passthroughLights[i]).Item1.gameObject.transform.position); } }
public void UpdatePhysics() { if (initialized) { Bounds exclBounds = new Bounds(transform.position, bounds.extents * 2f); //Grow bounds to encapsulate all duped colliders foreach (Tuple <Collider, Collider> c in portal.passthroughColliders) { exclBounds.Encapsulate(c.Item2.bounds); } ArrayList nearDynamicColliders = new ArrayList(Physics.OverlapBox(transform.position, exclBounds.extents * 2.2f, transform.rotation, ~0, QueryTriggerInteraction.Ignore)); foreach (Collider n in nearDynamicColliders) { if (!n || n.gameObject.isStatic) { continue; } foreach (Tuple <Collider, Collider> c in portal.passthroughColliders) { if (!c.Item2) { continue; } if (!ignoredCollisions.Contains(new Tuple <int, int>(n.GetInstanceID(), c.Item2.GetInstanceID()))) { Physics.IgnoreCollision(c.Item2, n, true); ignoredCollisions.Add(new Tuple <int, int>(n.GetInstanceID(), c.Item2.GetInstanceID())); } } foreach (Collider c in portal.targetPortal.bufferWall) { if (!ignoredCollisions.Contains(new Tuple <int, int>(n.GetInstanceID(), c.GetInstanceID()))) { Physics.IgnoreCollision(c, n, true); ignoredCollisions.Add(new Tuple <int, int>(n.GetInstanceID(), c.GetInstanceID())); } } } if (GlobalPortalSettings.physicsPassthrough && initialized) { for (int i = 0; i < portal.passthroughColliders.Count; i++) { var tup = (Tuple <Collider, Collider>)portal.passthroughColliders[i]; //tup.Item2.transform.localPosition = portal.destination.InverseTransformPoint(tup.Item1.transform.position); PortalUtils.TeleportObject(tup.Item2.gameObject, portal.destination, portal.origin, tup.Item2.gameObject.transform, tup.Item1.transform); // tup.Item2.transform.rotation = portal.destination.rotation * Quaternion.Inverse(portal.origin.rotation) * tup.Item1.transform.rotation; /* * tup.Item2.transform.localScale = new Vector3( * tup.Item1.transform.lossyScale.x / portal.destination.localScale.x, * tup.Item1.transform.lossyScale.y / portal.destination.localScale.y, * tup.Item1.transform.lossyScale.z / portal.destination.localScale.z);*/ tup.Item2.transform.localScale = new Vector3( tup.Item1.transform.lossyScale.x * (portal.origin.lossyScale.x / portal.destination.lossyScale.x), tup.Item1.transform.lossyScale.y * (portal.origin.lossyScale.y / portal.destination.lossyScale.y), tup.Item1.transform.lossyScale.z * (portal.origin.lossyScale.z / portal.destination.lossyScale.z)); } } } }
/// <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; } } } } }