修复音粒子效果符触发器

This commit is contained in:
2025-12-02 17:18:57 +08:00
parent 11623b044b
commit 6c5dc9cdbe
2 changed files with 40 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
using Convention;
using NUnit.Framework.Internal;
using System.Collections;
using System.Collections.Generic;
using Convention;
using UnityEngine;
namespace Demo.Game
@@ -16,6 +17,20 @@ namespace Demo.Game
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, string> AssetBundles = new();
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, GameObject> Prefabs = new();
[Content, SerializeField] private Dictionary<IInteraction.JudgementLevel, float> Durations = new();
[Setting, SerializeField] private bool IsZooming = true;
[Setting, SerializeField] private MathExtension.EaseCurveType ZoomCurve = MathExtension.EaseCurveType.OutCubic;
[Convention.RScript.Variable.Attr.Method]
public void SetZooming(bool status)
{
IsZooming = status;
}
[Convention.RScript.Variable.Attr.Method]
public void SetZoomingCurve(MathExtension.EaseCurveType curve)
{
ZoomCurve = curve;
}
protected override IEnumerator DoSomethingDuringApplyScript()
{
@@ -53,9 +68,10 @@ namespace Demo.Game
}));
}
private void CreateParticle(GameObject prefab)
private GameObject CreateParticle(GameObject prefab)
{
prefab.SetActive(true);
return prefab;
}
private void DestroyParticle(GameObject prefab)
@@ -63,14 +79,31 @@ namespace Demo.Game
prefab.SetActive(false);
}
private IEnumerator DoParticleRuntime(float duration, GameObject effect)
{
CreateParticle(effect);
if (IsZooming)
{
for (float clock = 0f; clock < duration; clock += Time.deltaTime)
{
float scale = MathExtension.Evaluate(clock / duration, ZoomCurve);
effect.transform.localScale = new Vector3(scale, scale, scale);
yield return null;
}
}
else
{
effect.transform.localScale = Vector3.one;
yield return new WaitForSeconds(duration);
}
DestroyParticle(effect);
}
public override void OnJudgement(IInteraction.JudgementLevel level)
{
if (Prefabs.TryGetValue(level, out var effect))
{
ConventionUtility.CreateSteps()
.Next(() => CreateParticle(effect))
.Wait(Durations[level], () => DestroyParticle(effect))
.Invoke();
ConventionUtility.StartCoroutine(DoParticleRuntime(Durations[level], effect));
}
}
}