138 lines
4.6 KiB
C#
138 lines
4.6 KiB
C#
using UnityEngine;
|
|
using AibisDream.FixSystem;
|
|
using Cinemachine;
|
|
using AibisDream.Framework;
|
|
using AibisDream.MiniGame.Language;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AibisDream
|
|
{
|
|
/// <summary>
|
|
/// 表达系统顶层管理器(原 ExpressionManager,现改为语言粒子系统)
|
|
/// </summary>
|
|
public class ExpressionManager : MonoBehaviour
|
|
{
|
|
public BubbleSlotGroup bubbleSlotGroup;
|
|
[Header("系统组件")]
|
|
[SerializeField] private LanguageParticleManager particleManager;
|
|
[SerializeField] private GameObject expressionView;
|
|
|
|
[Header("默认配置")]
|
|
[SerializeField] private List<string> defaultAnxietyPhrases = new List<string>
|
|
{
|
|
"我好怕",
|
|
"怎么办",
|
|
"不行",
|
|
"好难",
|
|
"做不到"
|
|
};
|
|
[SerializeField] private string defaultTargetSentence = "这是一个测试示例";
|
|
|
|
void Start()
|
|
{
|
|
// 注册到系统字典
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
|
|
// 查找并初始化表达视图
|
|
if (expressionView == null)
|
|
{
|
|
expressionView = transform.Find("Expression View")?.gameObject;
|
|
}
|
|
|
|
if (expressionView != null)
|
|
{
|
|
expressionView.SetActive(false);
|
|
}
|
|
|
|
// 查找粒子管理器
|
|
if (particleManager == null)
|
|
{
|
|
particleManager = GetComponentInChildren<LanguageParticleManager>(true);
|
|
}
|
|
|
|
// 注册相机
|
|
var virtualCam = transform.Find("Expression Camera")?.GetComponent<ICinemachineCamera>();
|
|
if (virtualCam != null)
|
|
{
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Expression, virtualCam);
|
|
}
|
|
|
|
var virtualCam2 = transform.Find("Expression Deep Camera")?.GetComponent<ICinemachineCamera>();
|
|
if (virtualCam2 != null)
|
|
{
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.ExpressionDeep, virtualCam2);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开表达视图(只显示美术背景,不启动粒子系统)
|
|
/// </summary>
|
|
public void OpenView()
|
|
{
|
|
if (expressionView != null)
|
|
{
|
|
expressionView.SetActive(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动粒子系统(在打开视图后调用,通常通过 Yarn 对话控制)
|
|
/// </summary>
|
|
/// <param name="anxietyPhrases">焦虑短句列表(非目标字符会随机组成这些短句)</param>
|
|
/// <param name="targetSentence">目标句子</param>
|
|
/// <param name="completionNodeName">完成时触发的对话节点名称(可选)</param>
|
|
public void StartSystem(List<string> anxietyPhrases, string targetSentence, string completionNodeName = null)
|
|
{
|
|
if (particleManager != null)
|
|
{
|
|
// 使用传入的配置,如果没有则使用默认配置
|
|
var phrases = anxietyPhrases ?? defaultAnxietyPhrases;
|
|
var sentence = targetSentence ?? defaultTargetSentence;
|
|
|
|
particleManager.InitializeSystem(phrases, sentence, completionNodeName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动粒子系统(字符串数组版本,方便 Yarn 调用)
|
|
/// </summary>
|
|
public void StartSystem(string[] anxietyPhrases, string targetSentence, string completionNodeName = null)
|
|
{
|
|
List<string> phrasesList = anxietyPhrases != null ? new List<string>(anxietyPhrases) : null;
|
|
StartSystem(phrasesList, targetSentence, completionNodeName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭表达系统
|
|
/// </summary>
|
|
public void CloseView()
|
|
{
|
|
if (expressionView != null)
|
|
{
|
|
expressionView.SetActive(false);
|
|
}
|
|
|
|
if (particleManager != null)
|
|
{
|
|
particleManager.StopSystem();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置系统(保持当前配置)
|
|
/// </summary>
|
|
public void ResetSystem(bool playEntranceEffect = true)
|
|
{
|
|
if (particleManager != null)
|
|
{
|
|
particleManager.ResetGame(playEntranceEffect);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CameraKit.Instance?.UnRegisterCamera(CameraEnum.Expression);
|
|
CameraKit.Instance?.UnRegisterCamera(CameraEnum.ExpressionDeep);
|
|
}
|
|
}
|
|
} |