Permalink
Browse files

Updated object pool to use exceptions

  • Loading branch information...
GandhiGames committed Sep 21, 2016
1 parent 09779bb commit 67245eb2b8c3b60f76e88d7592e86cfbe05ea8a7
Showing with 729 additions and 560 deletions.
  1. BIN Assets/Guide.docx
  2. +0 −4 Assets/Guide.docx.meta
  3. BIN Assets/Materials/Grey.mat
  4. BIN Assets/Scenes/Demo Scene.unity
  5. +15 −14 Assets/Scripts/Audio/2D/AudioEvent2D.cs
  6. +58 −57 Assets/Scripts/Audio/2D/AudioPlayer2D.cs
  7. +4 −6 Assets/Scripts/Audio/2D/IAudioEvent2D.cs
  8. +26 −23 Assets/Scripts/Audio/3D/AudioEvent3D.cs
  9. +61 −60 Assets/Scripts/Audio/3D/AudioPlayer3D.cs
  10. +4 −7 Assets/Scripts/Audio/3D/IAudioEvent3D.cs
  11. +69 −59 Assets/Scripts/Event System/Events.cs
  12. +3 −6 Assets/Scripts/Event System/GameEvent.cs
  13. +209 −131 Assets/Scripts/Object Pool/ObjectPool.cs
  14. +0 −12 Assets/Scripts/Object Pool/ObjectPoolItem.cs
  15. +75 −0 Assets/Scripts/Singleton.cs
  16. +2 −2 Assets/Scripts/{Object Pool/ObjectPoolItem.cs.meta → Singleton.cs.meta}
  17. +17 −18 Assets/Scripts/_Demo Scene Scripts/Controllers/CubeController.cs
  18. +80 −57 Assets/Scripts/_Demo Scene Scripts/Controllers/ShapeController.cs
  19. +15 −16 Assets/Scripts/_Demo Scene Scripts/Controllers/SphereController.cs
  20. +6 −7 Assets/Scripts/_Demo Scene Scripts/Events/CubeSelectedEvent.cs
  21. +36 −34 Assets/Scripts/_Demo Scene Scripts/Events/ExplosionEvent.cs
  22. +5 −7 Assets/Scripts/_Demo Scene Scripts/Events/SphereSelectedEvent.cs
  23. +41 −33 Assets/Scripts/_Demo Scene Scripts/MouseController.cs
  24. +2 −6 Assets/Scripts/_Demo Scene Scripts/ReloadScene.cs
  25. BIN ProjectSettings/{UnityAnalyticsManager.asset → ClusterInputManager.asset}
  26. BIN ProjectSettings/GraphicsSettings.asset
  27. BIN ProjectSettings/ProjectSettings.asset
  28. +1 −1 ProjectSettings/ProjectVersion.txt
  29. BIN ProjectSettings/UnityConnectSettings.asset
View
BIN -91.4 KB Assets/Guide.docx
Binary file not shown.
View

This file was deleted.

