private void Initialize()
        {
            m_stkTaskScheduler = new SoundToolKitTaskScheduler();

            if (StkAudioEngine == null)
            {
                InitializeAudioEngine();
            }

            InitializeAudioBridge();

            ResourceContainer = new ResourcesContainer();

            if (m_settingsInspector == null)
            {
                Settings = ScriptableObject.CreateInstance <SoundToolKitSettings>();
            }

            UpdateProperties();

            SoundToolKitDebug.SetLogStackTrace();

#if UNITY_EDITOR
#if !UNITY_5 && !UNITY_2017_1
            EditorApplication.pauseStateChanged += EditorApplication_pauseStateChanged;
#else
            EditorApplication.playmodeStateChanged += EditorApplication_playmodeStateChanged;
#endif
#endif
            SoundToolKitDebug.Log("Sound enabled.");

            // NOTE: On audioEngine start it will automatically play sound.
            Play();
        }
Beispiel #2
0
        protected override void OnValidate()
        {
            // <STK.LITE>
            // Warning: Modifying this code may result in plugin instability and frequent crashes to desktop.
            // This is the SoundToolKit Lite version.
            // Internally only one Playback per source is created anyway, so circumventing this check will not result in a possibility
            // of creating more playbacks - the previous Playback will be overwritten.
            if (Playbacks != null && Playbacks.Count > 1)
            {
                Playbacks.RemoveRange(1, Playbacks.Count - 1);
                SoundToolKitDebug.Log("Only one Playback per Sound Source is available in the SoundToolKit Lite version. " +
                                      "Deleting illegal playbacks.");
                return;
            }
            // </STK.LITE>

            base.OnValidate();

            if (Playbacks != null)
            {
                Playbacks.ForEach(x =>
                {
                    x.OnValidate();
                    if (m_playbackComponent != null)
                    {
                        m_playbackComponent.SynchronizePlaybackSamples(x);
                    }
                });
            }
        }
        public override void OnStkInitialized(SoundToolKitManager soundToolKitManager)
        {
            if (!Initialized)
            {
                // <STK.LITE>
                // Warning: Modifying this code may result in plugin instability and frequent crashes to desktop.
                // This is the SoundToolKit Lite version.
                // Internally only three SoundSources can be created simultaneously, so circumventing this check will not result
                // in a possibility of creating more sound sources - only more references to the same source.
                if (soundToolKitManager.ResourceContainer.AudioSources.Count >= StkLite.AvailableSources())
                {
                    SoundToolKitDebug.Log("Only three SoundSources are available simultaneously in the SoundToolKit " +
                                          "Lite version. Deleting the illegal SoundSource components at GameObject " + gameObject.name);
                    Destroy(this);
                    return;
                }
                // </STK.LITE>

                SoundToolKitDebug.Assert(soundToolKitManager.StkAudioEngine != null, "AudioEngine is not initialized.");

                var audioEngine = soundToolKitManager.StkAudioEngine;
                m_ambientSoundSource = audioEngine.ResourcesFactory.CreateAmbientSoundSource();

                UpdateSourceProperties();

                soundToolKitManager.ResourceContainer.Add(audioSource: this);

                m_playbackComponent = new PlaybackComponent(m_ambientSoundSource);

                m_playbackComponent.InitializeInternalPlaybacks(Playbacks);
                m_playbackComponent.PlayOnAwake(Playbacks, gameObject.activeSelf, isActiveAndEnabled);

                Initialized = true;
            }
        }
        private void InitializeTemporaryMeshCluster()
        {
            var meshes = SoundToolKitManager.Instance.ResourceContainer.AcousticMeshes;

            if (meshes.Any(x => x.MeshCluster == null))
            {
                m_temporaryCluster      = ScriptableObject.CreateInstance <SoundToolKitMeshCluster>();
                m_temporaryCluster.name = "Temporary Mesh Cluster";
                MeshClusters.Add(m_temporaryCluster);

                SoundToolKitDebug.Log("Temporary SoundToolKitMeshCluster created for the duration of the playtime " +
                                      "in order to load all of the SoundToolKitMeshes that have no MeshCluster assigned. \n" +
                                      "To make this permanent and suppress this message use the menu " +
                                      "Tools/SoundToolKit/Geometry/SynchronizeDefaultGeometry after exiting the PlayMode. \n" +
                                      "In order not to load specific SoundToolKitMeshes, assign them to " +
                                      "a MeshCluster that is not added to the SoundToolKitGeometry's MeshClusters field.");

                foreach (var mesh in meshes)
                {
                    if (mesh.MeshCluster == null)
                    {
                        mesh.MeshCluster = MeshClusters.Last();
                    }
                }
            }
        }
Beispiel #5
0
        internal void WriteData(string filename, byte[] geometryData)
        {
            Filename = Path.ChangeExtension(filename, "dat");
            var targetPath = DataFilePath();

            File.WriteAllBytes(targetPath, geometryData);

            SoundToolKitDebug.Log("Successful serialization of a MeshCluster. Geometry data saved to file: " + Filename);
#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(this);
#endif
        }
 internal void SerializeGeometry()
 {
     MeshClusters.ForEach(x =>
     {
         if (x != null && x != m_temporaryCluster)
         {
             x.Serialize();
         }
         else if (x == m_temporaryCluster)
         {
             SoundToolKitDebug.Log("Temporary Mesh Cluster can't be serialized.");
         }
     });
 }
Beispiel #7
0
        private void Awake()
        {
            // <STK.LITE>
            // Warning: Modifying this code will result in an undefined behaviour.
            // This is the SoundToolKit Lite version.
            // SourceSpawner component is not allowed in that version.
            // To obtain a full version, visit https://assetstore.unity.com/packages/tools/audio/soundtoolkit-136305
            SoundToolKitDebug.Log("SourceSpawner is not available in the SoundToolKit Lite version. " +
                                  "Deleting the illegal SourceSpawner component.");
            Destroy(this);
            // </STK.LITE>

            if (m_samples == null)
            {
                m_samples = new List <VolumeControlledSample>();
            }

            SourceObjects = new List <GameObject>();
        }
Beispiel #8
0
        public void OnStkInitialized(SoundToolKitManager soundToolKitManager)
        {
            if (!Initialized)
            {
                SoundToolKitDebug.Assert(soundToolKitManager.StkAudioEngine != null, "AudioEngine is not initialized.");
                var audioEngine = soundToolKitManager.StkAudioEngine;
                m_toolkit = new AiToolKit(audioEngine);

                SoundToolKitDebug.Assert(m_toolkit != null, "SoundToolKitAI is not initialized.");
                if (m_toolkit != null)
                {
                    SoundToolKitDebug.Log("SoundToolKitAI intialized.");
                    m_toolkit.StopAnalysis();
                    m_analysisEnabled           = m_toolkit.AnalysisEnabled();
                    m_energyThreshold           = m_toolkit.EnergyThreshold;
                    m_analyseAllSources         = false;
                    m_wasAnalysisOnBeforeChange = false;
                }
                Initialized = true;
            }
        }
Beispiel #9
0
 private void RestoreGeometry()
 {
     Model.RestoreGeometry(m_serializedGeometry.ReadData());
     SoundToolKitDebug.Log("SerializedGeometry restored for MeshCluster: " + name);
 }