RawFileHandle.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 
  2. namespace YooAsset
  3. {
  4. public class RawFileHandle : HandleBase
  5. {
  6. private System.Action<RawFileHandle> _callback;
  7. internal RawFileHandle(ProviderOperation provider) : base(provider)
  8. {
  9. }
  10. internal override void InvokeCallback()
  11. {
  12. _callback?.Invoke(this);
  13. }
  14. /// <summary>
  15. /// 完成委托
  16. /// </summary>
  17. public event System.Action<RawFileHandle> Completed
  18. {
  19. add
  20. {
  21. if (IsValidWithWarning == false)
  22. throw new System.Exception($"{nameof(RawFileHandle)} is invalid");
  23. if (Provider.IsDone)
  24. value.Invoke(this);
  25. else
  26. _callback += value;
  27. }
  28. remove
  29. {
  30. if (IsValidWithWarning == false)
  31. throw new System.Exception($"{nameof(RawFileHandle)} is invalid");
  32. _callback -= value;
  33. }
  34. }
  35. /// <summary>
  36. /// 等待异步执行完毕
  37. /// </summary>
  38. public void WaitForAsyncComplete()
  39. {
  40. if (IsValidWithWarning == false)
  41. return;
  42. Provider.WaitForAsyncComplete();
  43. }
  44. /// <summary>
  45. /// 获取原生文件的二进制数据
  46. /// </summary>
  47. public byte[] GetRawFileData()
  48. {
  49. if (IsValidWithWarning == false)
  50. return null;
  51. return Provider.BundleResultObject.ReadBundleFileData();
  52. }
  53. /// <summary>
  54. /// 获取原生文件的文本数据
  55. /// </summary>
  56. public string GetRawFileText()
  57. {
  58. if (IsValidWithWarning == false)
  59. return null;
  60. return Provider.BundleResultObject.ReadBundleFileText();
  61. }
  62. /// <summary>
  63. /// 获取原生文件的路径
  64. /// </summary>
  65. public string GetRawFilePath()
  66. {
  67. if (IsValidWithWarning == false)
  68. return string.Empty;
  69. return Provider.BundleResultObject.GetBundleFilePath();
  70. }
  71. }
  72. }