Ver.0.3.0.33

This commit is contained in:
2025-07-08 08:32:46 +00:00
parent 99f4dd67c2
commit 0ad5e29917
6831 changed files with 695623 additions and 234455 deletions
@@ -1,34 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
using DG.Tweening;
using Febucci.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream.FixSystem
{
public class ScreenSystem : MonoBehaviour, IScreen, IDialogView
public class ScreenSystem : MonoBehaviour, IDialogView
{
private static readonly int DirectionalAlphaFadeFade = Shader.PropertyToID("_DirectionalAlphaFadeFade");
#region
public float rotateDuration = 0.5f;
public float typeSpeed = 0.05f;
#endregion
#region
private Transform _textScreen;
[SerializeField] private TMP_Text title;
[SerializeField] private TMP_Text text;
[SerializeField] private SpriteRenderer screenImage;
private Material _imageMaterial;
[SerializeField] private RectTransform textRoot;
[SerializeField] private TMP_Text textForEstimation;
private GameObject _textItemPrefab;
private Queue<TypewriterByCharacter> _lineQueue;
private IUnRegister _plugOutRmv;
private Action _nextStep;
public BubbleSlotGroup BubbleSlotGroup { get; private set; }
public TaskScreen TaskScreen { get; private set; }
public int maxLineNum = 10;
#endregion
@@ -40,142 +38,87 @@ namespace AibisDream.FixSystem
private void InitComponentRefs()
{
_textScreen = transform.Find("旋转屏幕");
_imageMaterial = screenImage.material;
TaskScreen = GetComponentInChildren<TaskScreen>();
_lineQueue = new Queue<TypewriterByCharacter>();
_textItemPrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.ScreenTextName);
BubbleSlotGroup = GetComponentInChildren<BubbleSlotGroup>();
}
private void Register()
{
FixSystemCenter.SystemDic.Register(this);
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Screen, this);
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Task, TaskScreen);
}
private void OnDestroy()
{
FixSystemCenter.SystemDic.Unregister<ScreenSystem>();
DialogCanvasManager.Instance.UnregisterDialogView(DialogViewType.Screen);
DialogCanvasManager.Instance.UnregisterDialogView(DialogViewType.Task);
}
#region
public void OpenTextScreen()
{
// 旋转
_textScreen.DORotate(new Vector3(0, 0, 0), rotateDuration);
}
public void ShowTitle(string targetTitle)
private void ShowTitle(string targetTitle)
{
title.text = targetTitle;
}
public IEnumerator ShowText(string targetText)
{
// 先换行
if (!string.IsNullOrEmpty(text.text))
{
text.text += "\n";
}
var oldText = text.text;
var targetLength = text.text.Length + targetText.Length;
// 逐个字符添加
yield return DOTween.To(() => text.text.Length, x => UpdateText(x, targetText, oldText), targetLength,
targetText.Length * typeSpeed).WaitForCompletion();
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
yield return new WaitForSeconds(0.5f);
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
_nextStep.Invoke();
}
private void UpdateText(int currentLength, string nextText, string oldText)
{
var appendLength = currentLength - oldText.Length;
text.text = oldText + nextText[..appendLength];
}
public Tween ShowImage(Sprite sprite)
{
// 先回归隐藏状态
_imageMaterial.SetFloat(DirectionalAlphaFadeFade, 0);
// 切换图片
screenImage.sprite = sprite;
// 逐渐展示
return DOTween.To(() => _imageMaterial.GetFloat(DirectionalAlphaFadeFade),
value => _imageMaterial.SetFloat(DirectionalAlphaFadeFade, value), 10f, 0.5f);
}
public void ClearImage()
{
_imageMaterial.SetFloat(DirectionalAlphaFadeFade, 0);
screenImage.sprite = null;
}
public void ClearTextScreen()
{
title.text = "";
text.SetText("");
}
public void CloseTextScreen()
{
// 先清除文字
ClearTextScreen();
// 旋转隐藏
if (transform.eulerAngles.z >= -80f)
while (_lineQueue.Count > 0)
{
_textScreen.DORotate(new Vector3(0, 0, -90), rotateDuration, RotateMode.FastBeyond360);
var text = _lineQueue.Dequeue();
Destroy(text.gameObject);
}
ShowTitle(string.Empty);
}
#endregion
#region
/// <summary>
/// 插头链接时播放内容
/// </summary>
/// <param name="sprite">需要播放的图片</param>
/// <returns></returns>
public IEnumerator OnLink(Sprite sprite)
public void ShowTaskPanel()
{
EnumEventSystem.Global.Send(EventEnum.OpenScreen);
// 右侧加载图片
var tween = ShowImage(sprite);
yield return tween.WaitForCompletion();
// 左侧打开副屏
OpenTextScreen();
yield return new WaitForSeconds(rotateDuration + 0.2f);
}
/// <summary>
/// 收回屏幕时触发
/// </summary>
/// <returns></returns>
public IEnumerator OnUnlink()
{
// 隐藏图片
ClearImage();
yield return new WaitForSeconds(0.3f);
// 左侧回收屏幕
CloseTextScreen();
yield return new WaitForSeconds(rotateDuration + 0.2f);
EnumEventSystem.Global.Send(EventEnum.CloseScreen);
TaskScreen.transform.DOLocalMoveY(3.85f, 1f);
}
#endregion
#region
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, bool isAutoSkip = false)
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
{
if (string.IsNullOrWhiteSpace(dialogLine))
{
dialogLine = " ";
}
ShowTitle(character.GetActorName());
StartCoroutine(ShowText(dialogLine));
// 每行自动跳过
_nextStep = nextStep;
// 生成新文本组件
var textItem = Instantiate(_textItemPrefab, textRoot);
var textItemTypewriter = textItem.GetComponent<TypewriterByCharacter>();
// 估算文本高度
var newLineNum = EstimateLineNum(dialogLine);
var oldLineNum = CalcTotalLineNum();
if (newLineNum + oldLineNum > maxLineNum)
{
Destroy(_lineQueue.Dequeue().gameObject);
}
_lineQueue.Enqueue(textItemTypewriter);
// 播放文本
textItemTypewriter.ShowText(dialogLine);
textItemTypewriter.onTextShowed.AddListener(() => AfterLineShown(textItemTypewriter, nextStep));
// 强制更新布局
LayoutRebuilder.ForceRebuildLayoutImmediate(textRoot);
}
private void AfterLineShown(TypewriterByCharacter typewriter, Action nextStop)
{
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
ActionKit.Delay(0.3f, () =>
{
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
nextStop.Invoke();
}).StartGlobal();
typewriter.onTextShowed.RemoveAllListeners();
}
public void ShowOptions(DialogOption[] dialogueOptions)
@@ -198,34 +141,24 @@ namespace AibisDream.FixSystem
{
// 这里不能手动跳到下一行
}
public void OnLocalizationChanged(string value)
{
// 屏幕不需要本地化
}
#endregion
}
private int EstimateLineNum(string text)
{
textForEstimation.text = text;
textForEstimation.ForceMeshUpdate();
return textForEstimation.textInfo.lineCount;
}
/// <summary>
/// 屏幕接口
/// </summary>
public interface IScreen
{
// 打开副屏
void OpenTextScreen();
// 显示标题文字
void ShowTitle(string title);
// 显示正文
IEnumerator ShowText(string text);
// 显示图片
Tween ShowImage(Sprite sprite);
// 清除图片
void ClearImage();
// 清空屏幕
void ClearTextScreen();
// 关闭副屏
void CloseTextScreen();
private int CalcTotalLineNum()
{
return _lineQueue.Select(x => x.GetComponent<TMP_Text>().textInfo.lineCount).Sum();
}
}
}