Exemplo n.º 1
0
        /// <summary>
        /// Returns true during the frame the user releases the key identified by InputListener name. name.
        /// Takes into account handler BlockKeys and HardBlockKeys.
        /// <para>It's better to pass InputListener, not a name.</para>
        /// </summary>
        public bool GetJustReleased(InputListener listener)
        {
            var block = false;

            if (!Input.GetKeyUp(listener.Positive) && !Input.GetKeyUp(listener.Alternative))
            {
                return(false);
            }
            foreach (var h in InputHandlersStack)
            {
                foreach (var l in h.JustReleased.Values)
                {
                    if (l.Name == listener.Name)
                    {
                        return(true);
                    }
                    else
                    {
                        if (l.Positive != listener.Positive && l.Alternative != listener.Alternative)
                        {
                            continue;
                        }
                        if (h.BlockKeys)
                        {
                            block = true;
                        }
                    }
                }
                if (h.HardBlockKeys || block)
                {
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds action to the InputListiner of specific name in
 /// </summary>
 /// <param name="name">Name of InputListener</param>
 /// <param name="method">Method to be added to the listener</param>
 private void AddAction(KeyCode key, Action method, IDictionary <KeyCode, InputListener> dic)
 {
     if (dic.ContainsKey(key))
     {
         dic[key].Actions += method;
     }
     else
     {
         var il = new InputListener(key);
         il.Actions += method;
         dic.Add(key, il);
         isDirty = true;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Invokes all listener's actions
 /// </summary>
 private static void InvokeListener(InputListener il, IInputHandler handler)
 {
     if (il.Actions == null)
     {
         return;
     }
     // If it must be invoked only once per frame
     if (handler.InvokeOncePerFrame)
     {
         // Let's check if it hasn't been already invoked
         if (il.Invoked)
         {
             return;
         }
         il.Actions.Invoke();
         il.Invoked = true;
     }
     else
     {
         il.Actions.Invoke();
     }
 }