1111
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Stary.Evo;
|
||||
using Stary.Evo.AudioCore;
|
||||
using Stary.Evo.RKTools;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace Main
|
||||
{
|
||||
@@ -14,17 +17,19 @@ namespace Main
|
||||
void AddClickIntervalEvent(Action callback);
|
||||
void StartTime();
|
||||
void EndClick();
|
||||
|
||||
void BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback);
|
||||
void ResumeTouchClick(Transform tweenTarget);
|
||||
Task BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback,
|
||||
bool isOneByOne = false);
|
||||
void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget);
|
||||
|
||||
void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget, bool isOneByOne);
|
||||
int ElementChildrenClickCount();
|
||||
bool IsElementChildrenClick();
|
||||
}
|
||||
|
||||
public class ClickSystem : AbstractSystem, IClickSystem
|
||||
{
|
||||
// public Sequence loopTargetTween;
|
||||
|
||||
private AudioClip _clickSound;
|
||||
/// <summary>
|
||||
/// 点击计时器
|
||||
/// </summary>
|
||||
@@ -48,19 +53,35 @@ namespace Main
|
||||
Update();
|
||||
}
|
||||
|
||||
public void BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback)
|
||||
public async Task BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback,
|
||||
bool isOneByOne = false)
|
||||
{
|
||||
StartTime();
|
||||
this.clickElementChildrens = clickElementChildrens;
|
||||
//绑定点击事件
|
||||
foreach (var child in clickElementChildrens)
|
||||
for (int i = 0; i < clickElementChildrens.Count; i++)
|
||||
{
|
||||
child.transform.gameObject.ObjectAddTouchEvent(callback);
|
||||
clickElementChildrens[i].transform.gameObject.ObjectAddTouchEvent(callback);
|
||||
if (isOneByOne && i > 0)
|
||||
{
|
||||
clickElementChildrens[i].transform.gameObject.ObjectPauseTouchEvent();
|
||||
}
|
||||
}
|
||||
|
||||
//播放音效
|
||||
var package = YooAssets.GetPackage("Main");
|
||||
var sfxhandle = package.LoadAssetAsync<AudioClip>("Audios_au_effect_click");
|
||||
await sfxhandle.Task;
|
||||
_clickSound = sfxhandle.GetAssetObject<AudioClip>();
|
||||
}
|
||||
|
||||
public void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget)
|
||||
{
|
||||
Debug.Log("UnityEvo: 点击呼吸");
|
||||
AudioCoreManager.PlaySFX(new AudioData()
|
||||
{
|
||||
clip = _clickSound
|
||||
});
|
||||
time = 0;
|
||||
foreach (var tween in tweenList)
|
||||
{
|
||||
@@ -73,53 +94,111 @@ namespace Main
|
||||
if (tween.transform == tweenTarget)
|
||||
{
|
||||
tween.isClick = true;
|
||||
tween.transform.GetComponent<Animator>().CrossFade("dianji_idle", 0.2f);
|
||||
this.SendEvent<ModeType, ClickElementChildren>(ModeType.PLayAudioOrVideo,tween);
|
||||
tween.transform.GetComponent<Animator>().CrossFade("dianji_idle", 0.01f);
|
||||
this.SendEvent<ModeType, ClickElementChildren>(ModeType.PLayAudioOrVideo, tween);
|
||||
tweenTarget.gameObject.ObjectPauseTouchEvent();
|
||||
// if (loopTargetTween != null)
|
||||
// {
|
||||
// loopTargetTween.Kill();
|
||||
// loopTargetTween = null;
|
||||
// }
|
||||
//
|
||||
// loopTargetTween = DOTween.Sequence();
|
||||
// loopTargetTween.Append(tweenTarget.DOScale(tweenTarget.lossyScale * 1.3f, 1f));
|
||||
//
|
||||
// loopTargetTween.SetLoops(6, LoopType.Yoyo);
|
||||
// loopTargetTween.OnKill(() =>
|
||||
// {
|
||||
// if (tweenTarget != null)
|
||||
// tweenTarget.DOScale(Vector3.one, 0.3f);
|
||||
// });
|
||||
// loopTargetTween.Play();
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// tween.transform.DOKill();
|
||||
// tween.transform.DOScale(Vector3.one * 0.9f, 0.5f);
|
||||
tween.transform.GetComponent<Animator>().CrossFade("dianji_nood", 1f);
|
||||
tween.transform.GetComponent<Animator>().CrossFade("dianji_nood", 0.01f);
|
||||
}
|
||||
}
|
||||
public void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget,bool isOneByOne)
|
||||
{
|
||||
Debug.Log("UnityEvo: 点击呼吸");
|
||||
AudioCoreManager.PlaySFX(new AudioData()
|
||||
{
|
||||
clip = _clickSound
|
||||
});
|
||||
time = 0;
|
||||
for (int i = 0; i < tweenList.Count; i++)
|
||||
{
|
||||
var tween = tweenList[i];
|
||||
// if (tween.transform == tweenTarget)
|
||||
// {
|
||||
// tween.isClick = true;
|
||||
// }
|
||||
if (tween.transform == tweenTarget)
|
||||
{
|
||||
tween.isClick = true;
|
||||
tween.transform.gameObject.ObjectPauseTouchEvent();
|
||||
tween.transform.GetComponent<Animator>().CrossFade("dianji_disappear", 0.01f);
|
||||
|
||||
this.SendEvent<ModeType, ClickElementChildren>(ModeType.PLayAudioOrVideo, tween);
|
||||
|
||||
if (isOneByOne&& i+1 < tweenList.Count)
|
||||
{
|
||||
tweenList[i+1].transform.gameObject.ObjectResumeTouchEvent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void AddClickIntervalEvent(Action callback)
|
||||
{
|
||||
this.ClickIntervalEvent = callback;
|
||||
}
|
||||
|
||||
public int ElementChildrenClickCount()
|
||||
{
|
||||
int count = 0;
|
||||
//是否全部已经点击
|
||||
for (int i = 0; i < clickElementChildrens.Count; i++)
|
||||
{
|
||||
if (clickElementChildrens[i].isClick == true)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
public bool IsElementChildrenClick()
|
||||
{
|
||||
|
||||
//是否全部已经点击
|
||||
for (int i = 0; i < clickElementChildrens.Count; i++)
|
||||
{
|
||||
if (clickElementChildrens[i].isClick == false)
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public void ResumeTouchClick( Transform tweenTarget)
|
||||
{
|
||||
// if (loopTargetTween != null)
|
||||
// {
|
||||
// loopTargetTween.Kill();
|
||||
// loopTargetTween = null;
|
||||
// }
|
||||
|
||||
time = 0;
|
||||
if (tokenSource != null)
|
||||
{
|
||||
tokenSource?.Cancel();
|
||||
tokenSource?.Dispose();
|
||||
tokenSource = null;
|
||||
}
|
||||
|
||||
foreach (var children in clickElementChildrens)
|
||||
{
|
||||
if (children.transform != tweenTarget )
|
||||
{
|
||||
var animator = children.transform.GetComponent<Animator>();
|
||||
// 获取当前动画状态
|
||||
var currentState = animator.GetCurrentAnimatorStateInfo(0);
|
||||
if (currentState.IsName("dianji_disappear"))
|
||||
{
|
||||
children.transform.gameObject.ObjectResumeTouchEvent();
|
||||
animator.CrossFade("dianji_appear", 0.01f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void EndClick()
|
||||
{
|
||||
// if (loopTargetTween != null)
|
||||
@@ -139,40 +218,39 @@ namespace Main
|
||||
foreach (var children in clickElementChildrens)
|
||||
{
|
||||
children.transform.gameObject.ObjectRemoveTouchEvent();
|
||||
children.transform.GetComponent<Animator>().CrossFade("dianji_disappear", 0.2f);
|
||||
|
||||
children.transform.GetComponent<Animator>().CrossFade("dianji_disappear", 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Update()
|
||||
{
|
||||
//TODO暂时禁用
|
||||
// if (tokenSource != null)
|
||||
// {
|
||||
// tokenSource?.Cancel();
|
||||
// }
|
||||
//
|
||||
// tokenSource = new CancellationTokenSource();
|
||||
// try
|
||||
// {
|
||||
// while (time <= 11 && !tokenSource.IsCancellationRequested)
|
||||
// {
|
||||
// time += Time.deltaTime;
|
||||
//
|
||||
// if (time >= 10)
|
||||
// {
|
||||
// Debug.Log("UnityEvo:执行未点击间隔事件");
|
||||
// time = 0;
|
||||
// ClickIntervalEvent?.Invoke();
|
||||
// }
|
||||
//
|
||||
// await UniTask.Yield(tokenSource.Token);
|
||||
// }
|
||||
// }
|
||||
// catch (OperationCanceledException e)
|
||||
// {
|
||||
// Debug.Log("UnityEvo: 取消任务:" + e);
|
||||
// }
|
||||
if (tokenSource != null)
|
||||
{
|
||||
tokenSource?.Cancel();
|
||||
}
|
||||
|
||||
tokenSource = new CancellationTokenSource();
|
||||
try
|
||||
{
|
||||
while (time <= 15 && !tokenSource.IsCancellationRequested)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
|
||||
if (time >= 15)
|
||||
{
|
||||
Debug.Log("UnityEvo:执行未点击间隔事件");
|
||||
time = 0;
|
||||
ClickIntervalEvent?.Invoke();
|
||||
}
|
||||
|
||||
await UniTask.Yield(tokenSource.Token);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
Debug.Log("UnityEvo: 取消任务:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -190,9 +268,8 @@ namespace Main
|
||||
// loopTargetTween = null;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class ClickElementChildren
|
||||
{
|
||||
public bool isClick = false;
|
||||
@@ -201,24 +278,25 @@ namespace Main
|
||||
public Transform transform;
|
||||
|
||||
public Transform targetTransform;
|
||||
|
||||
|
||||
public ClickElementChildren(Transform child)
|
||||
{
|
||||
|
||||
this. transform = child;
|
||||
this.transform = child;
|
||||
}
|
||||
|
||||
public ClickElementChildren(Transform child, string[] auid, string vid)
|
||||
{
|
||||
this.auid = auid;
|
||||
this.vid = vid;
|
||||
this. transform = child;
|
||||
this.transform = child;
|
||||
}
|
||||
public ClickElementChildren(Transform child,Transform targetTransform , string[] auid, string vid)
|
||||
|
||||
public ClickElementChildren(Transform child, Transform targetTransform, string[] auid, string vid)
|
||||
{
|
||||
this.auid = auid;
|
||||
this.vid = vid;
|
||||
this. transform = child;
|
||||
this.targetTransform= targetTransform;
|
||||
this.transform = child;
|
||||
this.targetTransform = targetTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,10 @@ namespace Main
|
||||
{
|
||||
base.OnEnter();
|
||||
|
||||
this.RegisterEvent<IntroType, string, string>(IntroType.IntroSprite, OnClickPreviousIntro);
|
||||
this.RegisterEvent<IntroType, string, string>(IntroType.IntroSpriteName, OnClickPreviousIntro);
|
||||
this.RegisterEvent<IntroType, RuntimeAnimatorController, string>(IntroType.IntroAnimation, OnAddAnimation);
|
||||
this.RegisterEvent<IntroType, string, string>(IntroType.IntroAudio, OnClickPreviousIntroAudio);
|
||||
this.RegisterEvent<IntroType, Sprite, string>(IntroType.IntroSprite, SetIntroSprite);
|
||||
}
|
||||
|
||||
public override void OnExit(float delay = 0)
|
||||
@@ -46,9 +47,10 @@ namespace Main
|
||||
base.OnExit(delay);
|
||||
intro.sprite = null;
|
||||
intro.gameObject.SetActive(false);
|
||||
this.UnRegisterEvent<IntroType, string, string>(IntroType.IntroSprite, OnClickPreviousIntro);
|
||||
this.UnRegisterEvent<IntroType, string, string>(IntroType.IntroSpriteName, OnClickPreviousIntro);
|
||||
this.UnRegisterEvent<IntroType, string, string>(IntroType.IntroAudio, OnClickPreviousIntroAudio);
|
||||
this.UnRegisterEvent<IntroType, RuntimeAnimatorController, string>(IntroType.IntroAnimation, OnAddAnimation);
|
||||
this.UnRegisterEvent<IntroType, Sprite, string>(IntroType.IntroSprite, SetIntroSprite);
|
||||
var animator = intro.transform.GetComponent<Animator>();
|
||||
if (animator != null)
|
||||
{
|
||||
@@ -70,10 +72,7 @@ namespace Main
|
||||
{
|
||||
var handle= YooAssets.LoadAssetAsync<Sprite>(spriteName);
|
||||
await handle.Task;
|
||||
intro.sprite = handle.GetAssetObject<Sprite>();
|
||||
intro.SetNativeSize();
|
||||
intro.gameObject.SetActive(true);
|
||||
transformInfo.Set(desc);
|
||||
SetIntroSprite(handle.GetAssetObject<Sprite>(), desc);
|
||||
}
|
||||
|
||||
public async void OnClickPreviousIntroAudio(string auid, string desc)
|
||||
@@ -85,7 +84,7 @@ namespace Main
|
||||
});
|
||||
SetIntroSprite(info.sprite, desc);
|
||||
}
|
||||
private void SetIntroSprite(Sprite sprite, string desc)
|
||||
public void SetIntroSprite(Sprite sprite, string desc)
|
||||
{
|
||||
|
||||
intro.sprite = sprite;
|
||||
@@ -95,6 +94,7 @@ namespace Main
|
||||
}
|
||||
public enum IntroType
|
||||
{
|
||||
IntroSpriteName,
|
||||
IntroSprite,
|
||||
IntroAudio,
|
||||
IntroAnimation
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Stary.Evo;
|
||||
using Stary.Evo.AudioCore;
|
||||
using Stary.Evo.InformationSave;
|
||||
using Stary.Evo.TableTextConversion;
|
||||
using Stary.Evo.UIFarme;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using YooAsset;
|
||||
|
||||
namespace Main
|
||||
{
|
||||
public class TextPanel : BasePanel
|
||||
{
|
||||
static readonly string path = "TextPanel";
|
||||
|
||||
private TextMeshProUGUI intro;
|
||||
|
||||
private LocalTransformInfo transformInfo;
|
||||
|
||||
|
||||
public TextPanel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public override void Initialize(GameObject panelGo)
|
||||
{
|
||||
base.Initialize(panelGo);
|
||||
|
||||
intro = activePanel.transform.Find("Intro").GetComponent<TextMeshProUGUI>();
|
||||
transformInfo = activePanel.transform.GetComponent<LocalTransformInfo>();
|
||||
intro.text = "";
|
||||
|
||||
intro.overflowMode = TextOverflowModes.Overflow; // 启用溢出模式
|
||||
|
||||
intro.GetComponent<CanvasGroup>().alpha = 0;
|
||||
}
|
||||
|
||||
public override void OnEnter()
|
||||
{
|
||||
base.OnEnter();
|
||||
|
||||
this.RegisterEvent<IntroType, string, float, string>(IntroType.SetText, OnSetTextIntroEvent);
|
||||
this.RegisterEvent<IntroType, string, string>(IntroType.SetTextSubtitle, OnSetTextIntroEvent);
|
||||
}
|
||||
|
||||
public override void OnExit(float delay = 0)
|
||||
{
|
||||
base.OnExit(delay);
|
||||
intro.text = "";
|
||||
this.UnRegisterEvent<IntroType, string, float, string>(IntroType.SetText, OnSetTextIntroEvent);
|
||||
this.UnRegisterEvent<IntroType, string, string>(IntroType.SetTextSubtitle, OnSetTextIntroEvent);
|
||||
}
|
||||
|
||||
|
||||
public async void OnSetTextIntroEvent(string text, float audioLength, string desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
float delay = audioLength / (float)text.Length / 2;
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
intro.text += text[i];
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(delay),
|
||||
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Debug.Log($"ComponentExtensions:【{path}】异步任务被取消");
|
||||
}
|
||||
|
||||
intro.ForceMeshUpdate();
|
||||
transformInfo.Set(desc);
|
||||
}
|
||||
|
||||
public async void OnSetTextIntroEvent(string UIid, string desc)
|
||||
{
|
||||
var messageInfo = this.GetData<IAudioTableData>().GetUIInfo(UIid);
|
||||
if (messageInfo != null)
|
||||
{
|
||||
if (messageInfo.subtitle.Count > 0)
|
||||
{
|
||||
foreach (var subtitle in messageInfo.subtitle)
|
||||
{
|
||||
intro.text = "";
|
||||
//float delay = (float)(subtitle.end - subtitle.start) /subtitle.subtitle.Length /2 ;
|
||||
intro.GetComponent<CanvasGroup>().DOFade(1, 0.2f);
|
||||
|
||||
intro.text = subtitle.subtitle;
|
||||
// for (int i = 0; i < subtitle.subtitle.Length; i++)
|
||||
// {
|
||||
// intro.text += subtitle.subtitle[i];
|
||||
// await UniTask.Delay(TimeSpan.FromSeconds(delay),
|
||||
// cancellationToken: tokenSource.Token);
|
||||
// }
|
||||
try
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds((float)(subtitle.end - subtitle.start)),
|
||||
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
||||
intro.GetComponent<CanvasGroup>().DOFade(0, 0.2f);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.2f),
|
||||
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Debug.Log($"ComponentExtensions:【{path}】异步任务被取消");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transformInfo.Set(desc);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"UnityEvo:【{UIid}】没有找到对应的UI信息");
|
||||
}
|
||||
}
|
||||
|
||||
public enum IntroType
|
||||
{
|
||||
SetText,
|
||||
SetTextSubtitle,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a6fe969cd7b8f84fb3284ab34f4dd3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31eb4845a899e544dab03b7aba620e01
|
||||
guid: acecbcc2903fe7044bfb88198181773a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
Reference in New Issue
Block a user