标签:
1. private AudioClip SetAudio(string StrPath)
{
AudioClip clip=null;
clip = (AudioClip)Resources.Load(StrPath, typeof(AudioClip));
return clip;
}
这个是加载声音的 注意这里的strpath 如果用了Resources.Load 那么就需要assets文件夹下有Resources文件夹 资源必须在Resources文件夹里面 strpath指定Resources文件夹以下的路径
2. 路径加载 用www
public static IEnumerator CoroutineLoad(string url, Action<WWW> action = null) //url=Global.LOCAL_RES_URL + "card/" + cardBase.cardID + ".png" Global.LOCAL_RES_URL="file://" + Application.dataPath + "/Cache/";
{
WWW www = new WWW(url);
float time_start = Time.time;
_retry_times = 0;
while (!www.isDone)
{
if (Time.time - time_start > RETRY_LAG)
{
if (_retry_times == 0)
{
_download_progress = www.progress;
GameLog.LogError("[DOWNLOAD]first retry: " + url + ", progress: " + _download_progress);
time_start = Time.time;
_retry_times ++;
continue;
}
if (_download_progress == www.progress)
{
if (_retry_times > 1)
{
GameLog.LogError("[DOWNLOAD]download failed: " + url + ", progress: " + _download_progress);
www.Dispose();
yield break;
}
www.InitWWW(url, null, null);
time_start = Time.time;
_retry_times ++;
continue;
}
_retry_times = 0;
}
yield return null;
}
//yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Download.hasError = true;
GameLog.LogError(www.error);
}
if (action != null) action(www);
www.Dispose(); 这个很重要 忘写了 流就会不关闭 这样虚拟机跑不起来
}
3. filePath = Application.dataPath + @"/_Image/grid.png";
标签:
原文地址:http://www.cnblogs.com/mengdi520123/p/4537824.html