screen
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using Febucci.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class ScreenSystem : MonoBehaviour, IScreen, IDialogView
|
||||
{
|
||||
private static readonly int DirectionalAlphaFadeFade = Shader.PropertyToID("_DirectionalAlphaFadeFade");
|
||||
|
||||
#region 效果参数
|
||||
|
||||
public float rotateDuration = 0.5f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 索引
|
||||
|
||||
private Transform _textScreen;
|
||||
[SerializeField] private TMP_Text title;
|
||||
[SerializeField] private TMP_Text text;
|
||||
[SerializeField] private TypewriterByCharacter textTypewriter;
|
||||
[SerializeField] private SpriteRenderer screenImage;
|
||||
private Material _imageMaterial;
|
||||
|
||||
private IUnRegister _plugOutRmv;
|
||||
private Action _nextStep;
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitComponentRefs();
|
||||
Register();
|
||||
}
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
_textScreen = transform.Find("旋转屏幕");
|
||||
_imageMaterial = screenImage.material;
|
||||
}
|
||||
|
||||
private void Register()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Screen, this);
|
||||
|
||||
textTypewriter.onTextShowed.AddListener(() => StartCoroutine(AutoNextStep()));
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Unregister<ScreenSystem>();
|
||||
DialogCanvasManager.Instance.UnregisterDialogView(DialogViewType.Screen);
|
||||
}
|
||||
|
||||
#region 基础功能
|
||||
|
||||
public void OpenTextScreen()
|
||||
{
|
||||
// 旋转
|
||||
_textScreen.DORotate(new Vector3(0, 0, 0), rotateDuration);
|
||||
}
|
||||
|
||||
public void ShowTitle(string targetTitle)
|
||||
{
|
||||
title.text = targetTitle;
|
||||
}
|
||||
|
||||
public void ShowText(string targetText)
|
||||
{
|
||||
// 获取旧文字
|
||||
var oldText = text.text;
|
||||
// if (!string.IsNullOrWhiteSpace(oldText))
|
||||
// {
|
||||
// // 去掉notype标签,并且加上新的
|
||||
// var rawOldText = oldText.Replace("<notype>", "").Replace("</notype>", "");
|
||||
// oldText = "<notype> " + rawOldText + " </notype>";
|
||||
// }
|
||||
|
||||
// 显示文字
|
||||
textTypewriter.ShowText(oldText + targetText);
|
||||
}
|
||||
|
||||
public Tween ShowImage(Sprite sprite)
|
||||
{
|
||||
// 先回归隐藏状态
|
||||
_imageMaterial.SetFloat(DirectionalAlphaFadeFade, 0);
|
||||
// 切换图片
|
||||
screenImage.sprite = sprite;
|
||||
// 逐渐展示
|
||||
return DOTween.To(() => _imageMaterial.GetFloat(DirectionalAlphaFadeFade),
|
||||
value => _imageMaterial.SetFloat(DirectionalAlphaFadeFade, value), 10f, 1f);
|
||||
}
|
||||
|
||||
public void ClearImage()
|
||||
{
|
||||
_imageMaterial.SetFloat(DirectionalAlphaFadeFade, 0);
|
||||
screenImage.sprite = null;
|
||||
}
|
||||
|
||||
public void ClearTextScreen()
|
||||
{
|
||||
title.text = "";
|
||||
text.SetText("");
|
||||
}
|
||||
|
||||
public void CloseTextScreen()
|
||||
{
|
||||
// 先清除文字
|
||||
ClearTextScreen();
|
||||
// 旋转隐藏
|
||||
_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 对话框功能实现
|
||||
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed = null,
|
||||
bool isAutoSkip = false)
|
||||
{
|
||||
ShowTitle(character.GetActorName());
|
||||
ShowText(dialogLine);
|
||||
|
||||
// 每行自动跳过
|
||||
_nextStep = nextStep;
|
||||
}
|
||||
|
||||
public void ShowOptions(DialogOption[] dialogueOptions)
|
||||
{
|
||||
Debug.Log("不能在显示屏显示对话");
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
// HideDialog应该由其他函数控制
|
||||
}
|
||||
|
||||
public bool TrySkipLine()
|
||||
{
|
||||
// 这里不能跳过对话
|
||||
return true;
|
||||
}
|
||||
|
||||
public void NextStep()
|
||||
{
|
||||
// 这里不能手动跳到下一行
|
||||
}
|
||||
|
||||
private IEnumerator AutoNextStep()
|
||||
{
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
_nextStep?.Invoke();
|
||||
_nextStep = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 屏幕接口
|
||||
/// </summary>
|
||||
public interface IScreen
|
||||
{
|
||||
// 打开副屏
|
||||
void OpenTextScreen();
|
||||
|
||||
// 显示标题文字
|
||||
void ShowTitle(string title);
|
||||
|
||||
// 显示正文
|
||||
void ShowText(string text);
|
||||
|
||||
// 显示图片
|
||||
Tween ShowImage(Sprite sprite);
|
||||
|
||||
// 清除图片
|
||||
void ClearImage();
|
||||
|
||||
// 清空屏幕
|
||||
void ClearTextScreen();
|
||||
|
||||
// 关闭副屏
|
||||
void CloseTextScreen();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user