// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { Debug.LogInfor("Time=" + Time.realtimeSinceStartup + "Frame=" + EventCenter.Instance.CurFrameCount); SpriteLoader loader = SpriteLoader.LoadAsset(m_Image.transform, m_Url, m_LoadAssetModel, OnComplete); } if (Input.GetKeyDown(KeyCode.B)) { if (m_LoadAssetModel == LoadAssetModel.Async) { ResourcesMgr.Instance.LoadSpriteAsync(m_Url, m_Image, (result) => { m_Image.sprite = result; }); } else { ResourcesMgr.Instance.LoadSpriteSync(m_Url, m_Image); } } }
/// <summary> /// 加载已经打成Prefab的预制体的资源的Sprite 精灵 /// </summary> /// <param name="targetImag"></param> /// <param name="url"></param> /// <param name="callback"></param> private void LoadSprite(string url, UnityEngine.UI.Image targetImag, LoadAssetModel loadModel, System.Action <Sprite> callback) { SpriteLoader.LoadAsset(targetImag.transform, url, loadModel, (loader) => { #region 加载成功后的处理逻辑 ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); if (loader == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("LoadSprite Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 targetImag.sprite = loader.ResultObj as Sprite; if (callback != null) { callback.Invoke(targetImag.sprite); } #endregion }); }