示例#1
0
        private void SetSource()
        {
            List <Source>   sources      = SourceObjects.OrderBy(e => e.ID).ToList();
            List <Matrix2d> matrixList   = sources.Select(e => e.IDmatrix).ToList();
            Matrix2d        sourceMatrix = Matrix2d.MergeMatrix(matrixList, "");

            EnvimetMatrix.Add("sourceMatrix", sourceMatrix);
        }
示例#2
0
        /// <summary>
        /// Destroys all of the SpatialSources spawned by this Spawner immediately.
        /// </summary>
        public void KillAllSpawnedSources()
        {
            SourceObjects.ForEach(x =>
            {
                var soundSource = x.GetComponent <SoundToolKitSpatialSource>();
                var playback    = soundSource.Playbacks.Last();

                playback.OnEnded -= OnPlaybackEnded;
                OnPlaybackEnded(playback);

                SourceObjects.Remove(x);
                Destroy(x);
            });
        }
示例#3
0
        /// <summary>
        /// Spawn a SoundToolKitSpatialSource playing a single given SoundToolKitSample at a given location.
        /// The default position is that of component's parent GameObject.
        /// </summary>
        /// <param name="sampleToPlay">
        /// The VolumeControlledSample to be played by the spawned source. Pass an element of the Samples List or a VolumeControlledSample object.
        /// </param>
        /// <param name="positionOfSpawn">
        /// Position at which the Source is spawned. Defaults to the parent GameObject's position.
        /// </param>
        public void SpawnSound(VolumeControlledSample sampleToPlay, Vector3?positionOfSpawn = null)
        {
            if (sampleToPlay != null && sampleToPlay.Sample != null)
            {
                var spawnPosition = DeterminePosition(positionOfSpawn);

                var sourceObject = new GameObject("SpawnedSoundSource");
                sourceObject.transform.position = spawnPosition;
                SourceObjects.Add(sourceObject);

                var source = sourceObject.AddComponent <SoundToolKitSpatialSource>();
                SetupSource(source);

                PlayOneShot(source, sampleToPlay);

                StartCoroutine(TimedDestroy(sourceObject, sampleToPlay.Sample.AudioClip.length));
            }
            else
            {
                WarnSampleInvalid();
            }
        }
示例#4
0
        /// <summary>
        /// Spawn a SoundToolKitSpatialSource playing a random SoundToolKitSample from the Samples list at a given position.
        /// The default position is that of component's parent GameObject.
        /// </summary>
        /// <param name="positionOfSpawn">
        /// Position at which the Source is spawned. Defaults to the parent GameObject's position.
        /// </param>
        public void SpawnRandomSound(Vector3?positionOfSpawn = null)
        {
            if (m_samples.Any() && !m_samples.Exists(x => x.Sample == null))
            {
                var spawnPosition = DeterminePosition(positionOfSpawn);

                var sourceObject = new GameObject("SpawnedSoundSource");
                sourceObject.transform.position = spawnPosition;
                SourceObjects.Add(sourceObject);

                var source = sourceObject.AddComponent <SoundToolKitSpatialSource>();
                SetupSource(source);

                var randomSample = Samples[UnityEngine.Random.Range(0, Samples.Count - 1)];
                PlayOneShot(source, randomSample);

                StartCoroutine(TimedDestroy(sourceObject, randomSample.Sample.AudioClip.length));
            }
            else
            {
                WarnSampleInvalid();
            }
        }