private bool DrawPortal(Color portalColor, RaycastHit2D rayCastHit, Vector2 mousePosition, Vector2 userPosition) { WallBehaviour wallHit = (WallBehaviour)rayCastHit.collider.GetComponent("WallBehaviour"); this.DrawLineEffect(portalColor, rayCastHit, userPosition); if (!wallHit) { return(false); } if (!wallHit.portalAvailable) { return(false); } bool portalOk = this.CheckSpaceInWall(wallHit.verticalWallLeft || wallHit.verticalWallRight, userPosition, ref rayCastHit, wallHit.wallGuid); if (!portalOk) { return(false); } ++this.portalCount; GameObject actualPortal; actualPortal = (this.portalCount % 2 == 0) ? portal1 : portal2; int portalOrientation; if (wallHit.verticalWallLeft || wallHit.verticalWallRight) { rayCastHit.point = new Vector2(rayCastHit.point.x - 0.75f, rayCastHit.point.y); if (wallHit.verticalWallRight) { rayCastHit.point = new Vector2(rayCastHit.point.x + 1.5f, rayCastHit.point.y); } portalOrientation = 0; } else { rayCastHit.point = new Vector2(rayCastHit.point.x, rayCastHit.point.y + 0.75f); if (wallHit.horizontalWallDown) { rayCastHit.point = new Vector2(rayCastHit.point.x, rayCastHit.point.y - 1.5f); } portalOrientation = 1; } PortalBehaviour portalScript = (PortalBehaviour)actualPortal.GetComponent("PortalBehaviour"); portalScript.PortalOn(rayCastHit.point, portalOrientation, wallHit); return(true); }
public void ResetPortals() { PortalBehaviour portal1 = GameObject.Find("portal1").GetComponent <PortalBehaviour>(); PortalBehaviour portal2 = GameObject.Find("portal2").GetComponent <PortalBehaviour>(); portal1.PortalOff(); portal2.PortalOff(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("Connection")) { PortalBehaviour portal = (PortalBehaviour)target; portal.PrintTarget(); } }
public void OnPortalCollision(PortalBehaviour thisPortal, PortalBehaviour negativePortal, Transform entityTransform, Rigidbody2D entityRigidBody) { if (negativePortal.horizontalPortalDown) { float yVelocity = Mathf.Abs(entityRigidBody.velocity.y); if (yVelocity < 10.0f) { yVelocity = 10.0f; } entityTransform.position = new Vector3(negativePortal.transform.position.x, negativePortal.transform.position.y + thisPortal.paddingVertical, entityTransform.position.z); this.ToUp(); entityRigidBody.velocity = new Vector2(entityRigidBody.velocity.x, yVelocity); } else if (negativePortal.horizontalPortalUp) { entityTransform.position = new Vector3(negativePortal.transform.position.x, negativePortal.transform.position.y - thisPortal.paddingVertical, entityTransform.position.z); this.ToDown(); } else if (negativePortal.verticalPortalLeft) { float yVelocity = entityRigidBody.velocity.y * -1.0f; yVelocity = (yVelocity == 0.0f) ? 10.1f : yVelocity; entityTransform.position = new Vector3(negativePortal.transform.position.x + thisPortal.paddingHorizontal, negativePortal.transform.position.y, entityTransform.position.z); this.ToRight(); entityRigidBody.velocity = new Vector2(yVelocity, 0.0f); } else if (negativePortal.verticalPortalRight) { float yVelocity = entityRigidBody.velocity.y; yVelocity = (yVelocity == 0.0f) ? -10.1f : yVelocity; entityTransform.position = new Vector3(negativePortal.transform.position.x - thisPortal.paddingHorizontal, negativePortal.transform.position.y, entityTransform.position.z); this.ToLeft(); entityRigidBody.velocity = new Vector2(yVelocity, 0.0f); } }
public void OnPortalCollision(PortalBehaviour thisPortal, PortalBehaviour negativePortal, Transform entityTransform, Rigidbody2D entityRigidBody) { if (negativePortal.horizontalPortalDown) { entityTransform.position = new Vector3(negativePortal.transform.position.x, negativePortal.transform.position.y + thisPortal.paddingVertical, entityTransform.position.z); this.ToUp(); } else if (negativePortal.horizontalPortalUp) { entityTransform.position = new Vector3(negativePortal.transform.position.x, negativePortal.transform.position.y - thisPortal.paddingVertical, entityTransform.position.z); this.ToDown(); } else if (negativePortal.verticalPortalLeft) { entityTransform.position = new Vector3(negativePortal.transform.position.x + thisPortal.paddingHorizontal, negativePortal.transform.position.y, entityTransform.position.z); this.ToRight(); } else if (negativePortal.verticalPortalRight) { entityTransform.position = new Vector3(negativePortal.transform.position.x - thisPortal.paddingHorizontal, negativePortal.transform.position.y, entityTransform.position.z); this.ToLeft(); } }
public void Init() { if (MapLoader.Loader is OpenSpace.Loader.R3Loader) { MapLoader l = MapLoader.Loader; foreach (SuperObject so in l.superObjects) { if (so.type == SuperObject.Type.IPO_2) { //Debug.LogWarning("TYPE 2 " + so.Gao.name); Portal portal = new Portal() { containerSO = so, containerIPO = so.data as IPO }; portal.cameraSO = SuperObject.FromOffset(portal.containerIPO.off_portalCamera); GeometricObject geo = portal.containerIPO.data.visualSet[0].obj as GeometricObject; portal.geometricObject = geo; if (geo != null) { GeometricObjectElementTriangles el = geo.elements[0] as GeometricObjectElementTriangles; portal.meshElement = el; portal.material = el.Gao.GetComponent <Renderer>().sharedMaterial; //Debug.LogWarning(so.type + " - " + portal.containerIPO.offset + " - " + portal.containerIPO.off_portalCamera); if (portal.cameraSO != null) { GameObject camGao = new GameObject("Portal Camera - " + portal.containerIPO.Gao.name + " - " + portal.cameraSO.Gao.name); Camera camera = camGao.AddComponent <Camera>(); camGao.transform.position = portal.cameraSO.matrix.GetPosition(true); camGao.transform.rotation = portal.cameraSO.matrix.GetRotation(true) * Quaternion.Euler(-180, 0, 0); camGao.transform.localScale = portal.cameraSO.matrix.GetScale(true); camera.fieldOfView = Camera.main.fieldOfView; camera.enabled = false; camGao.transform.SetParent(transform); portal.camera = camera; portals.Add(portal); } else { // it's a mirror portal.isMirror = true; GameObject camGao = new GameObject("Mirror Camera - " + portal.containerIPO.Gao.name); Camera camera = camGao.AddComponent <Camera>(); camGao.transform.position = geo.vertices[0]; /*camGao.transform.rotation = portal.cameraSO.matrix.GetRotation(true) * Quaternion.Euler(-180, 0, 0); * camGao.transform.localScale = portal.cameraSO.matrix.GetScale(true);*/ camera.fieldOfView = Camera.main.fieldOfView; camera.enabled = false; camGao.transform.SetParent(transform); portal.camera = camera; portals.Add(portal); } el.Gao.layer = LayerMask.NameToLayer("VisualMirror"); PortalBehaviour pb = el.Gao.AddComponent <PortalBehaviour>(); pb.m_ReflectLayers = (1 << LayerMask.NameToLayer("Visual")) | (1 << LayerMask.NameToLayer("VisualOnlyInMirror")); pb.portal = portal; pb.textureIndex = portal.material.GetInt("_NumTextures"); portal.material.SetInt("_NumTextures", pb.textureIndex + 1); } } } } loaded = true; }