Esempio n. 1
0
 /// <summary>
 ///     Destroys an event
 /// </summary>
 /// <typeparam name="T">The event object Type</typeparam>
 /// <param name="eventIdentifier">The event identifier</param>
 /// <param name="eEvent">The event to remove</param>
 public void DestroyEvent <T>(string eventIdentifier, Event <T> eEvent)
 {
     if (_eventList.ContainsKey(eventIdentifier))
     {
         _eventList[eventIdentifier].Remove(eEvent);
     }
 }
Esempio n. 2
0
        /// <summary>
        ///     Enumarable for dispatching all events on a eventIdentifier
        /// </summary>
        /// <typeparam name="T">The ForgeEventArgument Type</typeparam>
        /// <param name="eventIdentifier">The eventIdentifier</param>
        /// <param name="sender">The event sender object</param>
        /// <param name="args">The ForgeEventArguments</param>
        /// <returns>
        ///     <see cref="DispatchEvents"/>
        /// </returns>
        public IEnumerable DispatchEvent <T>(string eventIdentifier, object sender, HammerEventArgs <T> args)
        {
            if (!_eventList.ContainsKey(eventIdentifier))
            {
                yield break;
            }

            foreach (Event @event in _eventList[eventIdentifier])
            {
                if (@event.GetType() != typeof(Event <T>))
                {
                    throw new ForgeCritical(Language.ForgeCriticalInvalidEventTypeInList + eventIdentifier);
                }

                Event <T> iEvent = (Event <T>)@event;

                if (iEvent.EventType == args.ArgumentType)
                {
                    yield return(iEvent.Execute(sender, args));
                }
                else
                {
                    throw new ForgeCritical(Language.ForgeCriticalArgumentTypeDoesNotEqualEventType);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Registers an event and adds it to the list.
        /// </summary>
        /// <param name="eventIdentifier">The event identifier</param>
        /// <param name="hammerEvent">The event object</param>
        public void RegisterEvent(string eventIdentifier, Event hammerEvent)
        {
            if (!_eventList.ContainsKey(eventIdentifier))
            {
                _eventList.Add(eventIdentifier, new EventList <Event>());
            }

            _eventList[eventIdentifier].Add(hammerEvent);
        }
Esempio n. 4
0
        /// <summary>
        ///     Registers an event for x seconds.
        ///     Usefull for time based powerups.
        /// </summary>
        /// <param name="eventIdentifier">The event identifier</param>
        /// <param name="hammerEvent">The event object</param>
        /// <param name="time">The amount of seconds to register this event for</param>
        public void RegisterEventForSeconds(string eventIdentifier, Event hammerEvent, float time)
        {
            RegisterEvent(eventIdentifier, hammerEvent);

            StartCoroutine(DestroyAfterSeconds(time, hammerEvent, eventIdentifier));
        }
Esempio n. 5
0
        /// <summary>
        ///     Destroys the event after x seconds
        /// </summary>
        /// <param name="time">The seconds to wait for</param>
        /// <param name="hammerEvent">The event to destroy</param>
        /// <param name="eventIdentifier">The event Identifier</param>
        /// <returns>WaitForSeconds</returns>
        private IEnumerator DestroyAfterSeconds(float time, Event hammerEvent, string eventIdentifier)
        {
            yield return(new WaitForSeconds(time));

            _eventList[eventIdentifier].Remove(hammerEvent);
        }