149 lines
4.8 KiB
C#
149 lines
4.8 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;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class ExpressionManager : MonoBehaviour
|
|
{
|
|
public GameObject expressView;
|
|
public TMP_Text totalPointsText;
|
|
public int totalPoints = 10;
|
|
|
|
public TMP_Text driverSlotText;
|
|
public TMP_Text logOutput;
|
|
public Button matchButton;
|
|
public Button applyAndTestButton;
|
|
|
|
public GameObject matchResultsPanel;
|
|
public GameObject driverButtonPrefab;
|
|
public string currentUser = "UserA";
|
|
private int[] valuesCurrent = new int[5];
|
|
private DriverProfile currentDriver = null;
|
|
private DriverDatabase db = new DriverDatabase();
|
|
private List<GameObject> currentResultButtons = new List<GameObject>();
|
|
|
|
void Start()
|
|
{
|
|
//CloseView();
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
|
|
var virtualCam = transform.Find("Expression Camera").GetComponent<ICinemachineCamera>();
|
|
var virtualCam2 = transform.Find("Expression Deep Camera").GetComponent<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Expression, virtualCam);
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.ExpressionDeep, virtualCam2);
|
|
|
|
db.LoadFromCSV(Path.Combine(Application.streamingAssetsPath, "drivers.csv"));
|
|
|
|
matchButton.onClick.AddListener(MatchDriver);
|
|
applyAndTestButton.onClick.AddListener(ApplyAndTestDriver);
|
|
|
|
UpdateUI();
|
|
}
|
|
|
|
public void OpenView()
|
|
{
|
|
expressView.SetActive(true);
|
|
}
|
|
|
|
public void CloseView()
|
|
{
|
|
expressView.SetActive(false);
|
|
}
|
|
|
|
public 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()
|
|
{
|
|
totalPointsText.text = $"剩余点数: {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 = $"已选中驱动:{driver.Name},请点击应用并测试以运行。";
|
|
}
|
|
|
|
void ApplyAndTestDriver()
|
|
{
|
|
if (currentDriver == null)
|
|
{
|
|
logOutput.text = "未选择任何驱动。";
|
|
return;
|
|
}
|
|
|
|
string nodeName = $"{currentUser}_{currentDriver.Name}";
|
|
DialogController.Instance.StartDialogNode(nodeName);
|
|
}
|
|
|
|
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 = "当前驱动与属性不匹配,已卸载。";
|
|
}
|
|
}
|
|
|
|
[YarnCommand("setUser")]
|
|
public void SetCurrentUser(string userName)
|
|
{
|
|
currentUser=userName;
|
|
}
|
|
}
|
|
} |