UnityWebRequestDownloadAgentHelper.DownloadHandler.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Download;
  9. using System;
  10. #if UNITY_5_4_OR_NEWER
  11. using UnityEngine.Networking;
  12. #else
  13. using UnityEngine.Experimental.Networking;
  14. #endif
  15. namespace UnityGameFramework.Runtime
  16. {
  17. public partial class UnityWebRequestDownloadAgentHelper : DownloadAgentHelperBase, IDisposable
  18. {
  19. private sealed class DownloadHandler : DownloadHandlerScript
  20. {
  21. private readonly UnityWebRequestDownloadAgentHelper m_Owner;
  22. public DownloadHandler(UnityWebRequestDownloadAgentHelper owner)
  23. : base(owner.m_CachedBytes)
  24. {
  25. m_Owner = owner;
  26. }
  27. protected override bool ReceiveData(byte[] data, int dataLength)
  28. {
  29. if (m_Owner != null && m_Owner.m_UnityWebRequest != null && dataLength > 0)
  30. {
  31. DownloadAgentHelperUpdateBytesEventArgs downloadAgentHelperUpdateBytesEventArgs = DownloadAgentHelperUpdateBytesEventArgs.Create(data, 0, dataLength);
  32. m_Owner.m_DownloadAgentHelperUpdateBytesEventHandler(this, downloadAgentHelperUpdateBytesEventArgs);
  33. ReferencePool.Release(downloadAgentHelperUpdateBytesEventArgs);
  34. DownloadAgentHelperUpdateLengthEventArgs downloadAgentHelperUpdateLengthEventArgs = DownloadAgentHelperUpdateLengthEventArgs.Create(dataLength);
  35. m_Owner.m_DownloadAgentHelperUpdateLengthEventHandler(this, downloadAgentHelperUpdateLengthEventArgs);
  36. ReferencePool.Release(downloadAgentHelperUpdateLengthEventArgs);
  37. }
  38. return base.ReceiveData(data, dataLength);
  39. }
  40. }
  41. }
  42. }