/// <summary> /// Gets the cache path. /// </summary> /// <returns>The cache path.</returns> /// <param name="category">Category.</param> public static string GetCachePath(CacheFileCategories category) { string path = ""; switch (category) { case CacheFileCategories.Icon: path = iconPath; break; case CacheFileCategories.Image: path = imagePath; break; case CacheFileCategories.Thumbnail: path = thumbnailPath; break; case CacheFileCategories.Voice: path = audioPath; break; case CacheFileCategories.Video: path = videoPath; break; } return(path); }
public Sprite GetSprite(CacheFileCategories category, string fileName, bool isFixedPath) { Sprite s; Texture2D tex; string path = isFixedPath ? "" : File.GetCachePath(category); return(GetSprite(fileName, true)); }
public IEnumerator SetIconOrImage(UnityEngine.UI.Image setToImage, string imageKeyOrURL, string savePath, string fileName, CacheFileCategories category, Action <bool, ContentUsedFrom> onDone) { ContentUsedFrom kind = ContentUsedFrom.None; bool isDisplay = false; Sprite tempSprite = null; if (null != setToImage) { if (string.IsNullOrEmpty(imageKeyOrURL)) { setToImage.sprite = null; setToImage.color = setToImage.color.SetChannelA(0f); setToImage.gameObject.SetActive(false); kind = ContentUsedFrom.None; } else { if (imageKeyOrURL.IsURL()) { string saveFileName = fileName.IsNulOrEmpty() ? File.GetFileNameFromURL(imageKeyOrURL) : fileName; string path = !category.Equals(CacheFileCategories.None) ? File.GetCachePath(category) : savePath; bool isFixedPath = category.Equals(CacheFileCategories.None); bool spriteAvailable = System.IO.File.Exists(savePath + saveFileName); if (spriteAvailable) { kind = ContentUsedFrom.DownloadCache; tempSprite = isFixedPath ? GetSprite(category, savePath + saveFileName, isFixedPath) : GetSprite(category, saveFileName); isDisplay = null != tempSprite; if (onDone != null) { onDone(isDisplay, kind); } } //if(null == tempSprite) { if (null != DownloaderUtility.Me) { yield return(StartCoroutine(DownloaderUtility.Me.DownloadImage(imageKeyOrURL, path, saveFileName, true, null))); } spriteAvailable = System.IO.File.Exists(savePath + saveFileName); if (spriteAvailable) { tempSprite = isFixedPath ? GetSprite(category, savePath + saveFileName, isFixedPath) : GetSprite(category, saveFileName); kind = ContentUsedFrom.DownloadFromServer; } else { tempSprite = null; } //} } else { kind = ContentUsedFrom.UnityCache; tempSprite = SubsetManager.Me.GetIcon(imageKeyOrURL); } //setToImage.gameObject.SetActive((tempSprite != null)); //MyDebug.Log("Sprite is available? => {0}", (tempSprite != null)); if (tempSprite != null) { setToImage.sprite = tempSprite; setToImage.color = setToImage.color.SetChannelA(1f); } //else { // setToImage.sprite = null; // setToImage.color = setToImage.color.SetChannelA(0f); //} } } isDisplay = null != tempSprite; if (onDone != null) { onDone(isDisplay, kind); } }
public IEnumerator SetIconOrImage(UnityEngine.UI.Image setToImage, string url, string savePath, CacheFileCategories category) { yield return(StartCoroutine(SetIconOrImage(setToImage, url, savePath, string.Empty, category, null))); }
public Sprite GetSprite(CacheFileCategories category, string fileName) { return(GetSprite(category, fileName, false)); }