69 lines
1.4 KiB
C#
69 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Data
|
|
{
|
|
public enum CountryAndRegionDataType{
|
|
Desc_1001 = 1001,
|
|
CAR_1001 = 1001,
|
|
Desc_1002 = 1002,
|
|
CAR_1002 = 1002,
|
|
Desc_1003 = 1003,
|
|
CAR_1003 = 1003,
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class CountryAndRegionData
|
|
{
|
|
/// <summary>
|
|
/// ID
|
|
/// </summary>
|
|
public int ID;
|
|
/// <summary>
|
|
/// 描述
|
|
/// </summary>
|
|
public string Desc;
|
|
/// <summary>
|
|
/// 国家和地区
|
|
/// </summary>
|
|
public string CAR;
|
|
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class CountryAndRegionDatas
|
|
{
|
|
public List<CountryAndRegionData> CountryAndRegionList = new List<CountryAndRegionData>();
|
|
}
|
|
|
|
public class CountryAndRegionDataExcel
|
|
{
|
|
private const string _fileName = "CountryAndRegion";
|
|
private string _filePath;
|
|
private CountryAndRegionDatas _datas;
|
|
public CountryAndRegionDatas Datas => _datas;
|
|
|
|
public CountryAndRegionDataExcel()
|
|
{
|
|
_filePath = $"{Application.dataPath}/Res/ExcelData/{_fileName}.json";
|
|
var text = File.ReadAllText(_filePath);
|
|
_datas = JsonConvert.DeserializeObject<CountryAndRegionDatas>(text);
|
|
}
|
|
|
|
public CountryAndRegionData GetData(int id)
|
|
{
|
|
foreach (var testData in _datas.CountryAndRegionList)
|
|
{
|
|
if (id == testData.ID)
|
|
{
|
|
return testData;
|
|
}
|
|
}
|
|
|
|
throw new NullReferenceException();
|
|
}
|
|
}} |