AwaitableExtensions.Starforce.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // using System;
  2. // using System.Threading.Tasks;
  3. // using GameFramework.DataTable;
  4. // using GameFramework.Event;
  5. // using UnityGameFramework.Runtime;
  6. //
  7. // namespace UGFExtensions.Await
  8. // {
  9. // public partial class AwaitableExtensions
  10. // {
  11. //
  12. // /// <summary>
  13. // /// 打开界面(可等待)
  14. // /// </summary>
  15. // public static Task<UIForm> OpenUIFormAsync(this UIComponent uiComponent, int uiFormId,
  16. // object userData = null)
  17. // {
  18. // #if UNITY_EDITOR
  19. // TipsSubscribeEvent();
  20. // #endif
  21. // int? serialId = uiComponent.OpenUIForm(uiFormId, userData);
  22. // if (serialId == null)
  23. // {
  24. // return Task.FromResult((UIForm)null);
  25. // }
  26. //
  27. // var tcs = new TaskCompletionSource<UIForm>();
  28. // s_UIFormTcs.Add(serialId.Value, tcs);
  29. // return tcs.Task;
  30. // }
  31. // /// <summary>
  32. // /// 打开界面(可等待)
  33. // /// </summary>
  34. // public static Task<UIForm> OpenUIFormAsync(this UIComponent uiComponent, UIFormId uiFormId,
  35. // object userData = null)
  36. // {
  37. // #if UNITY_EDITOR
  38. // TipsSubscribeEvent();
  39. // #endif
  40. // int? serialId = uiComponent.OpenUIForm(uiFormId, userData);
  41. // if (serialId == null)
  42. // {
  43. // return Task.FromResult((UIForm)null);
  44. // }
  45. //
  46. // var tcs = new TaskCompletionSource<UIForm>();
  47. // s_UIFormTcs.Add(serialId.Value, tcs);
  48. // return tcs.Task;
  49. // }
  50. //
  51. // /// <summary>
  52. // /// 显示实体(可等待)
  53. // /// </summary>
  54. // public static Task<Entity> ShowEntityAsync(this EntityComponent entityComponent, Type logicType,
  55. // int priority,
  56. // EntityData data)
  57. // {
  58. // #if UNITY_EDITOR
  59. // TipsSubscribeEvent();
  60. // #endif
  61. // var tcs = new TaskCompletionSource<Entity>();
  62. // s_EntityTcs.Add(data.Id, tcs);
  63. // entityComponent.ShowEntity(logicType, priority, data);
  64. // return tcs.Task;
  65. // }
  66. //
  67. // /// <summary>
  68. // /// 加载数据表(可等待)
  69. // /// </summary>
  70. // public static async Task<IDataTable<T>> LoadDataTableAsync<T>(this DataTableComponent dataTableComponent,
  71. // string dataTableName, bool formBytes, object userData = null) where T : IDataRow
  72. // {
  73. // #if UNITY_EDITOR
  74. // TipsSubscribeEvent();
  75. // #endif
  76. // IDataTable<T> dataTable = dataTableComponent.GetDataTable<T>();
  77. // if (dataTable != null)
  78. // {
  79. // return await Task.FromResult(dataTable);
  80. // }
  81. //
  82. // var loadTcs = new TaskCompletionSource<bool>();
  83. // var dataTableAssetName = AssetUtility.GetDataTableAsset(dataTableName, formBytes);
  84. // s_DataTableTcs.Add(dataTableAssetName, loadTcs);
  85. // dataTableComponent.LoadDataTable(dataTableName, dataTableAssetName, userData);
  86. // bool isLoaded = await loadTcs.Task;
  87. // dataTable = isLoaded ? dataTableComponent.GetDataTable<T>() : null;
  88. // return await Task.FromResult(dataTable);
  89. // }
  90. //
  91. //
  92. // private static void OnLoadDataTableSuccess(object sender, GameEventArgs e)
  93. // {
  94. // var ne = (LoadDataTableSuccessEventArgs)e;
  95. // s_DataTableTcs.TryGetValue(ne.DataTableAssetName, out TaskCompletionSource<bool> tcs);
  96. // if (tcs != null)
  97. // {
  98. // Log.Info("Load data table '{0}' OK.", ne.DataTableAssetName);
  99. // tcs.SetResult(true);
  100. // s_DataTableTcs.Remove(ne.DataTableAssetName);
  101. // }
  102. // }
  103. //
  104. // private static void OnLoadDataTableFailure(object sender, GameEventArgs e)
  105. // {
  106. // var ne = (LoadDataTableFailureEventArgs)e;
  107. // s_DataTableTcs.TryGetValue(ne.DataTableAssetName, out TaskCompletionSource<bool> tcs);
  108. // if (tcs != null)
  109. // {
  110. // Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", ne.DataTableAssetName,
  111. // ne.DataTableAssetName, ne.ErrorMessage);
  112. // tcs.SetResult(false);
  113. // s_DataTableTcs.Remove(ne.DataTableAssetName);
  114. // }
  115. // }
  116. // }
  117. // }