Example #1
0
        /// <summary>
        /// 将文本数据反序列化成AssetManagerInfo实例。
        /// </summary>
        /// <param name="stream">读取流。</param>
        /// <returns>返回AssetManagerInfo对象。</returns>
        public static AssetManagerInfo Deserialize(Stream stream)
        {
            try {
                var binarize = Convert.ToBoolean(stream.ReadByte());
                if (binarize)
                {
                    using (var reader = new StringStreamReader(stream)) {
                        AssetManagerInfo info = new AssetManagerInfo();
                        info._Read(reader);
                        return(info);
                    }
                }
                else
                {
                    using (var reader = new StreamReader(stream)) {
                        // var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                        //return deserializer.Deserialize<AssetManagerInfo>(reader);
                        return(null);
                    }
                }
            } catch (Exception e) {
                Logger <IAssetManager> .X(e);

                return(null);
            }
        }
Example #2
0
 /// <summary>
 /// 序列化AssetManagerInfo。
 /// </summary>
 /// <param name="stream">写入流。</param>
 /// <param name="managerInfo">要序列化的AssetManagerInfo对象。</param>
 /// <param name="binarize">是否二进制化</param>
 public static void Serialize(Stream stream, AssetManagerInfo managerInfo, bool binarize)
 {
     try {
         stream.WriteByte(Convert.ToByte(binarize));
         if (binarize)
         {
             using (var writer = new StringStreamWriter(stream)) {
                 managerInfo._Write(writer);
             }
         }
         else
         {
             using (var writer = new StreamWriter(stream)) {
                 //var serializer = new Serializer(namingConvention: new CamelCaseNamingConvention());
                 // serializer.Serialize(writer, managerInfo);
             }
         }
     } catch (Exception e) {
         Logger <IAssetManager> .X(e);
     }
 }
Example #3
0
        public void UpdateAsync(Action callback)
        {
            new FileReadTask(PathUtility.ComposeDataPath(Id))
            .Start()
            .Continue(task =>
            {
                if (null != task.Result)
                {
                    using (var stream = new MemoryStream(task.Result as byte[])) {
                        this.info           = AssetManagerInfo.Deserialize(stream);
                        this.info._LoadType = AssetPackLoadType.PERSISTENTDATAPATH;
                        stream.Close();
                    }
                }

                return(new WWWLoadTask(PathUtility.ComposeAppUrl(Id)));
            })
            .Continue(task =>
            {
                if (null != task.Result)
                {
                    var w = task.Result as WWW;
                    if (null == w.error)
                    {
                        using (var stream = new MemoryStream(w.bytes)) {
                            var info         = AssetManagerInfo.Deserialize(stream);
                            info._LoadType   = AssetPackLoadType.STREAMINGASSETS;
                            var innerVersion = new Version(info.Version);
                            var outerVersion = new Version(this.info.Version);
                            if (innerVersion.Compare(outerVersion) > 0)
                            {
                                this.info = info;
                            }
                        }
                    }
                }

                return(null);
            })
            .Continue(task =>
            {
                var reloadPacks = new List <AssetPack>();
                foreach (var pair in this.packs)
                {
                    var pack = pair.Value;
                    if (AssetPackLoadType.RESOURCES != pack.LoadType && AssetPackLoadType.REMOTE != pack.LoadType) // DO NOT reload asset in Resources
                    {
                        pack._Reset(false);                                                                        // Reset first
                        reloadPacks.Add(pack);
                    }
                }

                if (reloadPacks.Count > 0)
                {
                    var count = reloadPacks.Count;
                    for (var i = 0; i < reloadPacks.Count; ++i)
                    {
                        var pack      = reloadPacks[i];
                        pack.LoadType = this.info._LoadType; // Sync load type after _Reset
                        pack.LoadAsync((assetPack, _) =>
                        {
                            if (0 == (--count) && null != callback)
                            {
                                callback();
                            }
                        });
                    }
                }
                else if (null != callback)
                {
                    callback();
                }

                return(null);
            });
        }