static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction <float> uaing, UnityAction <float> uaend, ThreadPriority threadPriority) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } bc.LoadState = LoadState.LoadIng; bc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(bc.SourceUrl); www.threadPriority = threadPriority; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return(null); } float o1 = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 bc.LoadError = www.error; if (www.error != null) { bc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { bc.Size = www.size; bc.Bundle = www.assetBundle; bc.LoadState = LoadState.LoadComplete; } bc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
/// <summary> /// 加载模型或场景文件 /// </summary> /// <param name="bc">模型或场景文件内容</param> /// <param name="mb">MonoBehaviour</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> /// <param name="threadPriority">优先级别</param> public static void LoadBundle(WwwBundle bc, MonoBehaviour mb, UnityAction <float> uaing, UnityAction <float> uaend, ThreadPriority threadPriority) { mb.StartCoroutine(InvokeLoadbundle(bc, uaing, uaend, threadPriority)); }
/// <summary> /// 加载模型或场景文件 /// </summary> /// <param name="bc">模型或场景文件内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadBundle(WwwBundle bc, UnityAction <float> uaing, UnityAction <float> uaend) { LoadBundle(bc, MonoBehaviourAnysc.AnyscMonoBehaviour, uaing, uaend, ThreadPriority.Normal); }
/// <summary> /// 加载模型或场景文件 /// </summary> /// <param name="bc">模型或场景文件内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadBundle(WwwBundle bc, UnityAction<float> uaing, UnityAction<float> uaend) { LoadBundle(bc, MonoBehaviourAnysc.AnyscMonoBehaviour, uaing, uaend, ThreadPriority.Normal); }
static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction<float> uaing, UnityAction<float> uaend, ThreadPriority threadPriority) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); bc.LoadState = LoadState.LoadIng; bc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(bc.SourceUrl); www.threadPriority = threadPriority; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return null; } float o1 = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 bc.LoadError = www.error; if (www.error != null) { bc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { bc.Size = www.size; bc.Bundle = www.assetBundle; bc.LoadState = LoadState.LoadComplete; } bc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
/// <summary> /// 加载模型或场景文件 /// </summary> /// <param name="bc">模型或场景文件内容</param> /// <param name="mb">MonoBehaviour</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> /// <param name="threadPriority">优先级别</param> public static void LoadBundle(WwwBundle bc, MonoBehaviour mb, UnityAction<float> uaing, UnityAction<float> uaend, ThreadPriority threadPriority) { mb.StartCoroutine(InvokeLoadbundle(bc, uaing, uaend, threadPriority)); }