Example #1
0
        /// <summary>
        /// Lets the pbt handle a short impulse.
        /// </summary>
        /// <param name="impulse">The impulse to handle.</param>
        /// <param name="source">The source of the impulse.</param>
        /// <param name="data">The passed data to handle the impulse.</param>
        public void OnImpulse(Enum impulse, object source = null, object data = null)
        {
            if (impulse.GetType() != ImpulseType)
            {
                throw new InvalidOperationException(impulse.ToString() + " is not of the type " + ImpulseType.ToString());
            }

            ImpulseHandle          handle = new ImpulseHandle(impulse, source, data);
            List <IImpulseHandler> handler;

            if (ImpulseHandler.TryGetValue(Convert.ToUInt32(impulse), out handler))
            {
                handle.Handler = handler.ToArray();

                foreach (IImpulseHandler h in handle.Handler)
                {
                    h.OnBeginImpulse(handle);
                }

                handle.Active = false;

                foreach (IImpulseHandler h in handle.Handler)
                {
                    h.OnEndImpulse(handle);
                }
            }
        }
Example #2
0
 /// <summary>
 /// End the activity of the specified impulse.
 /// </summary>
 /// <param name="handle">The impulse handle.</param>
 public void OnEndImpulse(ImpulseHandle handle)
 {
     handle.Active = false;
     if (handle.Handler == null)
     {
         return;
     }
     foreach (IImpulseHandler h in handle.Handler)
     {
         h.OnEndImpulse(handle);
     }
 }