【ET8】2.ET8入门-ET框架解析

news/2025/3/21 2:03:29/

菜单栏相关:ENABLE_DLL选项

ET->ChangeDefine->ADD_ENABLE_DLL/REMOVE_ENABLE_DLL

一般在开发阶段使用Editor时需要关闭ENABLE_DLL选项。该选项关闭时,修改脚本之后,会直接重新编译所有的代码,Editor在运行时会直接使用最新的程序集。如果ENABLE_DLL选项是开启的,框架启动后会加载之前生成的程序集文件(这个文件需要在ET->BuildTool界面生成),导致每次需要应用修改,都要重新生成程序集文件。

框架解析

框架入口解析

启动流程如下

入口文件为Init,之后调用CodeLoader对代码进行加载
如果不是EnableDll模式则直接加载程序集。否则通过AB加载文件,之后调用LoadHotfix函数
LoadHotfix会加载程序集,并且调用EventSystem,根据特性注册对应事件的监听。
之后调用ET.Entry的Start方法。
ET.Entry.Start 进行初始化之后,调用FiberManager.Instance.Create

调用FiberInit事件,推送对应的EntryEvent事件
推送EntryEvent3,EntryEvent3_InitClient接收后推送AppStartInitFinish
AppStartInitFinish_CreateLoginUI接收该事件后,创建UI场景


UI系统

UI界面的生成流程

ET是通过异步方式创建UI,如下方例子,调用UIHelper.Create方法,指定创建UI的场景,UI类型和对应的层级

        protected override async ETTask Run(Scene scene, EventType.AppStartInitFinish args){await UIHelper.Create(scene, UIType.UILogin, UILayer.Mid);}

调用scene挂载的UIComponent组件,处理Create事件

        public static async ETTask<UI> Create(Scene scene, string uiType, UILayer uiLayer){return await scene.GetComponent<UIComponent>().Create(uiType, uiLayer);}

之后会标记有对应UIEvent特性的类,处理该事件,开始加载资源并生成对应的GameObject

    [UIEvent(UIType.UILogin)]public class UILoginEvent: AUIEvent{public override async ETTask<UI> OnCreate(UIComponent uiComponent, UILayer uiLayer){await uiComponent.DomainScene().GetComponent<ResourcesLoaderComponent>().LoadAsync(UIType.UILogin.StringToAB());GameObject bundleGameObject = (GameObject) ResourcesComponent.Instance.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject, UIEventComponent.Instance.GetLayer((int)uiLayer));UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UILogin, gameObject);ui.AddComponent<UILoginComponent>();return ui;}public override void OnRemove(UIComponent uiComponent){ResourcesComponent.Instance.UnloadBundle(UIType.UILogin.StringToAB());}}

UI组件解析

以UILogin为例子,对应的Prefab实际上只挂载了ReferenceCollector,ReferenceCollector负责将结点进行绑定

生成该GameObject之后,调用AddComponent

    [UIEvent(UIType.UILogin)]public class UILoginEvent: AUIEvent{public override async ETTask<UI> OnCreate(UIComponent uiComponent, UILayer uiLayer){string assetsName = $"Assets/Bundles/UI/Demo/{UIType.UILogin}.prefab";GameObject bundleGameObject = await uiComponent.Scene().GetComponent<ResourcesLoaderComponent>().LoadAssetAsync<GameObject>(assetsName);GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject, uiComponent.UIGlobalComponent.GetLayer((int)uiLayer));UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UILogin, gameObject);ui.AddComponent<UILoginComponent>();return ui;}public override void OnRemove(UIComponent uiComponent){}}

其中UILoginComponent负责显示对应成员

[ComponentOf(typeof(UI))]
public class UILoginComponent: Entity, IAwake
{public GameObject account;public GameObject password;public GameObject loginBtn;
}

AddComponent之后,会调用对应的System,这里UILoginComponentSystem就是对应的System,在Awake阶段通过ReferenceCollector对UILoginComponent进行了绑定,以及实现了对应的UI逻辑

[ObjectSystem]
public class UILoginComponentAwakeSystem : AwakeSystem<UILoginComponent>
{protected override void Awake(UILoginComponent self){ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();self.loginBtn = rc.Get<GameObject>("LoginBtn");self.loginBtn.GetComponent<Button>().onClick.AddListener(()=> { self.OnLogin(); });self.account = rc.Get<GameObject>("Account");self.password = rc.Get<GameObject>("Password");}
}

