LoopScrollPrefabSource.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using ET;
  5. namespace UnityEngine.UI
  6. {
  7. public interface LoopScrollPrefabAsyncSource
  8. {
  9. ETTask<GameObject> GetObject(int index);
  10. void ReturnObject(Transform trans);
  11. }
  12. public interface IYIUILoopScrollPrefabAsyncSource
  13. {
  14. }
  15. public interface IYIUILoopScrollPrefabAsyncSourceSystem : ISystemType
  16. {
  17. ETTask<GameObject> GetObject(Entity self, int index);
  18. void ReturnObject(Entity self, Transform trans);
  19. }
  20. [EntitySystem]
  21. public abstract class YIUILoopScrollPrefabAsyncSourceSystem<T> : SystemObject, IYIUILoopScrollPrefabAsyncSourceSystem
  22. where T : Entity, IYIUILoopScrollPrefabAsyncSource
  23. {
  24. Type ISystemType.Type()
  25. {
  26. return typeof(T);
  27. }
  28. Type ISystemType.SystemType()
  29. {
  30. return typeof(IYIUILoopScrollPrefabAsyncSourceSystem);
  31. }
  32. async ETTask<GameObject> IYIUILoopScrollPrefabAsyncSourceSystem.GetObject(Entity self, int index)
  33. {
  34. return await GetObject((T)self, index);
  35. }
  36. void IYIUILoopScrollPrefabAsyncSourceSystem.ReturnObject(Entity self, Transform trans)
  37. {
  38. ReturnObject((T)self, trans);
  39. }
  40. protected abstract ETTask<GameObject> GetObject(T self, int index);
  41. protected abstract void ReturnObject(T self, Transform trans);
  42. }
  43. public static class LoopScrollPrefabAsyncSourceExtensions
  44. {
  45. public static async ETTask<GameObject> GetObject(this IYIUILoopScrollPrefabAsyncSource source, int index)
  46. {
  47. var iEventSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(source.GetType(), typeof(IYIUILoopScrollPrefabAsyncSourceSystem));
  48. if (iEventSystems is not { Count: 1 })
  49. {
  50. Log.Error($"类:{source.GetType()} 没有具体实现的事件 或有多个实现的事件 [{iEventSystems?.Count}] IYIUILoopScrollPrefabAsyncSourceSystem 请检查");
  51. return default;
  52. }
  53. foreach (IYIUILoopScrollPrefabAsyncSourceSystem eventSystem in iEventSystems)
  54. {
  55. try
  56. {
  57. return await eventSystem.GetObject((Entity)source, index);
  58. }
  59. catch (Exception e)
  60. {
  61. Log.Error($"类:{source.GetType()} 事件错误: {e}");
  62. return default;
  63. }
  64. }
  65. Log.Error($"类:{source.GetType()} 存在多个实现的事件 IYIUILoopScrollPrefabAsyncSourceSystem 请检查");
  66. return default;
  67. }
  68. public static void ReturnObject(this IYIUILoopScrollPrefabAsyncSource source, Transform trans)
  69. {
  70. var iEventSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(source.GetType(), typeof(IYIUILoopScrollPrefabAsyncSourceSystem));
  71. if (iEventSystems is not { Count: 1 })
  72. {
  73. Log.Error($"类:{source.GetType()} 没有具体实现的事件 或有多个实现的事件 [{iEventSystems?.Count}] IYIUILoopScrollPrefabAsyncSourceSystem 请检查");
  74. return;
  75. }
  76. foreach (IYIUILoopScrollPrefabAsyncSourceSystem eventSystem in iEventSystems)
  77. {
  78. try
  79. {
  80. eventSystem.ReturnObject((Entity)source, trans);
  81. }
  82. catch (Exception e)
  83. {
  84. Log.Error($"类:{source.GetType()} 事件错误: {e}");
  85. }
  86. }
  87. }
  88. }
  89. }