当前位置: 首页>>代码示例>>C#>>正文


C# WWW.GetAudioClipCompressed方法代码示例

本文整理汇总了C#中UnityEngine.WWW.GetAudioClipCompressed方法的典型用法代码示例。如果您正苦于以下问题:C# WWW.GetAudioClipCompressed方法的具体用法?C# WWW.GetAudioClipCompressed怎么用?C# WWW.GetAudioClipCompressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.WWW的用法示例。


在下文中一共展示了WWW.GetAudioClipCompressed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: soundHelper

	IEnumerator soundHelper(searchResult sr,bool download)
	{
		//first check to make sure it wasnt already downloaded/cached
		if (!cacheSounds.ContainsKey (sr.id)) {
			Dictionary <string,string> headers = new Dictionary<string, string> ();
			headers.Add ("Authorization", "Bearer " + gv.accessToken);
			string wholeUrl = "https://www.freesound.org/apiv2/sounds/" + sr.id + "/download/";
			WWW www = new WWW (wholeUrl, null, headers);
			Debug.Log ("Loading " + www.url);
			//yield return www;

			while (!www.isDone) {
				progressTrack.text = "downloaded " + (www.progress * 100).ToString () + "%...";
				yield return null;
			}
			progressTrack.text = "";

			if (www.error == null)
				Debug.Log ("done");
			else
				Debug.Log (www.error);
			//AudioClip loadedClip = www.GetAudioClip(false,false,AudioType.WAV);
			playSource.clip = www.GetAudioClipCompressed (false, AudioType.WAV);
			playSource.clip.name = sr.name;//will change to name at some point
			cacheSounds.Add (sr.id, playSource.clip);

			//create a directory if there isnt one
			if (!System.IO.Directory.Exists (Application.persistentDataPath + "/Downloads"))//change to persistent?
				System.IO.Directory.CreateDirectory (Application.persistentDataPath + "/Downloads");//change to persistent

			string fullPath = Application.persistentDataPath + "/Downloads/" + playSource.clip.name + ".wav";//just testing, need to change to persistent
			File.WriteAllBytes (fullPath, www.bytes);

			//delete when navigated away from this page
			if (!download) {
				playSource.Play ();
				deleteList.Add (playSource.clip.name);
			} else {
				gv.gameObject.GetComponent<soundBank> ().addedSounds.Add (playSource.clip.name + ".wav");
			}




		}
		//sound has been cached
		else {
			AudioClip tempClip;
			cacheSounds.TryGetValue (sr.name, out tempClip);
			playSource.clip = tempClip;
			playSource.Play ();
		}

		//maybe some sort of cache system, to avoid downloading again?
		//check to make sure it has not already been downloaded


	}
开发者ID:englandjf,项目名称:musicProject,代码行数:58,代码来源:importScript.cs


注:本文中的UnityEngine.WWW.GetAudioClipCompressed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。