예제 #1
0
        public void ClearButtonCall(int action)
        {
            foreach (PlayerData pd in mBinds[action].players)
            {
                pd.callback = null;

                mButtonCallSetQueue[mButtonCallSetQueueCount] = new ButtonCallSetData()
                {
                    pd = pd, cb = null, add = false
                };
                mButtonCallSetQueueCount++;
            }
        }
예제 #2
0
        public void RemoveButtonCall(int player, int action, OnButton callback)
        {
            if (action < mBinds.Length && player < mBinds[action].players.Length)
            {
                PlayerData pd = mBinds[action].players[player];

                mButtonCallSetQueue[mButtonCallSetQueueCount] = new ButtonCallSetData()
                {
                    pd = pd, cb = callback, add = false
                };
                mButtonCallSetQueueCount++;
            }
        }
예제 #3
0
 public void RemoveButtonCall(OnButton callback)
 {
     for (int i = 0; i < mBinds.Length; i++)
     {
         for (int j = 0; j < mBinds[i].players.Length; j++)
         {
             PlayerData pd = mBinds[i].players[j];
             if (pd.callback == callback)
             {
                 mButtonCallSetQueue[mButtonCallSetQueueCount] = new ButtonCallSetData()
                 {
                     pd = pd, cb = callback, add = false
                 };
                 mButtonCallSetQueueCount++;
             }
         }
     }
 }
예제 #4
0
        protected virtual void Update()
        {
            for (int i = 0; i < mButtonCallsCount; i++)
            {
                PlayerData pd = mButtonCalls[i];

                pd.info.state = State.None;

                Key keyDown = null;

                for (int k = 0; k < pd.keys.Length; k++)
                {
                    Key key = pd.keys[k];
                    if (ProcessButtonDown(key))
                    {
                        keyDown = key;
                        break;
                    }
                }

                if (keyDown != null)
                {
                    if (!pd.down)
                    {
                        pd.down = true;

                        pd.info.axis  = keyDown.GetAxisValue();
                        pd.info.state = State.Pressed;
                        pd.info.index = keyDown.index;

                        pd.callback(pd.info);
                    }
                }
                else
                {
                    if (pd.down)
                    {
                        pd.down = false;

                        pd.info.axis  = 0.0f;
                        pd.info.state = State.Released;

                        pd.callback(pd.info);
                    }
                }
            }

            //add or remove button calls
            for (int i = 0; i < mButtonCallSetQueueCount; i++)
            {
                ButtonCallSetData dat = mButtonCallSetQueue[i];

                if (dat.add)
                {
                    if (dat.cb != null)
                    {
                        if (dat.pd.callback != dat.cb)
                        {
                            dat.pd.callback += dat.cb;
                        }

                        int ind = System.Array.IndexOf(mButtonCalls, dat.pd, 0, mButtonCallsCount);
                        if (ind == -1)
                        {
                            mButtonCalls[mButtonCallsCount] = dat.pd;
                            mButtonCallsCount++;
                        }
                    }
                }
                else
                {
                    if (dat.cb != null)
                    {
                        dat.pd.callback -= dat.cb;
                    }
                    else
                    {
                        dat.pd.callback = null;
                    }

                    //no more callbacks, don't need to poll this anymore
                    if (dat.pd.callback == null)
                    {
                        if (mButtonCallsCount > 1)
                        {
                            int ind = System.Array.IndexOf(mButtonCalls, dat.pd, 0, mButtonCallsCount);
                            mButtonCalls[ind] = mButtonCalls[mButtonCallsCount - 1];

                            mButtonCallsCount--;
                        }
                        else
                        {
                            mButtonCallsCount = 0;
                        }
                    }
                }
            }

            mButtonCallSetQueueCount = 0;
        }