12 HS_ParticleEndSound.SharedInstance =
this;
18 this.poolDictionary =
new Dictionary<string, Queue<GameObject>>();
22 GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(pool.prefab);
23 AudioSource component = gameObject.GetComponent<AudioSource>();
24 if (pool.tag ==
"AudioExplosion")
26 component.clip = this.audioExplosion[UnityEngine.Random.Range(0, this.audioExplosion.Length)];
27 component.volume = UnityEngine.Random.Range(this.explosionMinVolume, this.explosionMaxVolume);
28 component.pitch = UnityEngine.Random.Range(this.explosionPitchMin, this.explosionPitchMax);
30 else if (pool.tag ==
"AudioShot")
32 component.clip = this.audioShot[UnityEngine.Random.Range(0, this.audioExplosion.Length)];
33 component.volume = UnityEngine.Random.Range(this.shootMinVolume, this.shootMaxVolume);
34 component.pitch = UnityEngine.Random.Range(this.shootPitchMin, this.shootPitchMax);
36 gameObject.transform.parent = base.gameObject.transform;
37 gameObject.SetActive(
false);
38 queue.Enqueue(gameObject);
39 this.poolDictionary.Add(pool.tag, queue);
44 public GameObject SpawnFromPool(
string tag, Vector3 position)
46 if (!this.poolDictionary.ContainsKey(tag))
48 Debug.LogWarning(
"Pool with tag" + tag +
" does not excist.");
51 GameObject gameObject = this.poolDictionary[tag].Dequeue();
52 gameObject.SetActive(
true);
54 gameObject.transform.position = position;
55 this.poolDictionary[tag].Enqueue(gameObject);
60 public void LateUpdate()
62 ParticleSystem.Particle[] array =
new ParticleSystem.Particle[base.GetComponent<ParticleSystem>().particleCount];
63 int particles = base.GetComponent<ParticleSystem>().GetParticles(array);
64 for (
int i = 0; i < particles; i++)
66 if (this.audioExplosion.Length != 0 && array[i].remainingLifetime < Time.deltaTime)
68 GameObject gameObject =
HS_ParticleEndSound.SharedInstance.SpawnFromPool(
"AudioExplosion", array[i].position);
69 if (gameObject !=
null)
71 base.StartCoroutine(this.LateCall(gameObject));
74 if (this.audioShot.Length != 0 && array[i].remainingLifetime >= array[i].startLifetime - Time.deltaTime)
76 GameObject gameObject2 =
HS_ParticleEndSound.SharedInstance.SpawnFromPool(
"AudioShot", array[i].position);
77 if (gameObject2 !=
null)
79 base.StartCoroutine(this.LateCall(gameObject2));
86 private IEnumerator LateCall(GameObject soundInstance)
88 yield
return new WaitForSeconds(this.poolReturnTimer);
89 soundInstance.SetActive(
false);
94 public float poolReturnTimer = 1.5f;
97 public float explosionMinVolume = 0.3f;
100 public float explosionMaxVolume = 0.7f;
103 public float explosionPitchMin = 0.75f;
106 public float explosionPitchMax = 1.25f;
109 public float shootMinVolume = 0.05f;
112 public float shootMaxVolume = 0.1f;
115 public float shootPitchMin = 0.75f;
118 public float shootPitchMax = 1.25f;
121 public AudioClip[] audioExplosion;
124 public AudioClip[] audioShot;
133 public Dictionary<string, Queue<GameObject>> poolDictionary;
143 public GameObject prefab;