Dynamic Events

Overview

Provides easy way to subscribe methods to Vivox Events using Attributes like Unity NetCodeForGameObjects or Mirror Networking does with Server/Client RPC's. This functionality relies on the System.Reflection library which is known to be slow but I don't know how to use Mono.Cecil or C# Dynamic Methods with IL Emit/OpCodes. EasyCode searches assemblies for any methods containing EasyCode event Attributes (ex. [LoginEvent(LoginStatus.LoggedIn)]) at the start of the application.

When running starting your game/app EasyCode skips common assemblies (you can't modify them anyways) to speed up the search and uses async methods to prevent UI blocking as your application starts. EasyCode also stores all found methods containing event Attributes and caches/stores them in-memory and when Vivox Events are invoked it searches the cache, finds the gameobject that contains the correct event Attribute with a matching parameter type and calls/invokes the method.

As of right now using DynamicEvents will work on public, private, and static methods. Gotcha - If the method and class is static an exception may be thrown. I have yet to test this out but be warned.

For Async games/apps where most functionality is async/multi-threaded consider using the Unity Job System(with DOTS) or combine async Task/void methods with Parallel.For / Parallel.ForEach when doing CPU intensive work. Parallel.For / Parallel.ForEach will still block the UI / main thread if not used with async void or async Task methods. Do your own research if you don't know how to use asynchronous or Parallel programming. The advice I have mentioned above is not for all use cases and also considered bad in most contexts (like async void or using async with Parellel.ForEach), especially outside of Unity Game Engine where async is the standard for performant applications. Keep in mind Parallel programming (as well as async) comes with a lot of gotchas that could make your code hard to debug or actually make performance worse if not used correctly. Do your own research and avoid async until you have a good understanding of how to use it in Unity

Last updated