A type-safe event system for Unity3D based on the event listener pattern. Original blog article http://saltydog.digital/usage-pattern-for-a-type-safe-unity-event-system/
The code in this repository is a minor variation with added examples and tests of the event system originally described here: http://www.willrmiller.com/?p=87
EventManager is useful when you want to keep your codebase loosely coupled. Publishers and subscribers don't need to know anything about each other. EventManager is not a solution for exposing callbacks in the Unity Editor, Unity's own EventSystem may be more appropriate for that use case.
- Loosely coupled
- Type-safe
- Avoids breaking changes when new event parameters are added
Install the source or build a DLL.
Copy the Assets/EventManager folder to your project's Assets folder.
NOTE: Unit tests are stored in an 'Editor' folder so they are not added to your build
mkdir tmp
cd tmp
git clone https://github.com/robertwahler/EventManager
cp -R EventManager/Assets/EventManager ~/your_unity_project/Assets/
cp -R EventManager/Assets/Examples ~/your_unity_project/Assets/EventManager/
git --git-dir=./EventManager/.git log --pretty=format:%h -1 > ~/your_unity_project/Assets/EventManager/VERSION
Create a DLL and copy it to your Assets folder. These instructions expect the
standard Mono mcs compiler. If you need it on OS X, you can install it with
HomeBrew brew install mono
mkdir build
mcs -recurse:'Assets/EventManager/Source/*.cs' \
-lib:/Applications/Unity/Unity.app/Contents/Frameworks/ \
-lib:/Applications/Unity/Unity.app/Contents/Frameworks/Managed/ \
-r:UnityEngine \
-r:UnityEditor \
-target:library \
-out:build/SDD.EventManager.dll
mkdir Assets/Lib
cp build/SDD.EventManager.dll ~/your_unity_project/Assets/Lib/
The NUnit test framework is included in Unity 5.3 and higher. Tests require installation of the UnityTestTools asset for Unity 5.2 and lower.
There is no Unity hotkey for running tests. Instead, manually use this menu sequence:
Main Menu: Window, Editor Tests Runner
Editor Tests: Run All
All command line test scripts require a Ruby Thor scripting environment with Ruby > 2.0. These commands are configured for execution on Mac OS X. Other environments will need to modify the Ruby source in the ./tasks folder.
gem install bundler
bundle install
You need to shutdown the Unity IDE to run this command.
thor test:unit
The Unity IDE can be running.
thor test:nunit
This command will watch for file changes and automatically run the unit test suite. The Unity IDE can be running.
bundle exec guard
Do you use Vim instead of MonoDevelop/Visual Studio? Install https://github.com/neomake/neomake and add this to your .vimrc
let g:neomake_cs_mcs_maker = {
\ 'args': ['@.mcs'],
\ 'errorformat': '%f(%l\,%c): %trror %m',
\ }
See Assets/Examples
MIT, see ./LICENSE for details.