public IEnumerator DoSave()
        {
            var data = m_request.downloadHandler.data;
            var hash = data.GetMD5(false, 0, (int)m_request.downloadedBytes);
            var fs   = File.Create(m_path, (int)m_request.downloadedBytes);

            fs.BeginWrite(data, 0, (int)m_request.downloadedBytes, OnSave, fs);

            yield return(new WaitUntil(isDone));

            data = null;

            if ((!Level.loading || AssetManager.enableLoadingLog) && AssetManager.enableLog)
            {
                Logger.LogDetail("AssetManager: File saved to {0}", m_path);
            }

            HashListFile.ReplaceHashListFile(AssetManager.hashFileName, Path.GetFileName(m_path), hash);

            yield return(new WaitUntil(canDispose));

            m_request.Dispose();
            m_request = null;

            //Logger.LogDetail("AssetManager: Web request handler disposed! File: {0}", m_path);
        }
Beispiel #2
0
    /// <summary>
    /// 设置头像 avatar 到目标对象
    /// 目标对象应当是一个 UI 元素
    /// 注意:如果头像加载失败并且未指定性别,头像将显示空白
    /// </summary>
    /// <param name="o">要显示头像的目标对象</param>
    /// <param name="avatar">头像</param>
    /// <param name="useNativeSize">是否使用原始头像大小</param>
    /// <param name="gender">性别 可选,主要用于头像加载失败时确定男性还是女性默认头像</param>
    public static void SetAvatar(GameObject o, string avatar, bool useNativeSize = false, int gender = -1)
    {
        if (!o)
        {
            return;
        }

        if (string.IsNullOrEmpty(avatar))
        {
            var dt = gender < 0 ? null : gender == 0 ? defaultFemale : defaultMale;
            AtlasHelper.SetAvatar(o, dt);
            return;
        }

        var cached = m_cachedAvatars.Get(avatar);

        if (cached)
        {
            UIDynamicImage.LoadImageCreated(o, avatar, cached, useNativeSize);
            return;
        }

        var fp = LocalFilePath.AVATAR + "/" + avatar + ".avatar";

        cached = Util.LoadImage(fp);
        if (cached)
        {
            m_cachedAvatars.Set(avatar, cached);
            UIDynamicImage.LoadImageCreated(o, avatar, cached, useNativeSize);
            return;
        }

        var url = URLs.avatar + avatar + ".png";

        UIDynamicImage.LoadImage(o, url, (di, t) =>
        {
            if (!t)
            {
                if (di && gender > -1)
                {
                    AtlasHelper.SetAvatar(di.gameObject, gender == 0 ? defaultFemale : defaultMale);
                }
                return;
            }
            m_cachedAvatars.Set(avatar, t);

            var data = UIDynamicImage.RemoveCache(url, false);

            if (data != null)
            {
                var hash = data.GetMD5();
                if ((fp = Util.SaveFile(fp, data)) != null)
                {
                    HashListFile.ReplaceHashListFile(hashFileName, avatar, hash);
                }
            }
        }, useNativeSize);
    }