public static void doAutomation(ushort lineID, TransportLine.Flags __state) { TLMUtils.doLog("OLD: " + __state + " ||| NEW: " + Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags); if (lineID > 0 && (__state & TransportLine.Flags.Complete) == TransportLine.Flags.None && (__state & TransportLine.Flags.Temporary) == TransportLine.Flags.None) { if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.Complete) != TransportLine.Flags.None && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags.Temporary)) == TransportLine.Flags.None) { if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_COLOR_ENABLED)) { TLMController.instance.AutoColor(lineID); } if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_NAME_ENABLED)) { TLMController.instance.AutoName(lineID); } TLMController.instance.LineCreationToolbox.incrementNumber(); TLMTransportLineExtension.instance.SafeCleanEntry(lineID); } } if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.Complete) == TransportLine.Flags.None && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.CustomColor) != TransportLine.Flags.None ) { Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags &= ~TransportLine.Flags.CustomColor; } }
private void syncForm() { TransportSystemDefinition tsd = TransportSystemDefinition.from(transportTool.m_prefab); var configIdx = tsd.toConfigIndex(); if (TLMLineUtils.hasPrefix(transportTool.m_prefab)) { linePrefixDropDown.isVisible = true; linePrefixDropDown.items = TLMUtils.getPrefixesOptions(configIdx, false); linePrefixDropDown.selectedIndex = getCurrentPrefix(); lineNumberTxtBox.text = getCurrentNumber().ToString(); lineNumberTxtBox.width = 90; lineNumberTxtBox.relativePosition = new Vector3(85f, 45f); lineNumberTxtBox.maxLength = 3; prefixIncrementChk.isChecked = TLMConfigWarehouse.getCurrentConfigBool(configIdx | TLMConfigWarehouse.ConfigIndex.PREFIX_INCREMENT); prefixIncrementChk.isVisible = true; } else { linePrefixDropDown.isVisible = false; lineNumberTxtBox.text = getCurrentNumber().ToString(); lineNumberTxtBox.width = 170; lineNumberTxtBox.relativePosition = new Vector3(5f, 45f); lineNumberTxtBox.maxLength = 4; prefixIncrementChk.isVisible = false; } updateUI(); }
public void incrementNumber() { //TLMUtils.doLog("Increment Toolbox num"); TransportSystemDefinition tsd = TransportSystemDefinition.from(transportTool.m_prefab); int num = nextLineNumber; bool prefixIncrementVal = TLMConfigWarehouse.getCurrentConfigBool(tsd.toConfigIndex() | TLMConfigWarehouse.ConfigIndex.PREFIX_INCREMENT); //TLMUtils.doLog("prefixIncrement = " + prefixIncrementVal + "| num = " + num); while (((num + 1) & 0xFFFF) == 0 || TLMLineUtils.isNumberUsed((num + 1) & 0xFFFF, tsd, 0)) { if (!TLMLineUtils.hasPrefix(transportTool.m_prefab) || !prefixIncrementVal) { num++; } else { num++; num /= 1000; num++; num &= 0x4F; num *= 1000; num--; } } nextLineNumber = (ushort)num; syncForm(); }
private static void redrawMap(ToolStatus __state) { if (__state.m_lineCurrent > 0 || (Singleton <TransportManager> .instance.m_lines.m_buffer[TLMController.instance.CurrentSelectedId].m_flags & TransportLine.Flags.Complete) == TransportLine.Flags.None) { TLMController.instance.setCurrentSelectedId(__state.m_lineCurrent); if (__state.m_lineCurrent > 0 && TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_COLOR_ENABLED)) { TLMController.instance.AutoColor(__state.m_lineCurrent, true, true); } } }
public static bool isLineNamingEnabled(this TLMConfigWarehouse.ConfigIndex idx) { switch (idx) { case TLMConfigWarehouse.ConfigIndex.ADDRESS_NAME_CONFIG: return(true); case TLMConfigWarehouse.ConfigIndex.RESIDENTIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.COMMERCIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.INDUSTRIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.NATURAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.UNUSED2_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.CITIZEN_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOURISM_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.OFFICE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.ROAD_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.ELECTRICITY_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.WATER_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.BEAUTIFICATION_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.GARBAGE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.HEALTHCARE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.POLICEDEPARTMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.EDUCATION_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.MONUMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.FIREDEPARTMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.PUBLICTRANSPORT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.DISASTER_SERVICE_CONFIG: return(TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.USE_FOR_AUTO_NAMING_REF | idx)); case TLMConfigWarehouse.ConfigIndex.PLANE_CONFIG: case TLMConfigWarehouse.ConfigIndex.BUS_CONFIG: case TLMConfigWarehouse.ConfigIndex.METRO_CONFIG: case TLMConfigWarehouse.ConfigIndex.TRAIN_CONFIG: case TLMConfigWarehouse.ConfigIndex.TRAM_CONFIG: case TLMConfigWarehouse.ConfigIndex.CABLE_CAR_CONFIG: case TLMConfigWarehouse.ConfigIndex.MONORAIL_CONFIG: case TLMConfigWarehouse.ConfigIndex.BLIMP_CONFIG: case TLMConfigWarehouse.ConfigIndex.FERRY_CONFIG: case TLMConfigWarehouse.ConfigIndex.SHIP_CONFIG: case TLMConfigWarehouse.ConfigIndex.TAXI_CONFIG: case TLMConfigWarehouse.ConfigIndex.BALLOON_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOUR_BUS_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOUR_PED_CONFIG: return(TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.PUBLICTRANSPORT_USE_FOR_AUTO_NAMING_REF | idx)); default: return(false); } }
public static uint getPriority(this TLMConfigWarehouse.ConfigIndex idx) { uint saida; switch (idx) { case TLMConfigWarehouse.ConfigIndex.ADDRESS_NAME_CONFIG: return((uint)TLMConfigWarehouse.namingOrder.Length); case TLMConfigWarehouse.ConfigIndex.RESIDENTIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.COMMERCIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.INDUSTRIAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.NATURAL_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.UNUSED2_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.CITIZEN_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOURISM_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.OFFICE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.ROAD_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.ELECTRICITY_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.WATER_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.BEAUTIFICATION_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.GARBAGE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.HEALTHCARE_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.POLICEDEPARTMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.EDUCATION_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.MONUMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.FIREDEPARTMENT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.PUBLICTRANSPORT_SERVICE_CONFIG: case TLMConfigWarehouse.ConfigIndex.DISASTER_SERVICE_CONFIG: saida = TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.USE_FOR_AUTO_NAMING_REF | idx) ? (uint)Array.IndexOf(TLMConfigWarehouse.namingOrder, idx) : uint.MaxValue; break; case TLMConfigWarehouse.ConfigIndex.PLANE_CONFIG: case TLMConfigWarehouse.ConfigIndex.SHIP_CONFIG: saida = TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.PUBLICTRANSPORT_USE_FOR_AUTO_NAMING_REF | idx) ? (uint)Array.IndexOf(TLMConfigWarehouse.namingOrder, idx) : uint.MaxValue; break; case TLMConfigWarehouse.ConfigIndex.TAXI_CONFIG: case TLMConfigWarehouse.ConfigIndex.CABLE_CAR_CONFIG: case TLMConfigWarehouse.ConfigIndex.MONORAIL_CONFIG: case TLMConfigWarehouse.ConfigIndex.FERRY_CONFIG: case TLMConfigWarehouse.ConfigIndex.BLIMP_CONFIG: case TLMConfigWarehouse.ConfigIndex.BUS_CONFIG: case TLMConfigWarehouse.ConfigIndex.METRO_CONFIG: case TLMConfigWarehouse.ConfigIndex.TRAIN_CONFIG: case TLMConfigWarehouse.ConfigIndex.TRAM_CONFIG: case TLMConfigWarehouse.ConfigIndex.BALLOON_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOUR_BUS_CONFIG: case TLMConfigWarehouse.ConfigIndex.TOUR_PED_CONFIG: saida = TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.PUBLICTRANSPORT_USE_FOR_AUTO_NAMING_REF | idx) ? 3 : uint.MaxValue; break; default: saida = uint.MaxValue; break; } if (TLMSingleton.instance != null && TLMSingleton.debugMode) { TLMUtils.doLog("ConfigIndex.getPriority(): {0} ==> {1}", idx.ToString(), saida); } return(saida); }
public void SimulationStep(ushort lineID) { if (!m_initialized) { m_initialized = true; for (int i = 0; i < Singleton <TransportManager> .instance.m_lines.m_buffer.Length; i++) { m_flagsLastState[i] = Singleton <TransportManager> .instance.m_lines.m_buffer[i].m_flags; } } var flagsChanged = (m_flagsLastState[lineID] ^ Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags); m_flagsLastState[lineID] = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags; if ((flagsChanged & TransportLine.Flags.Complete) != TransportLine.Flags.None) { if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_COLOR_ENABLED)) { TLMController.instance.AutoColor(lineID); } if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_NAME_ENABLED)) { TLMUtils.setLineName(lineID, TLMUtils.calculateAutoName(lineID)); } } if (TransportLinesManagerMod.instance != null && TransportLinesManagerMod.debugMode) { TLMUtils.doLog("LTLMTransportLine SimulationStep!"); } TransportInfo info = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].Info; TLMCW.ConfigIndex lineType = TLMCW.getDefinitionForLine(lineID).toConfigIndex(); float defaultCostPerPassengerCapacity = TLMCW.getCostPerPassengerCapacityLine(lineType); if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].Complete) { int vehicleCount = 0; int installedCapacity = 0; if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_vehicles != 0) { VehicleManager instance = Singleton <VehicleManager> .instance; ushort nextId = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_vehicles; int loopCount = 0; while (nextId != 0) { ushort nextLineVehicle = instance.m_vehicles.m_buffer[(int)nextId].m_nextLineVehicle; vehicleCount++; installedCapacity += TLMLineUtils.getVehicleCapacity(nextId); nextId = nextLineVehicle; if (++loopCount > 16384) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } } uint prefix = 0; if (TLMConfigWarehouse.getCurrentConfigInt(TLMConfigWarehouse.getConfigIndexForTransportInfo(info) | TLMConfigWarehouse.ConfigIndex.PREFIX) != (int)ModoNomenclatura.Nenhum) { prefix = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_lineNumber / 1000u; } float budgetMultiplierPrefix = TLMUtils.getExtensionFromConfigIndex(TLMCW.getConfigIndexForTransportInfo(info)).getBudgetMultiplierForHour(prefix, (int)Singleton <SimulationManager> .instance.m_currentDayTimeHour) / 100f; var flagToCheck = (TransportLine.Flags.DisabledNight | TransportLine.Flags.DisabledDay); if (budgetMultiplierPrefix == 0 && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & flagToCheck) == TransportLine.Flags.None) { int flagsToAdd = (int)(TransportLine.Flags.DisabledDay | TransportLine.Flags.DisabledNight) | (int)(TLMTransportLineFlags.ZERO_BUDGET_SETTED); if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_SETTED) == TransportLine.Flags.None) { if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None) { flagsToAdd |= (int)TLMTransportLineFlags.ZERO_BUDGET_DAY; } if ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None) { flagsToAdd |= (int)TLMTransportLineFlags.ZERO_BUDGET_NIGHT; } } Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags |= (TransportLine.Flags)flagsToAdd; } else if ((budgetMultiplierPrefix > 0 && (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)(TLMTransportLineFlags.ZERO_BUDGET_SETTED)) != TransportLine.Flags.None)) { bool actDay = (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_DAY) != TransportLine.Flags.None; bool actNight = (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & (TransportLine.Flags)TLMTransportLineFlags.ZERO_BUDGET_NIGHT) != TransportLine.Flags.None; Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags &= (TransportLine.Flags) ~(TLMTransportLineFlags.ZERO_BUDGET_DAY | TLMTransportLineFlags.ZERO_BUDGET_NIGHT | TLMTransportLineFlags.ZERO_BUDGET_SETTED); TLMLineUtils.setLineActive(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID], actDay, actNight); } bool active; if (Singleton <SimulationManager> .instance.m_isNightTime) { active = ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledNight) == TransportLine.Flags.None); } else { active = ((Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_flags & TransportLine.Flags.DisabledDay) == TransportLine.Flags.None); } uint steps = 0u; float distance = 0f; bool broken = false; if (Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops != 0) { NetManager instance2 = Singleton <NetManager> .instance; ushort stops = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_stops; ushort nextStop = stops; int count = 0; while (nextStop != 0) { ushort num8 = 0; if (active) { NetNode[] expr_10A_cp_0 = instance2.m_nodes.m_buffer; ushort expr_10A_cp_1 = nextStop; expr_10A_cp_0[(int)expr_10A_cp_1].m_flags = (expr_10A_cp_0[(int)expr_10A_cp_1].m_flags & ~NetNode.Flags.Disabled); } else { NetNode[] expr_130_cp_0 = instance2.m_nodes.m_buffer; ushort expr_130_cp_1 = nextStop; expr_130_cp_0[(int)expr_130_cp_1].m_flags = (expr_130_cp_0[(int)expr_130_cp_1].m_flags | NetNode.Flags.Disabled); } for (int i = 0; i < 8; i++) { ushort segment = instance2.m_nodes.m_buffer[(int)nextStop].GetSegment(i); if (segment != 0 && instance2.m_segments.m_buffer[(int)segment].m_startNode == nextStop) { distance += instance2.m_segments.m_buffer[(int)segment].m_averageLength; num8 = instance2.m_segments.m_buffer[(int)segment].m_endNode; if ((instance2.m_segments.m_buffer[(int)segment].m_flags & NetSegment.Flags.PathLength) == NetSegment.Flags.None) { broken = true; } break; } } steps += 1u; nextStop = num8; if (nextStop == stops) { break; } if (++count >= 32768) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } } float lineCost = vehicleCount * info.m_maintenanceCostPerVehicle / 100;// * defaultCostPerPassengerCapacity; if (lineCost != 0) { Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Maintenance, m_linesCost.m_buffer[lineID], info.m_class); } int budget = Singleton <EconomyManager> .instance.GetBudget(info.m_class); int necessaryVehicles; if (!active) { necessaryVehicles = 0; } else { necessaryVehicles = TLMVehiclesLineManager.instance[lineID]; if (necessaryVehicles == 0) { if (broken) { necessaryVehicles = vehicleCount; } else { necessaryVehicles = Mathf.CeilToInt(budget * budgetMultiplierPrefix * distance / (info.m_defaultVehicleDistance * 100f)); } } } if (steps != 0u && vehicleCount < necessaryVehicles) { TransferManager.TransferReason vehicleReason = info.m_vehicleReason; int index = Singleton <SimulationManager> .instance.m_randomizer.Int32(steps); ushort stop = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].GetStop(index); if (vehicleReason != TransferManager.TransferReason.None && stop != 0) { TransferManager.TransferOffer offer = default(TransferManager.TransferOffer); offer.Priority = necessaryVehicles - vehicleCount + 1; offer.TransportLine = lineID; offer.Position = Singleton <NetManager> .instance.m_nodes.m_buffer[stop].m_position; offer.Amount = 1; offer.Active = false; Singleton <TransferManager> .instance.AddIncomingOffer(vehicleReason, offer); } } else if (vehicleCount > necessaryVehicles) { int index2 = Singleton <SimulationManager> .instance.m_randomizer.Int32((uint)vehicleCount); ushort vehicle = Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].GetVehicle(index2); if (vehicle != 0) { VehicleManager instance3 = Singleton <VehicleManager> .instance; VehicleInfo info2 = instance3.m_vehicles.m_buffer[(int)vehicle].Info; info2.m_vehicleAI.SetTransportLine(vehicle, ref instance3.m_vehicles.m_buffer[(int)vehicle], 0); } } } if ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 4095u) >= 3840u) { Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers.Update(); Singleton <TransportManager> .instance.m_passengers[(int)info.m_transportType].Add(ref Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers); Singleton <TransportManager> .instance.m_lines.m_buffer[lineID].m_passengers.Reset(); } }
private void updateUI(bool syncFromInput = false) { TransportSystemDefinition tsd = TransportSystemDefinition.from(transportTool.m_prefab); TLMLineUtils.GetNamingRulesFromTSD(out ModoNomenclatura prefixo, out Separador sep, out ModoNomenclatura sufixo, out ModoNomenclatura nonPrefix, out bool zeros, out bool invertPrefixSuffix, tsd); if (syncFromInput) { String value = "0" + lineNumberTxtBox.text; int valPrefixo = linePrefixDropDown.selectedIndex; ushort num = ushort.Parse(value); if (prefixo != ModoNomenclatura.Nenhum) { num = (ushort)(valPrefixo * 1000 + (num % 1000)); } if (nextLineNumber + 1 != num) { nextLineNumber = (ushort)(num - 1); } } var configIdx = tsd.toConfigIndex(); Color color; if (TLMConfigWarehouse.getCurrentConfigBool(TLMConfigWarehouse.ConfigIndex.AUTO_COLOR_ENABLED)) { color = TLMUtils.CalculateAutoColor((ushort)(nextLineNumber + 1), TLMConfigWarehouse.getConfigIndexForTransportInfo(transportTool.m_prefab), true); } else { color = TLMConfigWarehouse.getColorForTransportType(configIdx); } lineNumberTxtBox.color = color; lineFormat.color = color; lineFormat.backgroundSprite = TLMLineUtils.GetIconForIndex(configIdx); lineNumber.text = TLMUtils.getString(prefixo, sep, sufixo, nonPrefix, (nextLineNumber + 1) & 0xFFFF, zeros, invertPrefixSuffix); lineNumber.textColor = TLMUtils.contrastColor(color); int txtLen = lineNumber.text.Length; switch (txtLen) { case 1: lineNumber.textScale = 4; break; case 2: lineNumber.textScale = 3; break; case 3: lineNumber.textScale = 2.25f; break; case 4: lineNumber.textScale = 1.75f; break; case 5: lineNumber.textScale = 1.5f; break; case 6: lineNumber.textScale = 1.35f; break; case 7: lineNumber.textScale = 1.2f; break; case 8: lineNumber.textScale = 1.1f; break; default: lineNumber.textScale = 1f; break; } }