https://github.com/shlifedev/event-flow
non gc game event broadcast system for unity.
https://github.com/shlifedev/event-flow
event-system unity unity-event unity-event-system
Last synced: 7 months ago
JSON representation
non gc game event broadcast system for unity.
- Host: GitHub
- URL: https://github.com/shlifedev/event-flow
- Owner: shlifedev
- Created: 2024-05-13T08:07:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-06T07:00:47.000Z (over 1 year ago)
- Last Synced: 2024-11-06T07:37:21.080Z (over 1 year ago)
- Topics: event-system, unity, unity-event, unity-event-system
- Language: ShaderLab
- Homepage:
- Size: 11.1 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EventFlow
EventFlow is a Pub-Sub event system that can be easily used universally in Unity or general .NET projects.
- Zero GC with Roslyn Source Generator
- Very Simple
- Intuitive
The following is an example of sending a message to deal damage when a game character is touched.
## [Example](https://github.com/shlifedev/event-flow/tree/main/src/Assets/Example)
[Movie_001.webm](https://github.com/user-attachments/assets/19ef0dd3-7288-49fa-b3c3-87b2195be071)
## Installation
- git installiation
https://github.com/shlifedev/event-flow.git?path=/src/Packages/EventFlow
## Usage
### [Declare Your Game Event](https://github.com/shlifedev/event-flow/tree/main/src/Assets/Example/Scripts/Messages/OnEntityDamagedMessage.cs)
```
public struct YourMessage : IEventMessage{
public string Message;
}
```
## Very Simple Usage
### [Inherit IEventListenr And Regist](https://github.com/shlifedev/event-flow/tree/main/src/Assets/Example/Scripts/HealthBarUI.cs)
Inherit & Subscribe IEventListener Your Class.
```cs
[EventFlowListener]
public partial class YourClass : MonoBehaviour, IEventListener{
void OnEnable(){
RegisterEventListener(this);
}
void OnDisable(){
UnregisterEventListener(this);
}
public UniTask OnEvent(YourMessage args){
Debug.Log("Received! => " + args.Message);
}
}
```
### [Broadcast message](https://github.com/shlifedev/unity-event-system/blob/main/GameEvent/Example/Scripts/GameEntity.cs)
And Broadcast Your Message.
```cs
EventFlow.Broadcast(new YourMessage(){Message="hi"});
```
## FAQ
### Why should you use the EventFlowListener Attribute?
Internally, it uses the Roslyn source generator to help you subscribe to and unsubscribe from multiple message types without GC. If you use EventFlow.Register(this); instead, you don't have to use it, but we recommend using it.