blob: c834a68a6f00629bd5f321f4f19bb8c7df78f32f (
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
51
52
53
|
using UnityEngine;
public class ParticlePlayer : MonoBehaviour
{
public static ParticlePlayer instance;
private int spawnsThisFrame;
private void Awake()
{
instance = this;
}
private void Update()
{
spawnsThisFrame = 0;
}
public void PlayEffect(string effectName, Vector3 position, Quaternion rotation, float scale = 1f, Transform followTransform = null)
{
if ((float)spawnsThisFrame > 5f)
{
return;
}
spawnsThisFrame++;
Transform transform = base.transform.Find(effectName);
if (!transform)
{
return;
}
if ((bool)followTransform)
{
transform = Object.Instantiate(transform.gameObject, null).transform;
}
transform.transform.position = position;
transform.transform.localScale = scale * Vector3.one;
transform.transform.rotation = rotation;
if ((bool)followTransform)
{
transform.gameObject.AddComponent<FollowLocalPos>().Follow(followTransform);
}
ParticleSystem[] componentsInChildren = transform.GetComponentsInChildren<ParticleSystem>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((bool)followTransform)
{
ParticleSystem.MainModule main = componentsInChildren[i].main;
main.simulationSpace = ParticleSystemSimulationSpace.Local;
}
componentsInChildren[i].Play();
}
}
}
|