I have got one gameobject with a script attached which exposes 2 events, LevelLoaded and LevelUnloaded, the ValueEventHandler is just an extended EventHandler which accepts a type for the event args to carry over.
public class CurrentLevelBehaviour : MonoBehaviour
{
public event ValueEventHandler<ILevel> LevelLoaded;
public event ValueEventHandler<ILevel> LevelUnloaded;
// Methods which raise events
}
Then I have another gameobject with a behaviour which is a HUD of sorts, so when a level is loaded it needs to know to update and display the information, however for some reason the callback is never raised.
public class LevelHud : MonoBehaviour
{
private ILevel _currentLevel;
// Use this for initialization
void Start ()
{
var currentLevelBehaviour = GameObject.Find("CurrentLevel").GetComponent<CurrentLevelBehaviour>();
currentLevelBehaviour.LevelLoaded += (sender, eventArgs) => { _currentLevel = eventArgs.Value; };
currentLevelBehaviour.LevelUnloaded += (sender, eventArgs) => { _currentLevel = null; };
}
// Other methods which use _currentLevel
}
So is this a unity problem? as there are no errors from the compiler or from unity when running things, I can just see that the level is not being set in the HUD area.