Exemple #1
0
    private void Update()
    {
        // Handle the room keys, which are 1 - 5 on the top of the keyboard (not the numpad)
        for (var roomKeyCode = KeyCode.Alpha1; roomKeyCode <= KeyCode.Alpha5; roomKeyCode++)
        {
            // Check each room key individually
            if (Input.GetKeyDown(roomKeyCode))
            {
                // Get all of the selected callers
                List <Call_Individual> selectedCallers = m_bindingManager.SelectedCallers;

                // Try to transfer all of the selected callers to the given room
                if (m_roomManager.TransferCallers(selectedCallers, GetRoomNameFromKeyCode(roomKeyCode)))
                {
                    // Clear the selection
                    m_bindingManager.DeselectAll();
                }
            }
        }



        // Handle the alphabet keys
        for (var alphaKeyCode = KeyCode.A; alphaKeyCode <= KeyCode.Z; alphaKeyCode++)
        {
            // Check each alphabet key individually
            if (Input.GetKeyDown(alphaKeyCode))
            {
                // Pass the keycode to the binding manager so it can manage swapping or selecting
                m_bindingManager.HandleLetterKeyPressed(alphaKeyCode);
            }
        }



        // Handle the special keys
        if (m_holdToSwap)
        {
            // Hold the swap button down, letting go goes back out of swap mode
            m_bindingManager.SetSwapMode(Input.GetKey(m_swapKey));
        }
        else
        {
            // Toggle swap mode on and off by pressing the key again
            if (Input.GetKeyDown(m_swapKey))
            {
                m_bindingManager.ToggleSwapMode();
            }
        }

        if (Input.GetKeyDown(m_deselectKey))
        {
            // Deselect all of the selected callers at once
            m_bindingManager.DeselectAll();
        }
        else if (Input.GetKeyDown(m_disconnectKey))
        {
            // Get all of the selected callers
            List <Call_Individual> selectedCallers = m_bindingManager.SelectedCallers;

            // Try to transfer all of the selected callers to the waiting room
            if (m_roomManager.TransferCallers(selectedCallers, Room_Name.Waiting))
            {
                // Clear the selection
                m_bindingManager.DeselectAll();
            }
        }
    }
    public void HandleLetterKeyPressed(KeyCode _alphabetKey)
    {
        // If in swap mode, we should prepare to switch the bindings
        if (m_isInSwapMode)
        {
            // If this is the first alphabet key pressed since entering swap mode, we should store it so we can prepare to swap next time
            if (m_keyToSwap == KeyCode.None)
            {
                // Store the key so that next time, we are able to actually perform the swap
                m_keyToSwap = _alphabetKey;
            }
            else
            {
                // Hold the caller temporarily so we can perform a swap
                Call_Individual tempCaller = m_keyBindings[m_keyToSwap];

                // Swap the bindings
                BindCallerToKey(m_keyToSwap, m_keyBindings[_alphabetKey]);
                BindCallerToKey(_alphabetKey, tempCaller);

                // Invoke the event since the key bindings have changed
                m_OnBindingsChanged.Invoke();

                // Clear the held swap key
                m_keyToSwap = KeyCode.None;
            }
        }
        else if (m_groupToBind != null) // Otherwise, if the player selected a call group in the backlog, we should be binding those mappings
        {
            // We should check if the binding is currently open. If it isn't, we should back out
            if (!CheckIfBindingOpen(_alphabetKey))
            {
                return;
            }

            // Grab the individual callers from the bound group
            List <Call_Individual> callers = m_groupToBind.CallParticipants;

            // Loop through and find the next one that needs a binding
            for (int i = 0; i < callers.Count; i++)
            {
                // Grab the caller reference
                var caller = callers[i];

                // If the caller is already bound, we can move on to the next one
                if (caller.BoundKeyCode != KeyCode.None)
                {
                    continue;
                }

                // Otherwise, we can go ahead and perform the binding
                BindCallerToKey(_alphabetKey, caller);

                // Invoke the event since the key bindings have changed
                m_OnBindingsChanged.Invoke();

                // We should also mark the caller as selected to make it easier to move it around after
                SelectCaller(caller);

                // We now also need to move the caller into the waiting room
                m_roomManager.TransferCallers(new List <Call_Individual> {
                    caller
                }, Room_Name.Waiting);

                // If this is the last caller, then the group is fully bound and we can unlink it
                if (i == callers.Count - 1)
                {
                    // The group is no longer in bind mode
                    m_groupToBind.IsInBindMode = false;

                    // Stop tracking the group
                    m_groupToBind = null;
                }

                // Finally, we should break the loop to prevent binding the next caller to the same key
                break;
            }
        }
        else  // Otherwise, the player is selecting / deselecting a caller
        {
            // Grab the call participant reference associated with the keycode
            Call_Individual caller = m_keyBindings[_alphabetKey];

            // Check if there is an actual caller bound to that key
            if (caller != null)
            {
                // If the caller is currently unselected, we should select them and vice versa
                if (m_selectedCallers.Contains(caller))
                {
                    DeselectCaller(caller);
                }
                else
                {
                    SelectCaller(caller);
                }
            }
        }
    }