예제 #1
0
    private void OnClipFinished(object sender, AudioEventArgs e)
    {
        // Store the source in the pool
        ManagedSource source = (ManagedSource)sender;

        sourcePool.Put(source);
    }
예제 #2
0
    public ManagedSource PlayClip(Vector3 position, AudioClip clip, float volume, bool looped)
    {
        // Create the source and start it playing
        ManagedSource source = sourcePool.Get();

        source.Play(position, clip, volume, looped);
        return(source);
    }
예제 #3
0
    private ManagedSource CreateNewAudioSource()
    {
        ManagedSource instance = GameObject.Instantiate <ManagedSource>(sourcePrefab);

        // Self-register for events
        instance.clipFinishedHandler += OnClipFinished;

        return(instance);
    }
예제 #4
0
    /// <summary>
    ///
    /// </summary>
    public void StopAllSources()
    {
        List <ManagedSource> sources = activeSources.GetRawList();
        int len = sources.Count - 1;

        // Iterate and stop all sources
        for (int i = len; i >= 0; i--)
        {
            ManagedSource source = sources[i];
            source.Stop();
        }
    }
예제 #5
0
 private void OnSourceStored(ManagedSource obj)
 {
     activeSources.Remove(obj);
 }
예제 #6
0
 private void OnSourceReleased(ManagedSource obj)
 {
     activeSources.Add(obj);
 }
예제 #7
0
 public AudioController(SimulationController controller) : base(controller)
 {
     sourcePrefab  = Resources.Load <ManagedSource>("AudioSourcePrefab");
     activeSources = new Store <ManagedSource>();
     sourcePool    = new Pool <ManagedSource>(CreateNewAudioSource, OnSourceStored, OnSourceReleased);
 }