ArchPM.Unity.Events
1.0.1
dotnet add package ArchPM.Unity.Events --version 1.0.1
NuGet\Install-Package ArchPM.Unity.Events -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArchPM.Unity.Events" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ArchPM.Unity.Events --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ArchPM.Unity.Events, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ArchPM.Unity.Events as a Cake Addin #addin nuget:?package=ArchPM.Unity.Events&version=1.0.1 // Install ArchPM.Unity.Events as a Cake Tool #tool nuget:?package=ArchPM.Unity.Events&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ArchPM.Unity.Events
The drivers to write such a framework item.
- I am learning Unity for fun and I am watching youtube videos.
- I saw that everybody is kinda struggling while giving or creating examples.
- It easly can be shown the bifferences between Singleton and Observer patterns.
- I said to myself, don't struggle, use this 😃
Next thing to do
- I will create an Unity example with walls and doors example soon.
- The plan is in October 2021.
Benefit of Using this approach
- You don't have to create 1000 methods to handle events.
- Loosly coupled.
- Single publishing point, single consuming point.
- Easy to focus on process instead of code structure.
- it's open source, you can improve if you like.
How to use
Step 1/3: Creating Event Class
using ArchPM.Unity.Events;
// create a event class that transfers the data you need.
// the class should implement IEvent interface
public class Event1 : IEvent
{
}
// you can create Event classes as much as you want and use them.
Step 2/3: Publishing
using ArchPM.Unity.Events;
// create an instace of event class
var event1 = new Event1();
// just call static publish method
EventBus.Instance.Publisher.Publish(event1);
// now your event is published. if there are any consumers, they will get this information.
Step 3/3: Consuming
using ArchPM.Unity.Events;
// create a method to handle published event
private void Event1Handler(EventMessage<Event1> eventMessage){
// you will get the eventMessage which is a wrapper of Event1 event class.
// every time when the Event1 published, you will get this information.
}
// Call Consume method and set the Event1Handler
// you can put this in Start method
IConsumeResult event1ConsumeResult
= EventBus.Instance.Consumer.Consume<Event1>(Event1Handler);
// in OnDestroy method, item must be unsubscribed.
event1ConsumeResult.Unsubscribe();
Step 3/3: Consuming / Another approach
using ArchPM.Unity.Events;
// Call Consume method and set the Event1Handler
// you can put this in Start method
IConsumeResult event1ConsumeResult
= EventBus.Instance.Consumer.Consume<Event1>(eventMessage => {
// you will get the eventMessage which is a wrapper of Event1 event class.
// every time when the Event1 published, you will get this information.
});
// to Unsubscribe, in OnDestroy method
event1ConsumeResult.Unsubscribe();
Other Functionalities
Unsubscribe All
using ArchPM.Unity.Events;
EventBus.Instance.Consumer.UnsubscribeAll();
Getting Error Logs
using ArchPM.Unity.Events;
// when the consumer gets an exception, than you can get the error message in Unity Console or wherever you want to add the exception.
EventBus.Instance.Init
.RegisterErrorLogAction(ex=>{ Debug.LogException(ex); });
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Refactoring names and correcting documentation