protected virtual RaycastHit RaycastPortal(Transform portal, Transform otherPortal) { Vector3 fwd = -transform.up; Vector3 up = transform.forward; Vector3 pos = transform.position + up * 0.25f + fwd * 0.5f; LayerMask mask = AddPiece.CreateLayerMask(new int[] { 0, 2, 6, 7, 11, 24, 28, 29 }); RaycastHit[] hits = Physics.SphereCastAll(pos, 0.2f, fwd, 300f, mask); RaycastHit hit = new RaycastHit(); hit.distance = -1f; hit.point = pos; float min = float.MaxValue; for (int i = 0; i < hits.Length; i++) { if (hits[i].distance < min) { RaycastHit h = hits[i]; if (h.collider.transform.root == portal.transform || h.collider.isTrigger || VidyaMod.IsVirtualTrigger(h.collider.transform)) { continue; } if (!h.collider.transform.root.GetComponent <WinCondition>()) { if (h.collider.gameObject.layer == 2) { if (h.collider.transform.root == otherPortal.transform) { min = h.distance; h.distance = 0f; hit = h; } continue; } if (h.collider.attachedRigidbody) { if (h.collider.attachedRigidbody == Rigidbody) { continue; } } min = h.distance; h.distance = -1f; hit = h; continue; } min = h.distance; h.point = h.point + h.normal * (h.collider.name == "FloorBig" ? 0.02f : 0.2f); hit = h; } } return(hit); }
protected virtual RaycastHit Raycast(Vector3 pos, Vector3 dir, float dist, Portal portal, Portal other, float overlap = 0f) { LayerMask mask = AddPiece.CreateLayerMask(new int[] { 0, 2, 6, 7, 11, 24, 28, 29 }); RaycastHit[] hits = Physics.RaycastAll(pos, dir, dist, mask); RaycastHit hit = new RaycastHit(); hit.distance = dist; hit.point = pos + dir * dist; float min = float.MaxValue; for (int i = 0; i < hits.Length; i++) { if (hits[i].distance < min) { RaycastHit h = hits[i]; if (h.collider.transform.root == portal.transform) { continue; } if (h.collider.transform.root == BlockBehaviour.ParentMachine.transform.root) { continue; } float d = h.distance; if (h.collider.gameObject.layer == 2) { if (h.collider.transform.root != other.transform) { continue; } } else if (overlap > 0f) { if (!VidyaMod.IsVirtualTrigger(h.collider.transform)) { float diff = dist - h.distance; float o = diff > overlap ? overlap : diff; h.distance = h.distance + o; } } min = d; hit = h; } } /* * float r = dir.x * 0.5f + 0.75f; * float g = dir.y * 0.5f + 0.75f; * float b = dir.z * 0.5f + 0.75f; * Debug.DrawRay(pos, dir * dist, new Color(r, g, b, 0.2f)); * Debug.DrawRay(pos, dir * hit.distance, new Color(r, g, b, 1f));*/ return(hit); }
public static void OnSceneLoad(Scene scene, LoadSceneMode mode) { if (!hasLoaded) { return; } if (mode == LoadSceneMode.Single) { if (!AddPiece.IsMenuScene(scene.name)) { PortalingMaster.OnModLoad(); PortalDevice.RebuildForNewLevel(); } } }