public static RandomRoadName GetRoadName(RandomRoadName checkingName, int forcePick = -1) { RandomRoadName returnName = null; if (Instance().m_roadNames != null && Instance().m_roadNames.Length > 0) { List<RandomRoadName> validNames = new List<RandomRoadName>(); foreach (RandomRoadName name in Instance().m_roadNames) { if (ValidRoadName(name, checkingName)) { validNames.Add(name); } } if (validNames.Count > 0) { int nameToPick = (int)Math.Round(UnityEngine.Random.Range(0f, validNames.Count - 1)); nameToPick = forcePick != -1 ? forcePick : nameToPick; returnName = validNames[nameToPick]; } } else { Debug.LogWarning("Road Namer: There's no road names in the XML file! Can't use the randomiser!"); } return returnName; }
private static bool ValidRoadName(RandomRoadName nameToCheck, RandomRoadName checkingName) { bool valid = true; if (nameToCheck.MinimumLanes > 0 && checkingName.MinimumLanes <= nameToCheck.MinimumLanes) { valid = false; } if (nameToCheck.MaximumLanes > 0 && checkingName.MaximumLanes > nameToCheck.MaximumLanes) { valid = false; } if (nameToCheck.NameHasToContain != null && nameToCheck.NameHasToContain != "" && !checkingName.NameHasToContain.Contains(nameToCheck.NameHasToContain.ToLower())) { valid = false; } return valid; }
public static string GenerateRandomRoadName(ushort netSegmentId) { string returnRoadName = null; if (netSegmentId != 0) { NetManager netManager = Singleton<NetManager>.instance; NetSegment netSegment = netManager.m_segments.m_buffer[(int)netSegmentId]; NetSegment.Flags segmentFlags = netSegment.m_flags; if (segmentFlags.IsFlagSet(NetSegment.Flags.Created)) { int forwardLanes = 0, backwardLanes = 0, totalLanes = 0; string roadName = netSegment.Info.name.ToLower(); RandomRoadPrefix selectedPrefix = null; RandomRoadName selectedRoadName = null; RandomRoadPostfix selectedPostfix = null; netSegment.CountLanes(netSegmentId, NetInfo.LaneType.Vehicle | NetInfo.LaneType.PublicTransport | NetInfo.LaneType.TransportVehicle, VehicleInfo.VehicleType.All, ref forwardLanes, ref backwardLanes); totalLanes = forwardLanes + backwardLanes; Debug.Log(roadName); Debug.Log(forwardLanes.ToString()); Debug.Log(backwardLanes.ToString()); RandomRoadPrefix checkingPrefix = new RandomRoadPrefix() { NameHasToContain = roadName, MinimumLanes = totalLanes, MaximumLanes = totalLanes }; RandomRoadName checkingName = new RandomRoadName() { NameHasToContain = roadName, MinimumLanes = totalLanes, MaximumLanes = totalLanes }; RandomRoadPostfix checkingPostfix = new RandomRoadPostfix() { NameHasToContain = roadName, MinimumLanes = totalLanes, MaximumLanes = totalLanes }; selectedRoadName = RandomNameUtility.GetRoadName(checkingName); if (selectedRoadName != null) { bool lowercaseInitial = false; returnRoadName = ""; if (!selectedRoadName.NoPrefix) { selectedPrefix = RandomNameUtility.GetRoadPrefix(checkingPrefix, selectedRoadName.ForcePrefix); } if (!selectedRoadName.NoPostfix) { selectedPostfix = RandomNameUtility.GetRoadPostfix(checkingPostfix, selectedRoadName.ForcePostfix); } if(selectedPrefix != null) { returnRoadName += selectedPrefix.Name; returnRoadName += selectedPrefix.SpaceBetweenName ? " " : ""; lowercaseInitial = selectedPrefix.LowercaseInitialOnName; } returnRoadName += lowercaseInitial ? selectedRoadName.Name.ToLower() : selectedRoadName.Name; //TODO: There might be an instance where we actually only want the initial to be lowercase. Needs improvement if (selectedPostfix != null) { returnRoadName += selectedPostfix.SpaceBetweenName ? " " : ""; returnRoadName += selectedPostfix.Name; } returnRoadName = TranslateRoadName(netSegmentId, returnRoadName); } } } return returnRoadName; }