BuiltinVersionListSerializer.ResourcePackVersionListSerializeCallback.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using GameFramework.Resource;
  9. using System;
  10. using System.IO;
  11. using System.Text;
  12. namespace UnityGameFramework.Runtime
  13. {
  14. /// <summary>
  15. /// 内置版本资源列表序列化器。
  16. /// </summary>
  17. public static partial class BuiltinVersionListSerializer
  18. {
  19. #if UNITY_EDITOR
  20. /// <summary>
  21. /// 序列化资源包版本资源列表(版本 0)回调函数。
  22. /// </summary>
  23. /// <param name="stream">目标流。</param>
  24. /// <param name="versionList">要序列化的资源包版本资源列表(版本 0)。</param>
  25. /// <returns>是否序列化资源包版本资源列表(版本 0)成功。</returns>
  26. public static bool ResourcePackVersionListSerializeCallback_V0(Stream stream, ResourcePackVersionList versionList)
  27. {
  28. if (!versionList.IsValid)
  29. {
  30. return false;
  31. }
  32. Utility.Random.GetRandomBytes(s_CachedHashBytes);
  33. using (BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.UTF8))
  34. {
  35. binaryWriter.Write(s_CachedHashBytes);
  36. binaryWriter.Write(versionList.Offset);
  37. binaryWriter.Write(versionList.Length);
  38. binaryWriter.Write(versionList.HashCode);
  39. ResourcePackVersionList.Resource[] resources = versionList.GetResources();
  40. binaryWriter.Write7BitEncodedInt32(resources.Length);
  41. foreach (ResourcePackVersionList.Resource resource in resources)
  42. {
  43. binaryWriter.WriteEncryptedString(resource.Name, s_CachedHashBytes);
  44. binaryWriter.WriteEncryptedString(resource.Variant, s_CachedHashBytes);
  45. binaryWriter.WriteEncryptedString(resource.Extension != DefaultExtension ? resource.Extension : null, s_CachedHashBytes);
  46. binaryWriter.Write(resource.LoadType);
  47. binaryWriter.Write7BitEncodedInt64(resource.Offset);
  48. binaryWriter.Write7BitEncodedInt32(resource.Length);
  49. binaryWriter.Write(resource.HashCode);
  50. binaryWriter.Write7BitEncodedInt32(resource.CompressedLength);
  51. binaryWriter.Write(resource.CompressedHashCode);
  52. }
  53. }
  54. Array.Clear(s_CachedHashBytes, 0, CachedHashBytesLength);
  55. return true;
  56. }
  57. #endif
  58. }
  59. }