Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
HS_ParticleEndSound.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5
6public class HS_ParticleEndSound : MonoBehaviour
7{
8 [Serializable]
9 public class Pool
10 {
11 public string tag;
12
13 public GameObject prefab;
14
15 public int size;
16 }
17
18 public float poolReturnTimer = 1.5f;
19
20 public float explosionMinVolume = 0.3f;
21
22 public float explosionMaxVolume = 0.7f;
23
24 public float explosionPitchMin = 0.75f;
25
26 public float explosionPitchMax = 1.25f;
27
28 public float shootMinVolume = 0.05f;
29
30 public float shootMaxVolume = 0.1f;
31
32 public float shootPitchMin = 0.75f;
33
34 public float shootPitchMax = 1.25f;
35
36 public AudioClip[] audioExplosion;
37
38 public AudioClip[] audioShot;
39
41
42 public List<Pool> pools;
43
44 public Dictionary<string, Queue<GameObject>> poolDictionary;
45
46 private void Awake()
47 {
48 SharedInstance = this;
49 }
50
51 private void Start()
52 {
53 poolDictionary = new Dictionary<string, Queue<GameObject>>();
54 foreach (Pool pool in pools)
55 {
57 GameObject gameObject = UnityEngine.Object.Instantiate(pool.prefab);
58 AudioSource component = gameObject.GetComponent<AudioSource>();
59 if (pool.tag == "AudioExplosion")
60 {
61 component.clip = audioExplosion[UnityEngine.Random.Range(0, audioExplosion.Length)];
62 component.volume = UnityEngine.Random.Range(explosionMinVolume, explosionMaxVolume);
63 component.pitch = UnityEngine.Random.Range(explosionPitchMin, explosionPitchMax);
64 }
65 else if (pool.tag == "AudioShot")
66 {
67 component.clip = audioShot[UnityEngine.Random.Range(0, audioExplosion.Length)];
68 component.volume = UnityEngine.Random.Range(shootMinVolume, shootMaxVolume);
69 component.pitch = UnityEngine.Random.Range(shootPitchMin, shootPitchMax);
70 }
71 gameObject.transform.parent = base.gameObject.transform;
72 gameObject.SetActive(value: false);
73 queue.Enqueue(gameObject);
74 poolDictionary.Add(pool.tag, queue);
75 }
76 }
77
78 public GameObject SpawnFromPool(string tag, Vector3 position)
79 {
80 if (!poolDictionary.ContainsKey(tag))
81 {
82 Debug.LogWarning("Pool with tag" + tag + " does not excist.");
83 return null;
84 }
85 GameObject gameObject = poolDictionary[tag].Dequeue();
86 gameObject.SetActive(value: true);
87 position.z = 0f;
88 gameObject.transform.position = position;
89 poolDictionary[tag].Enqueue(gameObject);
90 return gameObject;
91 }
92
93 public void LateUpdate()
94 {
95 ParticleSystem.Particle[] array = new ParticleSystem.Particle[GetComponent<ParticleSystem>().particleCount];
96 int particles = GetComponent<ParticleSystem>().GetParticles(array);
97 for (int i = 0; i < particles; i++)
98 {
99 if (audioExplosion.Length != 0 && array[i].remainingLifetime < Time.deltaTime)
100 {
101 GameObject gameObject = SharedInstance.SpawnFromPool("AudioExplosion", array[i].position);
102 if (gameObject != null)
103 {
104 StartCoroutine(LateCall(gameObject));
105 }
106 }
107 if (audioShot.Length != 0 && array[i].remainingLifetime >= array[i].startLifetime - Time.deltaTime)
108 {
109 GameObject gameObject2 = SharedInstance.SpawnFromPool("AudioShot", array[i].position);
110 if (gameObject2 != null)
111 {
112 StartCoroutine(LateCall(gameObject2));
113 }
114 }
115 }
116 }
117
118 private IEnumerator LateCall(GameObject soundInstance)
119 {
120 yield return new WaitForSeconds(poolReturnTimer);
121 soundInstance.SetActive(value: false);
122 }
123}
IEnumerator LateCall(GameObject soundInstance)
static HS_ParticleEndSound SharedInstance
Dictionary< string, Queue< GameObject > > poolDictionary
GameObject SpawnFromPool(string tag, Vector3 position)
Definition: Queue.cs:2