示例#1
0
        static void OnExportWav(SerializedProperty property)
        {
            var path = EditorUtility.SaveFilePanel("Export as WAV", "", property.name + ".wav", "wav");

            if (path.Length == 0)
            {
                return;
            }
            var synth = new SfxrRenderer {
                param = PropertyToParams(property)
            };

            File.WriteAllBytes(path, synth.GetWavFile());
        }
示例#2
0
        /// <summary>
        /// Retrieves an AudioClip along with some other data if it's cached, otherwise it is generated
        /// </summary>
        static ClipTimeTuple CacheGet(SfxrParams param)
        {
            // make sure we have a renderer
            if (sfxrRenderer == null)
            {
                sfxrRenderer = new SfxrRenderer();
            }

            if (cache.TryGetValue(param, out var entry))
            {
                // sometimes it seems the audio clip will get lost despite the cache having a reference to it, so we may need to regenerate it
                if (entry.clip == null)
                {
                    entry.clip = sfxrRenderer.GenerateClip(param);
                }
                entry.firstPlay = false;
                return(entry);
            }

            entry = new ClipTimeTuple(sfxrRenderer.GenerateClip(param));
            cache.Add(param, entry);

            return(entry);
        }