void SwitchHitPoint(TeleportingPoint tp) { if (tp != hitTelepoint) { if (tp != null) { tp.OnEnterPoint(this); } if (hitTelepoint != null) { hitTelepoint.OnExitPoint(); } hitTelepoint = tp; //Modify Target Point if (hitTelepoint != null) { LineDrawer.modifiedTargetPoint = hitTelepoint.transform.position; } else { LineDrawer.modifiedTargetPoint = null; } } }
public static TeleportingPoint FindClosestTelepoints(Vector3 p) { float dist = 100f; TeleportingPoint closest = null; foreach (var tp in teleportingPoints) { if (!tp.gameObject.activeInHierarchy || !tp.enabled) { continue; } var d = Vector3.Distance(tp.transform.position, p); if (d < dist) { dist = d; closest = tp; } } if (dist < suckingRadius) { return(closest); } else { return(null); } }
public static TeleportingPoint FindClosestTelepoints(Vector3 p) { float dist = 100f; TeleportingPoint closest = null; foreach (var tp in teleportingPoints) { var d = Vector3.Distance(tp.transform.position, p); if (d < dist) { dist = d; closest = tp; } } if (dist < suckingRadius) { return(closest); } else { return(null); } }
// Update is called once per frame void Update() { if (WorkingTeleporter != null && WorkingTeleporter != this) { return; } if (!transportingEnabled || inTransporting) { if (LineDrawer) { LineDrawer.drawLine = false; } return; } if (LineDrawer) { if (GetTeleportingCommand()) { WorkingTeleporter = this; if (!LineDrawer.drawLine)//Enable teleporting predicting { GlobalEventManager.SendEvent("VRPlayer.BeginTeleportingPredict"); LineDrawer.drawLine = true; } //Teleporting Area Update TeleportingArea ta = null; if (LineDrawer.HitCollider != null) { ta = LineDrawer.HitCollider.GetComponent <TeleportingArea>(); } AnticipateHitPoint = LineDrawer.AnticipateHitPoint;//Acquire anticipated hit point of predicting line,not the final hit point SwitchHitArea(ta); //Telepoint Update if (AnticipateHitPoint != null) { TeleportingPoint tp = TeleportingPoint.FindClosestTelepoints(AnticipateHitPoint.Value);//Check if a telepoint is near the anicipate hit point SwitchHitPoint(tp); } else { SwitchHitPoint(null); } } else { if (LineDrawer.drawLine) { AnticipateHitPoint = null; LineDrawer.drawLine = false; if (hitArea != null) { hitArea.OnTeleport(); } if (hitTelepoint != null) { hitTelepoint.OnTeleport(); } SwitchHitArea(null); SwitchHitPoint(null); GlobalEventManager.SendEvent("VRPlayer.StopTeleportingPredict"); WorkingTeleporter = null; if (LineDrawer.Status == HittingStatus.HitTeleportingArea || LineDrawer.Status == HittingStatus.HitModifiedTarget) { StartBodyTransporting(); GlobalEventManager.SendEvent("TransportBody"); } } } } }