ET6框架(八)事件系统

文章目录


一、事件的定义

我们打开Client > Unity.Model > Codes > Model > Demo > EventType.cs 即可以查看目前工程中的事件

我们可以此添加事件结构体

我们还需要定义一个事件接收方法,创建路径文件夹及脚本

在Unity.HotfixView > Codes > Demo > Computer > Event 创建脚本 InstallComputer_AddComponent.cs

该类需要继承AEvent并制定类型 EventType.InstallComputer ,这样在接收到EventType.InstallComputer事件时则会执行以下事件

我们可以通过调用方法,触发事件

Game.EventSystem.Publish(new EventType.InstallComputer(){Computer = computer});


二、定义异步事件

同样在Client > Unity.Model > Codes > Model > Demo > EventType.cs 定义异步事件

我们同样在Unity.HotfixView > Codes > Demo > Computer > Event 创建脚本 InstallComputerAsync_AddComponent.cs

编写脚本内容,需要注意的是这个脚本需要继承AEventAsync并指事件EventType.InstallComputerAsync

并且需要使用async关键字,返回类型为ETTask

我们通过以下事件来触发,需要注意的是异步事件需要携程来触发

Game.EventSystem.Publish(new EventType.InstallComputerAsync(){Computer = computer}).Coroutine();

相关推荐
小盖子15 天前
ET6框架(十二)ET-EUI基本使用
et6·et6eui·e-ui·eui·et-eui
小盖子21 天前
ET6框架(一)介绍及环境部署
et6·et框架·et6框架·什么是et框架