04-ET框架的事件系统
TIPS:
本系列贴仅用于博主学习ET框架的记录
文章目录
- 前言
- 一、使用ET的事件组装电脑实体(Computer)
- 1.同步事件
- 2.异步事件
- 总结
前言
ET框架的事件系统的学习。
一、使用ET的事件组装电脑实体(Computer)
1.同步事件
(1)打开ET目录下的Client-Server.sln,打开Client/Unity.Model/Codes/Model/Demo文件夹下的EventType.cs文件,在末尾添加一个事件结构体InstallComputer。
代码如下(示例):EventType.cs
namespace ET
{namespace EventType{.........public struct InstallComputer{public Computer Computer;}}
}
(2)回到AfterCreateZoneScene_AddComponent.cs文件下注释掉之前的代码,发布一个同步的事件。
代码如下(示例):AfterCreateZoneScene_AddComponent.cs
namespace ET
{public class AfterCreateZoneScene_AddComponent: AEvent<EventType.AfterCreateZoneScene>{protected override void Run(EventType.AfterCreateZoneScene args){Scene zoneScene = args.ZoneScene;zoneScene.AddComponent<UIComponent>();zoneScene.AddComponent<UIPathComponent>();zoneScene.AddComponent<UIEventComponent>();zoneScene.AddComponent<RedDotComponent>();zoneScene.AddComponent<ResourcesLoaderComponent>();zoneScene.GetComponent<UIComponent>().ShowWindow(WindowID.WindowID_Login);Computer computer = zoneScene.AddChild<Computer>();Game.EventSystem.Publish(new EventType.InstallComputer(){Computer = computer});}}
}
(3)发布了事件就要有一个处理事件的类,在Unity.HotfixView/Codes/HotfixView/Demo下创建一个Computer文件夹,再在Computer文件夹下新建一个Event文件夹,之后在Event文件夹下新建一个事件处理的类InstallComputer_AddComponent.cs
代码如下(示例):InstallComputer_AddComponent .cs
using ET.EventType;namespace ET
{public class InstallComputer_AddComponent : AEvent<EventType.InstallComputer>{protected override void Run(InstallComputer a){Computer computer = a.Computer;computer.AddComponent<PCCaseComponent>();computer.AddComponent<MonitorsComponent>();computer.Start();}}
}
(4)保存代码返回编辑器F5等待编译结束即可运行查看。
实体成功添加上了组件。
2.异步事件
异步事件和同步事件差不多,不过发布事件时要使用PublishAsync,事件处理类需要继承AEventAsync。
Game.EventSystem.PublishAsync(new EventType.InstallComputerAsync() { Computer = computer }).Coroutine();
using ET.EventType;namespace ET
{public class InstallComputerAsync_AddComponent: AEventAsync<InstallComputerAsync>{protected async override ETTask Run(InstallComputerAsync args){Computer computer = args.Computer;computer.AddComponent<PCCaseComponent>();computer.AddComponent<MonitorsComponent>();await TimerComponent.Instance.WaitAsync(3000);//等待三秒computer.Start();}}
}
总结
目前学到这还算能顶。
04-ET框架的事件系统相关推荐
- ET框架的事件系统和异步编程详解
ET框架的事件系统和异步编程 文章目录 ET框架的事件系统和异步编程 ET框架使用事件的步骤 ET框架中事件使用的规则和注意事项 ET框架下ETTask的异步编程 ETTask下Await的本质 ET ...
- java web应用开发期末考试_Java开发工程师(Web方向) - 04.Spring框架 - 期末测试
假设有如下数据表: create table Blog( blogId int auto_increment primary key comment "博客Id", blogTit ...
- ubuntu14.04初体会
2014年4月17日ubuntu新的长期支持版14.04公布了,中国时间18日一早就能够下载到. 18日晚.在我的X200上安装上了14.04,算是比較早一批体会到14.04正式版的人 ...
- 20.Java集合框架(四)
01.集合框架工具类(Collections-sort) public static <T extends Comparable<? super T>> void sort(L ...
- 自动化测试框架-pytest框架入门篇
前段时间,九九姐更新了自动化测试中unittest框架,然后有很多小伙伴私聊九九姐,说想学习一下pytest框架的内容.既然大家已经说话了,九九姐怎么能不安排呢,所以今天就给大家说一说pytest框架 ...
- LeetCode刷题框架总结
LeetCode刷题框架总结 01 | 数组和链表遍历框架 1.数组遍历框架,典型的线性迭代结构 void traverse(int[] arr) {for (int i = 0; i < ar ...
- uft自动化测试工具安装步骤_你需要了解的自动化测试框架知识
01 自动化测试与测试自动化 很多人会以为自动化测试和测试自动化这两个概念没有什么不同.但是从我个人看来,这两个概念有本质上的区别. 自动化测试是指使用自动化测试工具代替人工的方式来执行测试用例.使用 ...
- ApiTesting全链路接口自动化测试框架
简介 此框架是基于Python+Pytest+Requests+Allure+Yaml+Json实现全链路接口自动化测试. 主要流程:解析接口数据包 ->生成接口基础配置(yml) ->生 ...
- 【嵌入式Linux开发一路清障-连载01】Ubuntu22.04启动U盘制作及系统安装与配置
[嵌入式Linux开发一路清障-连载01]Ubuntu22.04启动U盘制作及系统安装与配置 Ubuntu22.04启动工具 Ubuntu22.04安装 障碍01--Ubuntu中安装搜狗五笔输入法 ...
最新文章
- 深度学习新星:GANs的基本原理、应用和走向
- HTML上传文件的多种方式
- 多协议标签交换中的标签指的是什么?—Vecloud微云
- 发展农业对话国际农民丰收节贸易会 菲律宾学中国还是印度?
- Mysql的存储过程修改表的数据:项目上一个小练习
- 外设驱动库开发笔记21:BME680环境传感器驱动
- 博图如何上载wincc程序_WINCC 博途 以太网下载方式
- NSBundle 的理解和 mainBundle
- RocketMq 事务消息使用
- vs没有添加引用_国内考研VS英国读研!各有哪些利弊?
- MySQL 执行原生sql
- java elasticsearch_在Spring java框架中使用ElasticSearch的最佳方式
- freemaker--hibernate
- 闲聊Framebuffer
- java day08【String类、static关键字、Arrays类、 Math类】
- JS操作iframe元素
- Spring JDBC 【继承JdbcDaoSupport】
- mmap映射方式读写本地文件
- 机器人学基础——位姿
- spark安装以及hive on spark和spark on hive 的配置