Oops, something went wrong.
View
BIN +0 Bytes (100%) Assets/Materials/Grey.mat
Binary file not shown.
View
BIN +1.16 KB (100%) Assets/Scenes/Demo Scene.unity
Binary file not shown.
@@ -1,18 +1,19 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
public class AudioEvent2D : GameEvent, IAudioEvent2D
{
public class AudioEvent2D : GameEvent, IAudioEvent2D
{
private AudioClip audioClip;
public AudioClip Audio { get {
return audioClip;
} }
public AudioEvent2D (AudioClip audioClip)
{
this.audioClip = audioClip;
}
}
private AudioClip audioClip;
public AudioClip Audio
{
get
{
return audioClip;
}
}
public AudioEvent2D(AudioClip audioClip)
{
this.audioClip = audioClip;
}
}
@@ -1,62 +1,63 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
[RequireComponent(typeof(AudioSource))]
public class AudioPlayer2D : MonoBehaviour
{
[RequireComponent (typeof(AudioSource))]
public class AudioPlayer2D : MonoBehaviour
{
public int MaxPending = 30;
private AudioSource source;
private IAudioEvent2D[] pending;
private int head;
private int tail;
void Awake ()
{
source = GetComponent<AudioSource> ();
source.spatialBlend = 0f;
}
void OnEnable ()
{
head = tail = 0;
pending = new IAudioEvent2D [MaxPending];
Events.instance.AddListener<AudioEvent2D> (OnAudio);
}
void OnDisable ()
{
Events.instance.RemoveListener<AudioEvent2D> (OnAudio);
}
void Update ()
{
if (head == tail)
return;
Debug.Log ("Playing AudioClip: " + pending [head].Audio.name);
source.PlayOneShot (pending [head].Audio);
head = (head + 1) % MaxPending;
}
void OnAudio (IAudioEvent2D e)
{
for (int i = head; i != tail; i = (i+1) % MaxPending) {
if (pending [i].Audio.name.Equals (e.Audio.name)) {
return;
}
}
pending [tail] = e;
tail = (tail + 1) % MaxPending;
}
}
public int MaxPending = 30;
private AudioSource source;
private IAudioEvent2D[] pending;
private int head;
private int tail;
void Awake()
{
source = GetComponent<AudioSource>();
source.spatialBlend = 0f;
}
void OnEnable()
{
head = tail = 0;
pending = new IAudioEvent2D[MaxPending];
Events.instance.AddListener<AudioEvent2D>(OnAudio);
}
void OnDisable()
{
Events.instance.RemoveListener<AudioEvent2D>(OnAudio);
}
void Update()
{
if (head == tail)
return;
Debug.Log("Playing AudioClip: " + pending[head].Audio.name);
source.PlayOneShot(pending[head].Audio);
head = (head + 1) % MaxPending;
}
void OnAudio(IAudioEvent2D e)
{
for (int i = head; i != tail; i = (i + 1) % MaxPending)
{
if (pending[i].Audio.name.Equals(e.Audio.name))
{
return;
}
}
pending[tail] = e;
tail = (tail + 1) % MaxPending;
}
}
@@ -1,10 +1,8 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
public interface IAudioEvent2D
{
public interface IAudioEvent2D
{
AudioClip Audio { get; }
}
AudioClip Audio { get; }
}
@@ -1,29 +1,32 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
public class AudioEvent3D : GameEvent, IAudioEvent3D
{
public class AudioEvent3D : GameEvent, IAudioEvent3D
{
private Vector3 position;
public Vector3 Position {
get {
return position;
}
}
private AudioClip audio;
public AudioClip Audio {
get {
return audio;
}
}
public AudioEvent3D (AudioClip audio, Vector3 position)
{
this.audio = audio;
this.position = position;
}
private Vector3 position;
public Vector3 Position
{
get
{
return position;
}
}
private AudioClip audio;
public AudioClip Audio
{
get
{
return audio;
}
}
public AudioEvent3D(AudioClip audio, Vector3 position)
{
this.audio = audio;
this.position = position;
}
}
}
@@ -1,65 +1,66 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
[RequireComponent(typeof(AudioSource))]
public class AudioPlayer3D : MonoBehaviour
{
[RequireComponent (typeof(AudioSource))]
public class AudioPlayer3D : MonoBehaviour
{
public int MaxPending = 30;
private AudioSource source;
private IAudioEvent3D[] pending;
private int head;
private int tail;
void Awake ()
{
source = GetComponent<AudioSource> ();
source.spatialBlend = 1f;
}
void OnEnable ()
{
head = tail = 0;
pending = new IAudioEvent3D [MaxPending];
Events.instance.AddListener<AudioEvent3D> (OnAudio);
}
void OnDisable ()
{
Events.instance.RemoveListener<AudioEvent3D> (OnAudio);
}
void Update ()
{
if (head == tail)
return;
Debug.Log ("Playing: " + pending [head].Audio.name + " at position: " + pending [head].Position);
AudioSource.PlayClipAtPoint (pending [head].Audio, pending [head].Position);
source.PlayOneShot (pending [head].Audio);
head = (head + 1) % MaxPending;
}
void OnAudio (IAudioEvent3D e)
{
for (int i = head; i != tail; i = (i+1) % MaxPending) {
Debug.Log (i + ": " + pending [i].Audio.name);
if (pending [i].Audio.name.Equals (e.Audio.name)) {
return;
}
}
pending [tail] = e;
tail = (tail + 1) % MaxPending;
}
}
public int MaxPending = 30;
private AudioSource source;
private IAudioEvent3D[] pending;
private int head;
private int tail;
void Awake()
{
source = GetComponent<AudioSource>();
source.spatialBlend = 1f;
}
void OnEnable()
{
head = tail = 0;
pending = new IAudioEvent3D[MaxPending];
Events.instance.AddListener<AudioEvent3D>(OnAudio);
}
void OnDisable()
{
Events.instance.RemoveListener<AudioEvent3D>(OnAudio);
}
void Update()
{
if (head == tail)
return;
Debug.Log("Playing: " + pending[head].Audio.name + " at position: " + pending[head].Position);
AudioSource.PlayClipAtPoint(pending[head].Audio, pending[head].Position);
source.PlayOneShot(pending[head].Audio);
head = (head + 1) % MaxPending;
}
void OnAudio(IAudioEvent3D e)
{
for (int i = head; i != tail; i = (i + 1) % MaxPending)
{
Debug.Log(i + ": " + pending[i].Audio.name);
if (pending[i].Audio.name.Equals(e.Audio.name))
{
return;
}
}
pending[tail] = e;
tail = (tail + 1) % MaxPending;
}
}
@@ -1,11 +1,8 @@
using UnityEngine;
using System.Collections;
namespace GameFoundations
public interface IAudioEvent3D
{
public interface IAudioEvent3D
{
Vector3 Position { get; }
AudioClip Audio { get; }
}
Vector3 Position { get; }
AudioClip Audio { get; }
}
Oops, something went wrong.

0 comments on commit 67245eb

Please sign in to comment.