实现 UILoadingComponent 并实现该组件的事件系统:
UILoading 组件
- public class UILoadingComponent : Component
- {
- public Text text;
- }
UILoading 事件系统:
- [ObjectSystem]
- public class UiLoadingComponentAwakeSystem : AwakeSystem<UILoadingComponent>
- {
- public override void Awake(UILoadingComponent self)
- {
- self.text = self.GetParent<UI>().GameObject.Get<GameObject>("Text").GetComponent<Text>();
- }
- }
- [ObjectSystem]
- public class UiLoadingComponentStartSystem : StartSystem<UILoadingComponent>
- {
- public override void Start(UILoadingComponent self)
- {
- StartAsync(self).Coroutine();
- }
- public async ETVoid StartAsync(UILoadingComponent self)
- {
- TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
- long instanceId = self.InstanceId;
- while (true)
- {
- await timerComponent.WaitAsync(1000);
- if (self.InstanceId != instanceId)
- {
- return;
- }
- BundleDownloaderComponent bundleDownloaderComponent = Game.Scene.GetComponent<BundleDownloaderComponent>();
- if (bundleDownloaderComponent == null)
- {
- continue;
- }
- self.text.text = $"{bundleDownloaderComponent.Progress}%";
- }
- }
- }
事件类的定义: 1. 添加 [ObjectSystem] 标志 2. 继承自对应的 XxxSystem 类, 并实现基类的虚方法 - 事件类与 Unity 中含义类似, 请自行参阅源码学习
来源: https://www.cnblogs.com/raymondking123/p/11369623.html