summaryrefslogtreecommitdiff
path: root/GameCode/ParticleExplosionModifier.cs
blob: ca3a6f6ecb1d916540713123aa0c5038da8834c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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<ParticleSystem>();
		main = effect.main;
		Explosion componentInParent = GetComponentInParent<Explosion>();
		componentInParent.DealDamageAction = (Action<Damagable>)Delegate.Combine(componentInParent.DealDamageAction, new Action<Damagable>(DealDamage));
		Explosion componentInParent2 = GetComponentInParent<Explosion>();
		componentInParent2.DealHealAction = (Action<Damagable>)Delegate.Combine(componentInParent2.DealHealAction, new Action<Damagable>(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;
		}
	}
}