Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnityDownloadHandler.cs 1.6KB

Svelto.ECS 2.9 changes (random order of importance): New Serialization framework more thorough disposing of the EnginesRoot an EnginesRoot reference should never be held, unless it’s a weak reference. The code changed to stick to this rule IReactOnAddAndRemove callbacks are now guaranteed to be called after all the entity structs generated by the same entity have been added and before any is removed. both functions pass the EGID of the analysing entity by parameter now, so that the entity struct won’t need to implement INeedEGID for this sole purpose. The IReactOnSwap MovedFrom method has been removed, it is now redundant. Entities built or removed during the IReactOnAddAndRemove callbacks are now added and removed immediately and not on the next submission like used to happen. This avoid some awkward checks that were previously needed inside engines. EntityStreams can get (optionally) the EGID of the entity published, so that the EntityStruct won’t need an INeedEGID for this sole purpose. Groups are not trimmed anymore when they are emptied to avoid allocations. Removed a bunch of run-time allocations that weren’t supposed to happen in Release and/or when the Profile define is used in editor (for debugging reasons Svelto.ECS may need to use strings at run-time, but Svelto.ECS is allocation zero in Release and when the Profile keyword is used) A improved the DynamicEntityDescriptor and ExtendibleEntityDescriptor code and more notably, introduced the new method ExtendedWith<> to facilitate the writing of modular and reusable entity descriptors. Several minor code design improvements/optimisations
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using UnityEngine.Networking;
  5. namespace Svelto.Services
  6. {
  7. public class UnityDownloadHandler : DownloadHandlerScript
  8. {
  9. public string GetError()
  10. {
  11. if (String.IsNullOrEmpty(_errorString) == true)
  12. {
  13. MemoryStream errorBuffer = new MemoryStream(_dataLength);
  14. errorBuffer.Write(data, 0, _dataLength);
  15. _errorString = Encoding.UTF8.GetString(errorBuffer.GetBuffer(), 0, (int) errorBuffer.Length);
  16. errorBuffer.Dispose();
  17. }
  18. return _errorString;
  19. }
  20. protected override bool ReceiveData(byte[] data, int dataLength)
  21. {
  22. if (data.Length < 1)
  23. return false; // No need to receive data
  24. _data = data;
  25. _dataLength = dataLength;
  26. if (_handler == null)
  27. return false; // No need to receive data
  28. return _handler.ReceiveData(data, dataLength);
  29. }
  30. public UnityDownloadHandler(IResponseHandler handler)
  31. {
  32. _handler = handler;
  33. }
  34. protected override byte[] GetData()
  35. {
  36. return _data;
  37. }
  38. // Called when all data has been received from the server and delivered via ReceiveData.
  39. protected override void CompleteContent()
  40. {
  41. _handler?.CompleteContent();
  42. }
  43. readonly IResponseHandler _handler;
  44. byte[] _data;
  45. int _dataLength;
  46. string _errorString;
  47. }
  48. }