public void SetPlayerHandleMaps(PlayerHandle handle, bool initializeWithDevices = true, bool allowAssignUnassignedDevices = false)
 {
     handle.maps.Clear();
     for (int i = 0; i < actionMaps.Count; i++)
     {
         ActionMapSlot  actionMapSlot  = actionMaps[i];
         ActionMapInput actionMapInput = ActionMapInput.Create(actionMapSlot.actionMap);
         actionMapInput.active          = actionMapSlot.active;
         actionMapInput.blockSubsequent = actionMapSlot.blockSubsequent;
         if (initializeWithDevices)
         {
             actionMapInput.TryInitializeWithDevices(handle.GetApplicableDevices(allowAssignUnassignedDevices));
         }
         if (!handle.global && allowAssignUnassignedDevices)
         {
             List <InputDevice> usedDevices = actionMapInput.GetCurrentlyUsedDevices();
             for (int deviceIndex = 0; deviceIndex < usedDevices.Count; deviceIndex++)
             {
                 if (usedDevices[deviceIndex].GetAssignment() == null)
                 {
                     handle.AssignDevice(usedDevices[deviceIndex]);
                 }
             }
         }
         handle.maps.Add(actionMapInput);
     }
 }
Exemple #2
0
        void DrawPlayerHandle(PlayerHandle player)
        {
            EditorGUIUtility.labelWidth = 160;

            GUIContent playerContent = new GUIContent("Player " + player.index);

            GUILayout.BeginVertical(playerContent, Styles.playerStyle, GUILayout.Width(s_PlayerElementWidth));
            {
                GUILayout.Label("Assigned Devices", Styles.nodeLabel);
                for (int i = 0; i < s_MaxAssignedDevices; i++)
                {
                    Rect deviceRect = GUILayoutUtility.GetRect(GUIContent.none, Styles.deviceStyle, GUILayout.Width(k_DeviceElementWidth));
                    if (i >= player.assignments.Count)
                    {
                        continue;
                    }
                    m_DevicePositionTargets[player.assignments[i].device] = deviceRect;
                }

                if (m_ShowMaps)
                {
                    GUILayout.Label("Action Map Inputs", Styles.nodeLabel);
                    for (int i = 0; i < player.maps.Count; i++)
                    {
                        DrawActionMapInput(player.maps[i]);
                    }
                }
            }
            EditorGUILayout.EndVertical();
            if (player.global)
            {
                Rect rect = GUILayoutUtility.GetLastRect();
                GUI.Label(rect, "(Global)");
            }
        }
        // Gets existing handle for index if available.
        public static PlayerHandle GetPlayerHandle(int index)
        {
            PlayerHandle player = null;

            s_Players.TryGetValue(index, out player);
            return(player);
        }
        public static PlayerHandle GetNewPlayerHandle()
        {
            PlayerHandle handle = new PlayerHandle(s_NextPlayerIndex);

            s_Players[handle.index] = handle;
            s_NextPlayerIndex++;
            return(handle);
        }
 void Awake()
 {
     if (autoAssign)
     {
         handle        = PlayerHandleManager.GetNewPlayerHandle();
         handle.global = global;
         SetPlayerHandleMaps(handle, true, true);
     }
 }
 internal static void RemovePlayerHandle(PlayerHandle handle)
 {
     s_Players.Remove(handle.index);
 }