public Vector3 GetTrainPosition(out Vector3 forward, out Vector3 up) { double timeToLeave; int targetIndex = GetNextPointIndex(out timeToLeave); Railway.Point targetPoint = Railway.Manager.Instance.GetPoint(pointList[targetIndex].id); if (pointList[targetIndex].pointType != Railway.Point.EType.Joint && timeToLeave <= pointList[targetIndex].stayTime + PETools.PEMath.Epsilon) { forward = targetPoint.GetJointRotation() * Vector3.forward; if (targetIndex == pointCount - 1) { forward = -1 * forward; } up = Quaternion.Euler(targetPoint.rotation) * Vector3.up; stayStation = Railway.Manager.Instance.GetPoint(pointList[targetIndex].id); return(stayStation.GetJointPosition()); } stayStation = null; float timeToArrive = (float)(timeToLeave); if (pointList[targetIndex].pointType != Railway.Point.EType.Joint) { timeToArrive -= pointList[targetIndex].stayTime; } Vector3 targetPos = targetPoint.GetJointPosition(); Railway.Point prePoint = Railway.Manager.Instance.GetPoint(pointList[targetIndex - moveDir].id); Vector3 prePos = prePoint.GetJointPosition(); forward = moveDir * (targetPos - prePos).normalized; up = Vector3.Lerp(Quaternion.Euler(targetPoint.rotation) * Vector3.up , Quaternion.Euler(prePoint.rotation) * Vector3.up , timeToArrive * Railway.Manager.TrainSteerSpeed / (targetPos - prePos).magnitude); return(targetPos + (prePos - targetPos).normalized * Railway.Manager.TrainSteerSpeed * timeToArrive); }
public List <Railway.Point> GetNearPoint(Railway.Point centerPoint) { List <Railway.Point> retList = GetNearPoint(centerPoint.position, JointMaxDistance); retList.Remove(centerPoint); return(retList); }
public Stats GetStats() { Stats stats = new Stats(); Railway.Point lastPoint = null; foreach (Railway.Point point in pointList) { if (null != lastPoint) { stats.totalDis += Vector3.Distance(point.position, lastPoint.position); } lastPoint = point; if (point.pointType != Railway.Point.EType.Joint) { stats.stationNum++; } else { stats.jointNum++; } } return(stats); }
void UpdateRotation() { Vector3 forwrd = Vector3.zero; Railway.Point prePoint = GetPrePoint(); Railway.Point nextpoint = GetNextPoint(); Vector3 upDir = Quaternion.Euler(rotation) * Vector3.up; if (pointType != Railway.Point.EType.Joint) { upDir = Vector3.up; } if (null != prePoint) { forwrd = (position - prePoint.position).normalized; } if (null != nextpoint) { forwrd = (forwrd.normalized + (nextpoint.position - position).normalized).normalized; } else { forwrd = -forwrd; } if (forwrd != Vector3.zero) { rotation = Quaternion.LookRotation(forwrd, upDir).eulerAngles; } }
public Railway.Route GetRouteByPointId(int pointId) { Railway.Point point = GetPoint(pointId); if (null == point) { return(null); } return(GetRoute(point.routeId)); }
public Railway.Point GetAnotherEndPoint(Railway.Point endPoint) { Railway.Route route = GetRoute(endPoint.routeId); if (null != route) { if (route.GetPointByIndex(0) == endPoint) { return(route.GetPointByIndex(route.pointCount - 1)); } else { return(route.GetPointByIndex(0)); } } return(null); }
//network need it to resore public void Import(byte[] data) { PETools.Serialize.Import(data, (r) => { saveVersion = r.ReadInt32(); int count = r.ReadInt32(); for (int i = 0; i < count; i++) { Railway.Point point = Point.Deserialize(PETools.Serialize.ReadBytes(r)); mPointDic[point.id] = point; } count = r.ReadInt32(); for (int i = 0; i < count; i++) { Railway.Route route = Railway.Route.Deserialize(PETools.Serialize.ReadBytes(r)); mRouteList.Add(route); } //----------- if (saveVersion >= Version4) { StroyManager.m_Passengers.Clear(); int n = r.ReadInt32(); byte[] buff; for (int i = 0; i < n; i++) { buff = PETools.Serialize.ReadBytes(r); PassengerInfo pi = new PassengerInfo(); pi.Import(buff); StroyManager.m_Passengers.Add(pi.npcID, pi); } } }); foreach (Point point in mPointDic.Values) { point.UpdateLinkTarget(); } }
public Railway.Point AddPoint(Vector3 pos , int prePointId , Point.EType type = Point.EType.Joint , int pointId = -1) { if (GetPoint(pointId) != null) { return(null); } if (pointId == InvalId) { pointId = GetValidPointId(); } Railway.Point point = new Railway.Point(pointId, type); point.position = pos; if (type == Railway.Point.EType.Station) { point.stayTime = Railway.Manager.DefaultStayTime; } else if (type == Railway.Point.EType.End) { point.stayTime = Railway.Manager.DefaultStayTime;// / 2f; } else { point.stayTime = 0f; } mPointDic[point.id] = point; point.ChangePrePoint(prePointId); pointChangedEventor.Dispatch(new PointChanged() { bAdd = true, point = point }); return(point); }
public static Railway.Point GetTail(Railway.Point point) { if (point == null) { return(null); } while (true) { Railway.Point nextPoint = point.GetNextPoint(); if (nextPoint == null) { return(point); } else { point = nextPoint; } } }
public static Railway.Point GetHeader(Railway.Point point) { if (point == null) { return(null); } while (true) { Railway.Point prePoint = point.GetPrePoint(); if (prePoint == null) { return(point); } else { point = prePoint; } } }
public void Destroy() { Railway.Point getPoint = GetPrePoint(); if (null != getPoint) { getPoint.ChangeNextPoint(Railway.Manager.InvalId); } getPoint = GetNextPoint(); if (null != getPoint) { getPoint.ChangePrePoint(Railway.Manager.InvalId); } if (null != station) { GameObject.Destroy(station.gameObject); } }
public static void Travel(Railway.Point point, System.Action <Railway.Point> action) { if (point == null) { return; } while (true) { action(point); Railway.Point nextPoint = point.GetNextPoint(); if (nextPoint == null) { break; } else { point = nextPoint; } } }
public bool SetStayTime(int pointId, float time) { if (trainRunning) { return(false); } Railway.Point point = Railway.Manager.Instance.GetPoint(pointId); if (point == null) { return(false); } if (point.routeId != id) { return(false); } point.stayTime = time; UpdateTimeSchedule(); return(true); }
public void ChangeNextPoint(int nextID) { if (nextID == nextPointId) { return; } Railway.Point oldNextPoint = GetNextPoint(); nextPointId = nextID; if (null != oldNextPoint) { oldNextPoint.ChangePrePoint(Railway.Manager.InvalId); } Railway.Point newNextPoint = Railway.Manager.Instance.GetPoint(nextID); if (null != newNextPoint) { newNextPoint.ChangePrePoint(id); } UpdateRotation(); }
public void ChangePrePoint(int preId) { if (preId == prePointId) { return; } Railway.Point oldPrePoint = GetPrePoint(); prePointId = preId; if (null != oldPrePoint) { oldPrePoint.ChangeNextPoint(Railway.Manager.InvalId); } Railway.Point newPrePoint = Railway.Manager.Instance.GetPoint(preId); if (null != newPrePoint) { newPrePoint.ChangeNextPoint(id); } UpdateRotation(); }