예제 #1
0
 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);
     }
 }
예제 #2
0
        bool ProcessEventInMap(ActionMapInput map, InputEvent inputEvent)
        {
            if (map.ProcessEvent(inputEvent))
            {
                return(true);
            }

            if (!map.autoReinitialize)
            {
                return(false);
            }

            if (map.CurrentlyUsesDevice(inputEvent.device))
            {
                return(false);
            }

            // Only switch control scheme if devices in existing scheme weren't used for a little while,
            // to avoid rapid switching.
            if (inputEvent.time < map.GetLastDeviceInputTime() + m_AutoReinitializeMinDelay)
            {
                return(false);
            }

            // If this event uses a different device than the current control scheme
            // then try and initialize a control scheme that has that device.
            // Otherwise, leave the current current control scheme state alone
            // as a re-initialization of the same control scheme will cause a reset in the process.
            if (!map.TryInitializeWithDevices(GetApplicableDevices(), new List <InputDevice>()
            {
                inputEvent.device
            }))
            {
                return(false);
            }

            m_FirstMapToReceiveEvents = maps.IndexOf(map) + 1;
            map.SendControlResetEvents();
            m_FirstMapToReceiveEvents = 0;

            // When changing control scheme, we do not want to init control scheme to device states
            // like we normally want, so do a hard reset here, before processing the new event.
            map.Reset(false);

            return(map.ProcessEvent(inputEvent));
        }