////REVIEW: the descriptor may come from anywhere; method assumes we get passed some state we actually own
        ////REVIEW: this mutates the state of the current instance but also mutates the shared ActionMap; that's bad
        public bool BindControl(InputControlDescriptor descriptor, InputControl control, bool restrictToExistingDevices)
        {
            bool existingDevice = false;

            for (int i = 0; i < m_DeviceStates.Count; i++)
            {
                if (control.provider == m_DeviceStates[i].controlProvider)
                {
                    existingDevice = true;
                    break;
                }
            }

            if (!existingDevice)
            {
                if (restrictToExistingDevices)
                {
                    return(false);
                }

                deviceStates.Add(new InputState(control.provider, new List <int>()
                {
                    control.index
                }));
            }

            descriptor.controlIndex = control.index;
            descriptor.deviceType   = control.provider.GetType();

            m_ControlScheme.customized = true;

            RefreshBindings();

            return(true);
        }
示例#2
0
 public static string GetDeviceControlName(InputControlDescriptor source)
 {
     string[] names = GetDeviceControlNames(source.deviceType);
     if (source.controlIndex < 0 || source.controlIndex >= names.Length)
     {
         return("None");
     }
     return(names[source.controlIndex]);
 }
示例#3
0
        public static string GetDeviceControlName(DeviceSlot deviceSlot, InputControlDescriptor source)
        {
            if (deviceSlot != null)
            {
                string[] names = GetDeviceControlNames(deviceSlot.type);
                if (source.controlIndex >= 0 && source.controlIndex < names.Length)
                {
                    return(names[source.controlIndex]);
                }
            }

            return("None");
        }
示例#4
0
        ////REVIEW: the descriptor may come from anywhere; method assumes we get passed some state we actually own
        ////REVIEW: this mutates the state of the current instance but also mutates the shared ActionMap; that's bad
        public bool BindControl(InputControlDescriptor descriptor, InputControl control, bool restrictToExistingDevices)
        {
            bool existingDevice = false;

            for (int i = 0; i < m_DeviceStates.Count; i++)
            {
                if (control.provider == m_DeviceStates[i].controlProvider)
                {
                    existingDevice = true;
                    break;
                }
            }

            if (!existingDevice)
            {
                if (restrictToExistingDevices)
                {
                    return(false);
                }

                deviceStates.Add(new InputState(control.provider, new List <int>()
                {
                    control.index
                }));
            }

            descriptor.controlIndex = control.index;
            var inputDevice = control.provider as InputDevice;

            if (inputDevice == null)
            {
                Debug.LogError(string.Format("The InputControlProvider must be an InputDevice, but it is a {0}", control.provider.GetType()));
                return(false);
            }
            int key = m_ControlScheme.GetDeviceKey(inputDevice);

            if (key == DeviceSlot.kInvalidKey)
            {
                Debug.LogError(string.Format("Could not find key for InputDevice type {0}", inputDevice.GetType()));
                return(false);
            }
            descriptor.deviceKey = key;

            m_ControlScheme.customized = true;

            RefreshBindings();

            return(true);
        }
示例#5
0
        private string GetSourceName(InputControlDescriptor source)
        {
            var deviceState = GetDeviceStateForDeviceSlot(m_ControlScheme.GetDeviceSlot(source.deviceKey));

            return(deviceState.controlProvider.GetControlData(source.controlIndex).name);
        }
示例#6
0
        private float GetSourceValue(InputControlDescriptor source)
        {
            var deviceState = GetDeviceStateForDeviceSlot(m_ControlScheme.GetDeviceSlot(source.deviceKey));

            return(deviceState.GetCurrentValue(source.controlIndex));
        }
示例#7
0
 public static string GetDeviceName(InputControlDescriptor source)
 {
     return((Type)source.deviceType == null ? "No-Device" : source.deviceType.Name);
 }
示例#8
0
 public ButtonAxisSource(InputControlDescriptor negative, InputControlDescriptor positive)
 {
     this.negative = negative;
     this.positive = positive;
 }