Пример #1
0
 /// <summary>
 /// Based on the choice of the given device, select an appropriate control scheme.
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 /// <remarks>
 /// The chosen control scheme may depend also on what other devices are already in use by other
 /// players.
 /// </remarks>
 public InputControlScheme?SelectControlSchemeBasedOnDevice(InputDevice device)
 {
     return(InputControlScheme.FindControlSchemeForDevice(device, controls.controlSchemes));
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <param name="scheme"></param>
        /// <typeparam name="TUser"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public static ControlSchemeSyntax AssignControlScheme <TUser>(this TUser user, InputControlScheme scheme)
            where TUser : class, IInputUser
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var index = FindUserIndex(user);

            if (index == -1)
            {
                throw new InvalidOperationException(string.Format("User '{0}' has not been added to the system", user));
            }

            if (string.IsNullOrEmpty(scheme.name) && !s_AllUserData[index].controlScheme.HasValue)
            {
                return new ControlSchemeSyntax {
                           m_UserIndex = index
                }
            }
            ;

            if (!string.IsNullOrEmpty(scheme.name) && s_AllUserData[index].controlScheme.HasValue &&
                string.Compare(
                    s_AllUserData[index].controlScheme.Value.m_Name, scheme.name,
                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                return new ControlSchemeSyntax {
                           m_UserIndex = index
                }
            }
            ;

            if (string.IsNullOrEmpty(scheme.name))
            {
                s_AllUserData[index].controlScheme = null;
            }
            else
            {
                s_AllUserData[index].controlScheme = scheme;
            }

            Notify(user, InputUserChange.ControlSchemeChanged);
            return(new ControlSchemeSyntax {
                m_UserIndex = index
            });
        }
Пример #3
0
 public void SwitchControlScheme(InputControlScheme controlScheme)
 {
     User.UnpairDevices();
     User.ActivateControlScheme(controlScheme).AndPairRemainingDevices();
 }
Пример #4
0
 public InputState(IInputActionCollection actions, InputControlScheme controlScheme)
 {
     User = InputUser.CreateUserWithoutPairedDevices();
     User.AssociateActionsWithUser(actions);
     SwitchControlScheme(controlScheme);
 }
Пример #5
0
 public InputContext(InputActionMap inputActions, InputControlScheme controlScheme)
 {
     this.actionMapName     = inputActions.name;
     this.controlSchemeName = controlScheme.name;
 }
Пример #6
0
        public static bool AssignControlScheme <TUser>(this TUser user, InputControlScheme scheme, bool assignMatchingUnusedDevices = false)
            where TUser : class, IInputUser
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var index = FindUserIndex(user);

            if (index == -1)
            {
                throw new InvalidOperationException(string.Format("User '{0}' has not been added to the system", user));
            }

            // Ignore if the control scheme is already set on the user.
            if (s_AllUserData[index].controlScheme.HasValue && s_AllUserData[index].controlScheme == scheme)
            {
                return(true);
            }

            s_AllUserData[index].controlScheme = scheme;

            // If we're supposed to automatically add devices, look for matching devices now which aren't
            // used by any other user.
            if (assignMatchingUnusedDevices)
            {
                var needToNotify = false;

                // If we are currently assigned devices, unassign them first.
                if (s_AllUserData[index].deviceCount > 0)
                {
                    ClearAssignedInputDevicesInternal(index);
                    needToNotify = true;
                }

                // Only go through the matching process if we actually have device requirements.
                if (scheme.deviceRequirements.Count > 0)
                {
                    // Grab all unused devices and then select a set of devices matching the scheme's
                    // requirements.
                    using (var availableDevices = GetUnusedDevices())
                        using (var pickedDevices = scheme.PickDevicesFrom(availableDevices))
                        {
                            if (!pickedDevices.isSuccessfulMatch)
                            {
                                // Control scheme isn't satisfied with the devices we have available.
                                // Fail setting the control scheme.
                                s_AllUserData[index].controlScheme = null;
                                return(false);
                            }

                            // Assign selected devices to user.
                            if (availableDevices.Count > 0)
                            {
                                foreach (var device in pickedDevices.devices)
                                {
                                    AssignDeviceInternal(index, device);
                                }
                                needToNotify = true;
                            }
                        }
                }

                if (needToNotify)
                {
                    Notify(user, InputUserChange.DevicesChanged);
                }
            }

            Notify(user, InputUserChange.ControlSchemeChanged);
            return(true);
        }