/// <summary> /// Registers an achievement to be notified when an event occurs. This method /// should only be called from within the Initialize method of an achievement! /// </summary> /// <param name="e">The event to register for.</param> /// <param name="caller">A reference to the achievement registering.</param> public void RegisterForEvent( string e, Achievement caller ) { // Can only register for events while the engine is initializing! if ( state != ManagerState.Initializing ) { throw new Exception( "Cannot register for an achievement event at this time." ); } if ( ! eventReg.ContainsKey( e ) ) { // Event doesn't exist yet, create it! eventReg.Add( e, new List<Achievement>() ); } eventReg[e].Add( caller ); }
/// <summary> /// Unregisters an achievement from being notified when an event occurs. /// </summary> /// <param name="e">The event to unregister from.</param> /// <param name="caller">A reference to the achievement unregistering.</param> public void UnregisterFromEvent( string e, Achievement caller ) { if ( eventReg.ContainsKey( e ) ) { // Queue up to unregister the achievement. The actual // unregistering will occur the next time RaiseEvent // is called. This is to avoid the eventReg dictionary // from being modified while being iterated through // during a RaiseEvent call. unregQueue.Add( new Tuple<string,Achievement>(e, caller) ); } }
/// <summary> /// Adds an achievement to be tracked by the Achievement Manager. /// </summary> /// <remarks>All achievements must be added before calling Initialize()!</remarks> /// <param name="achievement">The achievement to add.</param> public void AddAchievement( Achievement achievement ) { // Check to make sure we're still in the raw uninitialized state. if ( state != ManagerState.Uninitialized ) { throw new Exception( "Cannot add an achievement at this time." ); } achis.Add( achievement ); }