This commit is contained in:
2025-09-02 14:15:18 +08:00
parent 796c8d845d
commit 8872c20cf2
34 changed files with 2024 additions and 695 deletions

View File

@@ -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;
}
}
}