替换
This commit is contained in:
@@ -5,16 +5,14 @@ using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class ScreenSystem : MonoBehaviour, IScreen, IDialogView
|
||||
{
|
||||
private static readonly int DirectionalAlphaFadeFade = Shader.PropertyToID("_DirectionalAlphaFadeFade");
|
||||
|
||||
#region 效果参数
|
||||
|
||||
public float rotateDuration = 0.5f;
|
||||
public float typeSpeed = 0.05f;
|
||||
public int maxTextLine;
|
||||
|
||||
@@ -22,11 +20,8 @@ namespace AibisDream.FixSystem
|
||||
|
||||
#region 索引
|
||||
|
||||
private Transform _textScreen;
|
||||
[SerializeField] private TMP_Text title;
|
||||
[SerializeField] private TMP_Text text;
|
||||
[SerializeField] private SpriteRenderer screenImage;
|
||||
private Material _imageMaterial;
|
||||
private Action _nextStep;
|
||||
|
||||
private TextGenerator _generator;
|
||||
@@ -44,9 +39,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
_textScreen = transform.Find("旋转屏幕");
|
||||
_imageMaterial = screenImage.material;
|
||||
|
||||
_generator = new TextGenerator();
|
||||
_generationSettings = new TextGenerationSettings
|
||||
{
|
||||
@@ -74,12 +66,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
#region 基础功能
|
||||
|
||||
public void OpenTextScreen()
|
||||
{
|
||||
// 旋转
|
||||
_textScreen.DORotate(new Vector3(0, 0, 0), rotateDuration);
|
||||
}
|
||||
|
||||
public void ShowTitle(string targetTitle)
|
||||
{
|
||||
title.text = targetTitle;
|
||||
@@ -142,78 +128,13 @@ namespace AibisDream.FixSystem
|
||||
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)
|
||||
{
|
||||
_textScreen.DORotate(new Vector3(0, 0, -90), rotateDuration, RotateMode.FastBeyond360);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 状态切换
|
||||
|
||||
/// <summary>
|
||||
/// 插头链接时播放内容
|
||||
/// </summary>
|
||||
/// <param name="sprite">需要播放的图片</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerator OnLink(Sprite sprite)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对话框功能实现
|
||||
@@ -260,25 +181,24 @@ namespace AibisDream.FixSystem
|
||||
/// </summary>
|
||||
public interface IScreen
|
||||
{
|
||||
// 打开副屏
|
||||
void OpenTextScreen();
|
||||
|
||||
// 显示标题文字
|
||||
void ShowTitle(string title);
|
||||
|
||||
// 显示正文
|
||||
IEnumerator ShowText(string text);
|
||||
|
||||
// 显示图片
|
||||
Tween ShowImage(Sprite sprite);
|
||||
|
||||
// 清除图片
|
||||
void ClearImage();
|
||||
|
||||
// 清空屏幕
|
||||
void ClearTextScreen();
|
||||
}
|
||||
|
||||
public static class ScreenYarnCommand
|
||||
{
|
||||
private static ScreenSystem ScreenSystem => FixSystemCenter.SystemDic.Get<ScreenSystem>();
|
||||
|
||||
// 关闭副屏
|
||||
void CloseTextScreen();
|
||||
[YarnCommand("clear_screen")]
|
||||
public static void ClearTextScreen()
|
||||
{
|
||||
ScreenSystem.ClearTextScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user