142 lines
4.9 KiB
C#
142 lines
4.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using System.IO;
|
|
using AibisDream.FixSystem;
|
|
using Cinemachine;
|
|
using AibisDream.Framework;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class ExpressionManager : MonoBehaviour
|
|
{
|
|
public GameObject expressView;
|
|
public Slider[] sliders; // A, P, R, E, T
|
|
public TMP_Text totalPointsText;
|
|
public int totalPoints = 10;
|
|
|
|
public TMP_Text driverSlotText;
|
|
public TMP_Text logOutput;
|
|
public Button matchButton;
|
|
|
|
public GameObject matchResultsPanel;
|
|
public GameObject driverButtonPrefab;
|
|
|
|
private int[] valuesCurrent = new int[5];
|
|
private DriverProfile currentDriver = null;
|
|
private DriverDatabase db = new DriverDatabase();
|
|
private List<GameObject> currentResultButtons = new List<GameObject>();
|
|
|
|
void Start()
|
|
{
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
var virtualCam = transform.Find("Expression Camera").GetComponent<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Expression, virtualCam);
|
|
|
|
db.LoadFromCSV(Path.Combine(Application.streamingAssetsPath, "drivers.csv"));
|
|
|
|
for (int i = 0; i < sliders.Length; i++)
|
|
{
|
|
int index = i;
|
|
Transform plus = sliders[i].transform.Find("Plus");
|
|
if (plus != null && plus.TryGetComponent(out Button plusBtn))
|
|
plusBtn.onClick.AddListener(() => AdjustValue(index, 1));
|
|
Transform minus = sliders[i].transform.Find("Minus");
|
|
if (minus != null && minus.TryGetComponent(out Button minusBtn))
|
|
minusBtn.onClick.AddListener(() => AdjustValue(index, -1));
|
|
}
|
|
|
|
matchButton.onClick.AddListener(MatchDriver);
|
|
UpdateUI();
|
|
}
|
|
public void OpenView()
|
|
{
|
|
expressView.SetActive(true);
|
|
}
|
|
public void CloseView()
|
|
{
|
|
expressView.SetActive(false);
|
|
}
|
|
|
|
void AdjustValue(int index, int delta)
|
|
{
|
|
if (delta > 0 && totalPoints <= 0) return;
|
|
if (delta < 0 && valuesCurrent[index] <= 0) return;
|
|
if (valuesCurrent[index] + delta > 5) return;
|
|
|
|
valuesCurrent[index] += delta;
|
|
totalPoints -= delta;
|
|
CheckDriverStillValid();
|
|
UpdateUI();
|
|
}
|
|
|
|
void UpdateUI()
|
|
{
|
|
for (int i = 0; i < sliders.Length; i++)
|
|
{
|
|
sliders[i].value = valuesCurrent[i];
|
|
Transform valueTextTransform = sliders[i].transform.Find("Value");
|
|
if (valueTextTransform != null && valueTextTransform.TryGetComponent(out TMP_Text valueText))
|
|
valueText.text = valuesCurrent[i].ToString();
|
|
}
|
|
totalPointsText.text = $"Points Left: {totalPoints}";
|
|
}
|
|
|
|
void MatchDriver()
|
|
{
|
|
currentResultButtons.ForEach(btn => Destroy(btn));
|
|
currentResultButtons.Clear();
|
|
|
|
var matches = db.MatchDrivers(
|
|
valuesCurrent[0], valuesCurrent[1],
|
|
valuesCurrent[2], valuesCurrent[3],
|
|
valuesCurrent[4]);
|
|
|
|
if (matches.Count > 0)
|
|
{
|
|
matchResultsPanel.SetActive(true);
|
|
foreach (var driver in matches)
|
|
{
|
|
var btnObj = Instantiate(driverButtonPrefab, matchResultsPanel.transform);
|
|
var text = btnObj.GetComponentInChildren<TMP_Text>();
|
|
if (text) text.text = driver.Name;
|
|
var btn = btnObj.GetComponent<Button>();
|
|
if (btn) btn.onClick.AddListener(() => SelectDriver(driver));
|
|
currentResultButtons.Add(btnObj);
|
|
}
|
|
logOutput.text = $"共找到 {matches.Count} 个可用驱动,请选择。";
|
|
}
|
|
else
|
|
{
|
|
matchResultsPanel.SetActive(false);
|
|
currentDriver = null;
|
|
driverSlotText.text = "No Driver";
|
|
logOutput.text = "没有找到匹配的驱动。";
|
|
}
|
|
}
|
|
|
|
void SelectDriver(DriverProfile driver)
|
|
{
|
|
currentDriver = driver;
|
|
driverSlotText.text = $"Driver: {driver.Name}";
|
|
logOutput.text = $"[YARN] Loading: {driver.YarnFile}";
|
|
matchResultsPanel.SetActive(false);
|
|
}
|
|
|
|
void CheckDriverStillValid()
|
|
{
|
|
if (currentDriver != null && !currentDriver.Matches(
|
|
valuesCurrent[0], valuesCurrent[1],
|
|
valuesCurrent[2], valuesCurrent[3],
|
|
valuesCurrent[4]))
|
|
{
|
|
currentDriver = null;
|
|
driverSlotText.text = "No Driver";
|
|
logOutput.text = "当前驱动与属性不匹配,已卸载。";
|
|
}
|
|
}
|
|
}
|
|
}
|