/// <summary> /// 设置目标图片 从 cache中找 -> 用initSprite 赋值 -> 从Assetbundle中找 —> 从url下载 /// </summary> /// <param name="picName"></param> /// <param name="resourcePath"></param> /// <param name="url"></param> /// <param name="nativeSize"></param> /// <param name="initSprite"></param> /// <param name="onCompleteListener"></param> /// <returns></returns> public bool SetTargetPic( string picName, string resourcePath, string url = null, bool nativeSize = false, Sprite initSprite = null, OnComplete onCompleteListener = null) { PicName = picName; ResourcePath = resourcePath; NativeSize = nativeSize; _onCompleteListener = onCompleteListener; LastCheckTime = 0; if (!ContentImage) { // 如果没有内容图片,则直接切换到完成状态。 SwitchToStatus(StatusComplete); return(true); } //先从Cache中取图片 var sprite = _resourceCache.LoadSpriteFromCache(PicName); if (sprite) { ContentImage.sprite = sprite; if (nativeSize) { ContentImage.SetNativeSize(); } SwitchToStatus(StatusComplete); return(true); } if (initSprite != null) { if (ContentImage) { ContentImage.sprite = initSprite; if (nativeSize) { ContentImage.SetNativeSize(); } if (!ContentImage.gameObject.activeSelf) { ContentImage.gameObject.SetActive(true); } } if (WaitingImage && WaitingImage.gameObject.activeSelf) { WaitingImage.gameObject.SetActive(false); } SwitchToStatus(StatusComplete); return(true); } SwitchToStatus(StatusChecking, initSprite != null); if (!string.IsNullOrEmpty(ResourcePath)) { _downLoadByUrl = false; _resource.StartLoadResource(ResourcePath, PicName); } else { if (!string.IsNullOrEmpty(url)) { _downLoadByUrl = true; if (!_resourceCache.ContainsDownloadTask(picName)) { _resourceCache.StartDownload(picName, url, ContentType.Image); } } } return(false); }