TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

47 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class CSVReader : MonoBehaviour
{
[SerializeField] private TextAsset countryCodesTextAsset;
[Serializable]
public class CountryCode
{
public string Name;
public string Code;
}
public class CountryCodesList
{
public CountryCode[] CountryCodes;
}
[System.NonSerialized] public int size = 0;
public CountryCodesList SW_CountryCodes = new CountryCodesList();
private void Awake()
{
ReadCSV();
}
private void ReadCSV()
{
string[] data = countryCodesTextAsset.text.Split(new string[] { ",", "\n" }, StringSplitOptions.None);
//2 colums, - 1 to remove the top row.
int tableSize = data.Length / 2 - 1;
this.size = tableSize;
SW_CountryCodes.CountryCodes = new CountryCode[tableSize];
for (int i = 0; i < tableSize; i++)
{
SW_CountryCodes.CountryCodes[i] = new CountryCode();
SW_CountryCodes.CountryCodes[i].Name = data[2 * (i + 1)];
SW_CountryCodes.CountryCodes[i].Code = data[2 * (i + 1) + 1];
}
}
}