1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using GameFramework;
- using GameFramework.Resource;
- using System;
- using System.IO;
- using System.Text;
- namespace UnityGameFramework.Runtime
- {
- /// <summary>
- /// 内置版本资源列表序列化器。
- /// </summary>
- public static partial class BuiltinVersionListSerializer
- {
- #if UNITY_EDITOR
- /// <summary>
- /// 序列化资源包版本资源列表(版本 0)回调函数。
- /// </summary>
- /// <param name="stream">目标流。</param>
- /// <param name="versionList">要序列化的资源包版本资源列表(版本 0)。</param>
- /// <returns>是否序列化资源包版本资源列表(版本 0)成功。</returns>
- public static bool ResourcePackVersionListSerializeCallback_V0(Stream stream, ResourcePackVersionList versionList)
- {
- if (!versionList.IsValid)
- {
- return false;
- }
- Utility.Random.GetRandomBytes(s_CachedHashBytes);
- using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8))
- {
- binaryWriter.Write(s_CachedHashBytes);
- binaryWriter.Write(versionList.Offset);
- binaryWriter.Write(versionList.Length);
- binaryWriter.Write(versionList.HashCode);
- ResourcePackVersionList.Resource[] resources = versionList.GetResources();
- binaryWriter.Write7BitEncodedInt32(resources.Length);
- foreach (ResourcePackVersionList.Resource resource in resources)
- {
- binaryWriter.WriteEncryptedString(resource.Name, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Variant, s_CachedHashBytes);
- binaryWriter.WriteEncryptedString(resource.Extension != DefaultExtension ? resource.Extension : null, s_CachedHashBytes);
- binaryWriter.Write(resource.LoadType);
- binaryWriter.Write7BitEncodedInt64(resource.Offset);
- binaryWriter.Write7BitEncodedInt32(resource.Length);
- binaryWriter.Write(resource.HashCode);
- binaryWriter.Write7BitEncodedInt32(resource.CompressedLength);
- binaryWriter.Write(resource.CompressedHashCode);
- }
- }
- Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength);
- return true;
- }
- #endif
- }
- }
|