private GameEventData <T> GetOrCreateLocalData() { IGameEventData untypedData = Owner.EventData.Get(_metadata.Id); GameEventData <T> data; if (untypedData != null) { // data found! data = (GameEventData <T>)untypedData; } else { // No data found! Create new data. data = new GameEventData <T>(); Owner.EventData.Set(_metadata.Id, data); } return(data); }
public void Add <T>(int id) where T : EventArgs { if (Owner.EventData.Get(id) != null) { return; } if (id < 0 || id >= GameObject.EventMetadata.Count) { string message = string.Format( CultureInfo.InvariantCulture, "Unknown ID. No game object event with the ID '{0}' and type '{1}' was defined. " + "Game object events must be defined using GameObject.CreateEvent() before they can be used.", id, typeof(T).FullName); throw new ArgumentException(message, "id"); } var data = new GameEventData <T>(); Owner.EventData.Set(id, data); }