コード例 #1
0
ファイル: SoundController.cs プロジェクト: popboyhsf/Unity
 public void StopAudioSource(AudioSource audioSource)
 {
     if (audioSource)
     {
         audioSource.loop = false;
         audioSource.Pause();
         audioSourcePool.Release(audioSource);
     }
 }
コード例 #2
0
        public void should_nullify_class_based_components_on_release()
        {
            var componentPool = new ComponentPool <TestComponentOne>(10);
            var indexToUse    = componentPool.IndexPool.AllocateInstance();

            componentPool.Components[indexToUse] = new TestComponentOne();

            componentPool.Release(indexToUse);

            Assert.True(componentPool.Components.All(x => x is null));
        }
コード例 #3
0
        public void should_dispose_disposable_component_on_release()
        {
            var componentPool  = new ComponentPool <TestDisposableComponent>(10);
            var indexToUse     = componentPool.IndexPool.AllocateInstance();
            var componentToUse = new TestDisposableComponent();

            componentPool.Components[indexToUse] = componentToUse;

            componentPool.Release(indexToUse);

            Assert.True(componentToUse.isDisposed);
        }
コード例 #4
0
        public void should_request_index_pool_release_when_releasing_component()
        {
            var componentPool         = new ComponentPool <TestStructComponentOne>(10);
            var indexToUse            = componentPool.IndexPool.AllocateInstance();
            var availableIndexesPrior = componentPool.IndexPool.AvailableIndexes.ToArray();

            componentPool.Release(indexToUse);
            var availableIndexesAfter = componentPool.IndexPool.AvailableIndexes.ToArray();

            Assert.NotSame(availableIndexesPrior, availableIndexesAfter);
            Assert.DoesNotContain(indexToUse, availableIndexesPrior);
            Assert.Contains(indexToUse, availableIndexesAfter);
        }