场景切换

关于ET的场景切换相关逻辑可以查看

UILobbyComponentSystem处理进入Map的操作,先是调用EnterMap异步函数,等待EnterMapHelper异步返回后删除界面

        //UILobbyComponentSystempublic static async ETTask EnterMap(this UILobbyComponent self){await EnterMapHelper.EnterMapAsync(self.ClientScene());await UIHelper.Remove(self.ClientScene(), UIType.UILobby);}

之后EnterMapHelper会向服务器发起进入Map的请求

        //EnterMapHelperpublic static async ETTask EnterMapAsync(Scene clientScene){try{G2C_EnterMap g2CEnterMap = await clientScene.GetComponent<SessionComponent>().Session.Call(new C2G_EnterMap()) as G2C_EnterMap;clientScene.GetComponent<PlayerComponent>().MyId = g2CEnterMap.MyId;// 等待场景切换完成await clientScene.GetComponent<ObjectWait>().Wait<Wait_SceneChangeFinish>();EventSystem.Instance.Publish(clientScene, new EventType.EnterMapFinish());}catch (Exception e){Log.Error(e);}       }


 


http://www.ppmy.cn/news/1268118.html

相关文章

springboot 极简案例

安装idea File -> New Project 选择依赖 创建controller文件 输入controller类名 输入代码 运行项目 访问 localhost:8080/hello/boot package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.…

Swagger PHP Thinkphp 接口文档

安装 1. 安装依赖 composer require zircote/swagger-php 2. 下载Swagger UI git clone https://github.com/swagger-api/swagger-ui.git 3. 复制下载好的Swagger UI 中的dist目录到public目录中&#xff0c;修改目录名称 cp -rf swagger-ui/dist /home/htdocs/public/ m…

Axure元件的介绍使用以及登录界面

一、Axure元件介绍 简介&#xff1a; Axure元件是一种功能强大的设计工具&#xff0c;专门用于用户体验设计和交互设计。它可以帮助设计师创建可交互的原型&#xff0c;并实现各种界面元素的设计和布局。 Axure元件的基本特点包括&#xff1a; 多样性&#xff1a;Axure元件包括…

耦合与内聚

目录 ​编辑 前言 耦合&#xff08;Coupling&#xff09;&#xff1a; 低耦合的示例&#xff1a; 内聚&#xff08;Cohesion&#xff09;&#xff1a; 高内聚的示例&#xff1a; 总结&#xff1a; 我的其他博客 前言 "耦合"和"内聚"是软件工程中两…

Qt6.5类库实例大全:QWidget

哈喽大家好&#xff0c;我是20YC小二&#xff01;欢迎扫码关注公众号&#xff0c;现在可免费领取《C程序员》在线视频教程哦&#xff01; ~下面开始今天的分享内容~ 1. QWidget介绍 QWidget 是 Qt 框架中的一个核心类&#xff0c;用于创建图形用户界面(GUI)应用程序的基本可视…

Halcon一维码识别

文章目录 参数连接halcon 自带案例1&#xff08;设置校验位识别条码&#xff09;Halcon 自带案例2&#xff08;设置对比度识别条码&#xff09;Halcon 自带案例3&#xff08;存在曲面变形&#xff09;Halcon 自带案例4&#xff08;设置条码扫描线&#xff09;Halcon 自带案例5&…

七、CM4树莓派连接DHT11温湿度传感器模块实现温湿度测定

4.DHT11说明书.pdf DHT11是一款有已校准数字信号输出的温湿度传感器。 其精度湿度5%RH&#xff0c; 温度2℃&#xff0c;量程湿度5~95%RH&#xff0c; 温度-20~60℃。 该传感器包含一个电阻湿度感元件和一个NTC温度测量设备。 3个引脚、-分别接VCC与GND&#xff0c;中间引脚DA…

RocketMQ-源码架构二

梳理一些比较完整&#xff0c;比较复杂的业务线 消息持久化设计 RocketMQ的持久化文件结构 消息持久化也就是将内存中的消息写入到本地磁盘的过程。而磁盘IO操作通常是一个很耗性能&#xff0c;很慢的操作&#xff0c;所以&#xff0c;对消息持久化机制的设计&#xff0c;是…