BuiltinVersionListSerializer.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 System.Collections.Generic;
  8. namespace UnityGameFramework.Runtime
  9. {
  10. /// <summary>
  11. /// 内置版本资源列表序列化器。
  12. /// </summary>
  13. public static partial class BuiltinVersionListSerializer
  14. {
  15. private const string DefaultExtension = "dat";
  16. private const int CachedHashBytesLength = 4;
  17. private static readonly byte[] s_CachedHashBytes = new byte[CachedHashBytesLength];
  18. private static int AssetNameToDependencyAssetNamesComparer(KeyValuePair<string, string[]> a, KeyValuePair<string, string[]> b)
  19. {
  20. return a.Key.CompareTo(b.Key);
  21. }
  22. private static int GetAssetNameIndex(List<KeyValuePair<string, string[]>> assetNameToDependencyAssetNames, string assetName)
  23. {
  24. return GetAssetNameIndexWithBinarySearch(assetNameToDependencyAssetNames, assetName, 0, assetNameToDependencyAssetNames.Count - 1);
  25. }
  26. private static int GetAssetNameIndexWithBinarySearch(List<KeyValuePair<string, string[]>> assetNameToDependencyAssetNames, string assetName, int leftIndex, int rightIndex)
  27. {
  28. if (leftIndex > rightIndex)
  29. {
  30. return -1;
  31. }
  32. int middleIndex = (leftIndex + rightIndex) / 2;
  33. if (assetNameToDependencyAssetNames[middleIndex].Key == assetName)
  34. {
  35. return middleIndex;
  36. }
  37. if (assetNameToDependencyAssetNames[middleIndex].Key.CompareTo(assetName) > 0)
  38. {
  39. return GetAssetNameIndexWithBinarySearch(assetNameToDependencyAssetNames, assetName, leftIndex, middleIndex - 1);
  40. }
  41. else
  42. {
  43. return GetAssetNameIndexWithBinarySearch(assetNameToDependencyAssetNames, assetName, middleIndex + 1, rightIndex);
  44. }
  45. }
  46. }
  47. }