67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
|
||
using UnityEngine;
|
||
|
||
/// <summary>
|
||
/// Для склонений валюты
|
||
/// </summary>
|
||
public class PluralizeUtil
|
||
{
|
||
/// <summary>
|
||
/// Склонение для рублей
|
||
/// </summary>
|
||
public static string Rubles(int n)
|
||
{
|
||
int lastDigit = n % 10;
|
||
int lastTwoDigits = n % 100;
|
||
|
||
// Исключения для 11–14 (рублей)
|
||
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
|
||
return "рублей";
|
||
|
||
return lastDigit switch
|
||
{
|
||
1 => "рубль",
|
||
2 or 3 or 4 => "рубля",
|
||
_ => "рублей"
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// Склонение для жетонов
|
||
/// </summary>
|
||
public static string Tokens(int n)
|
||
{
|
||
int lastDigit = n % 10;
|
||
int lastTwoDigits = n % 100;
|
||
|
||
// Исключения для 11–14 (жетонов)
|
||
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
|
||
return "жетонов";
|
||
|
||
return lastDigit switch
|
||
{
|
||
1 => "жетон",
|
||
2 or 3 or 4 => "жетона",
|
||
_ => "жетонов"
|
||
};
|
||
}
|
||
|
||
public static int PlaytimeToMinutes(string playtime)
|
||
{
|
||
if (playtime == "Тест 0 мин") return 1;
|
||
if (playtime == "Неограниченно") return 0;
|
||
|
||
try
|
||
{
|
||
string textNumber = playtime.Split(' ')[0];
|
||
int minutes = int.Parse(textNumber);
|
||
return minutes;
|
||
}
|
||
catch
|
||
{
|
||
Debug.Log($"Ошибка парсинга значения {playtime}");
|
||
return 0;
|
||
}
|
||
}
|
||
}
|