63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using System.IO;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class DriverDatabase
|
|
{
|
|
public List<DriverProfile> Drivers = new List<DriverProfile>();
|
|
|
|
public void LoadFromCSV(string path)
|
|
{
|
|
// 使用 FileShare.ReadWrite 防止文件被其他进程占用
|
|
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) // 全限定名避免编码引用问题
|
|
{
|
|
string header = reader.ReadLine();
|
|
while (!reader.EndOfStream)
|
|
{
|
|
string line = reader.ReadLine().Trim();
|
|
if (string.IsNullOrEmpty(line)) continue;
|
|
|
|
// 支持逗号或分号分隔
|
|
char delimiter = line.Contains(';') ? ';' : ',';
|
|
string[] fields = line.Split(delimiter);
|
|
|
|
// 期望 12 列
|
|
if (fields.Length < 12)
|
|
{
|
|
Debug.LogWarning($"Skipping invalid CSV line (columns={fields.Length}): {line}");
|
|
continue;
|
|
}
|
|
|
|
DriverProfile d = new DriverProfile();
|
|
int idx = 0;
|
|
d.Name = fields[idx++];
|
|
int.TryParse(fields[idx++], out d.MinA);
|
|
int.TryParse(fields[idx++], out d.MaxA);
|
|
int.TryParse(fields[idx++], out d.MinP);
|
|
int.TryParse(fields[idx++], out d.MaxP);
|
|
int.TryParse(fields[idx++], out d.MinR);
|
|
int.TryParse(fields[idx++], out d.MaxR);
|
|
int.TryParse(fields[idx++], out d.MinE);
|
|
int.TryParse(fields[idx++], out d.MaxE);
|
|
int.TryParse(fields[idx++], out d.MinT);
|
|
int.TryParse(fields[idx++], out d.MaxT);
|
|
d.YarnFile = fields[idx++];
|
|
|
|
Drivers.Add(d);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<DriverProfile> MatchDrivers(int A, int P, int R, int E, int T)
|
|
{
|
|
return Drivers.FindAll(d => d.Matches(A, P, R, E, T));
|
|
}
|
|
}
|
|
}
|