From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/ParticleExplosionModifier.cs | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 GameCode/ParticleExplosionModifier.cs (limited to 'GameCode/ParticleExplosionModifier.cs') diff --git a/GameCode/ParticleExplosionModifier.cs b/GameCode/ParticleExplosionModifier.cs new file mode 100644 index 0000000..ca3a6f6 --- /dev/null +++ b/GameCode/ParticleExplosionModifier.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections; +using UnityEngine; + +public class ParticleExplosionModifier : MonoBehaviour +{ + public AnimationCurve curve; + + public float speed = 1f; + + private ParticleSystem effect; + + private ParticleSystem.MainModule main; + + private Coroutine corutine; + + private void Start() + { + effect = GetComponent(); + main = effect.main; + Explosion componentInParent = GetComponentInParent(); + componentInParent.DealDamageAction = (Action)Delegate.Combine(componentInParent.DealDamageAction, new Action(DealDamage)); + Explosion componentInParent2 = GetComponentInParent(); + componentInParent2.DealHealAction = (Action)Delegate.Combine(componentInParent2.DealHealAction, new Action(DealDamage)); + } + + public void DealDamage(Damagable damagable) + { + if (corutine != null) + { + StopCoroutine(corutine); + } + corutine = StartCoroutine(DoCurve()); + } + + private IEnumerator DoCurve() + { + float c = 0f; + float t = curve.keys[curve.keys.Length - 1].time; + while (c < t) + { + ParticleSystem.MinMaxCurve startSize = main.startSize; + startSize.constantMin = curve.Evaluate(c) * 0.5f; + startSize.constantMax = curve.Evaluate(c); + main.startSize = startSize; + c += TimeHandler.deltaTime * speed; + yield return null; + } + } +} -- cgit v1.1-26-g67d0