internal void ExportAudio(AudioClip audio) { if (audio == null) return; string path = AssetDatabase.GetAssetPath(audio.GetInstanceID()); if (exportedAudio.Contains(path)) return; exportedAudio.Add(path); string dest = Path.Combine(AudioDir, Path.GetFileName(path)); try { File.Copy(path, dest, true); } catch (UnityException ue) { Debug.Log(ue.ToString()); throw; } }
public void ExportAudio(AudioClip asset) { string assetPath = AssetDatabase.GetAssetPath(asset.GetInstanceID()); string exportPath = Path.Combine(Path.Combine(assets.AudioDir, ".."), assetPath.Replace("Assets/", "")); if (!Directory.Exists(Path.GetDirectoryName(exportPath))) { Directory.CreateDirectory(Path.GetDirectoryName(exportPath)); } File.Copy(assetPath, exportPath, true); //Debug.Log("Exported Audio asset to " + exportPath); }
public ImportInfo( AudioClip clip ) { Clip = clip; Path = AssetDatabase.GetAssetPath( clip.GetInstanceID() ); GUID = AssetDatabase.AssetPathToGUID( Path ); Importer = AssetImporter.GetAtPath( Path ) as AudioImporter; if( GATEditorUtilities.IsInResources( Path ) ) { PathInResources = GATEditorUtilities.PathInResources( Path ); } else if( GATEditorUtilities.IsInStreamingAssets( Path ) ) { PathInResources = GATEditorUtilities.PathInStreamingAssets( Path ); System.IO.Path.ChangeExtension( PathInResources, System.IO.Path.GetExtension( Importer.assetPath ) ); IsStreamingAsset = true; } }
/// <summary> /// Plays the given audio clip with a random pitch and volume as defined in the settings given. /// </summary> public AudioSource PlayRandom(AudioClip clip, Vector3 pos, AudioClipSettings settings) { if (settings.SingleInstance && m_activeClips.Count > 0) { // Search the list for the matching audio clip for (int i = 0; i < m_activeClips.Count; i++) { if (m_activeClips[i].clip.GetInstanceID() == clip.GetInstanceID()) { // Found and overlap period not over yet // End the function and skip the audio clip if (m_activeClips[i].time < settings.OverlapThreshold && m_activeClips[i].isPlaying) { return null; } // Found and overlap is over else { m_activeClips.RemoveAt(i); break; } } } } // Retrieve unused audio source from pool GameObject newSound = m_AudioSources.New(pos); var cb = newSound.GetComponent<CustomBehaviour>(); var audSrc = cb.GetAudioSource; // Randomization float randomPitch = UnityEngine.Random.Range(settings.MinPitch, settings.MaxPitch); float randomVol = UnityEngine.Random.Range(settings.MinVolume, settings.MaxVolume); newSound.transform.position = pos; audSrc.clip = clip; audSrc.pitch = randomPitch; audSrc.volume = randomVol; audSrc.outputAudioMixerGroup = settings.MixerGroup; if (settings.SingleInstance) { m_activeClips.Add(audSrc); } newSound.SetActive(true); Timing.RunCoroutine(StoreClip(cb), Segment.SlowUpdate); return audSrc; }