InputControlType ListenForControl( BindingListenOptions listenOptions, InputDevice device )
		{
			if (device.IsKnown)
			{
				var controlCount = device.Controls.Length;
				for (int i = 0; i < controlCount; i++)
				{
					var control = device.Controls[i];
					if (control != null && IsPressed( control ))
					{
						if (listenOptions.IncludeNonStandardControls || control.IsStandard)
						{
							var target = control.Target;
							if (target == InputControlType.Command && listenOptions.IncludeNonStandardControls)
							{
								continue;
							}
							return target;
						}
					}
				}
			}

			return InputControlType.None;
		}
        InputControlType ListenForControl(BindingListenOptions listenOptions, InputDevice device)
        {
            if (device.IsKnown)
            {
                var controlCount = device.Controls.Length;
                for (int i = 0; i < controlCount; i++)
                {
                    var control = device.Controls[i];
                    if (control != null && control.IsPressed)
                    {
                        if (listenOptions.IncludeNonStandardControls || control.IsStandard)
                        {
                            var target = control.Target;
                            if (target == InputControlType.Command && listenOptions.IncludeNonStandardControls)
                            {
                                continue;
                            }
                            return(target);
                        }
                    }
                }
            }

            return(InputControlType.None);
        }
示例#3
0
        public void ListenForBindingReplacing(BindingSource binding)
        {
            BindingListenOptions bindingListenOptions = ListenOptions ?? Owner.ListenOptions;

            bindingListenOptions.ReplaceBinding = binding;
            Owner.listenWithAction = this;
            int num = bindingSourceListeners.Length;

            for (int i = 0; i < num; i++)
            {
                bindingSourceListeners[i].Reset();
            }
        }
示例#4
0
        UnknownDeviceControl ListenForControl(BindingListenOptions listenOptions, InputDevice device)
        {
            if (device.IsUnknown)
            {
                var button = device.GetFirstPressedButton();
                if (button)
                {
                    return(button);
                }

                var analog = device.GetFirstPressedAnalog();
                if (analog)
                {
                    return(analog);
                }
            }

            return(UnknownDeviceControl.None);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeMouseButtons)
            {
                return(null);
            }

            if (detectFound != Mouse.None)
            {
                if (!IsPressed(detectFound))
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new MouseBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var control = ListenForControl();

            if (control != Mouse.None)
            {
                if (detectPhase == 1)
                {
                    detectFound = control;
                    detectPhase = 2;                     // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1;                     // Wait for press.
                }
            }

            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeControllers || device.IsUnknown)
            {
                return(null);
            }

            if (detectFound != InputControlType.None)
            {
                if (!IsPressed(detectFound, device))
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new DeviceBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var control = ListenForControl(listenOptions, device);

            if (control != InputControlType.None)
            {
                if (detectPhase == 1)
                {
                    detectFound = control;
                    detectPhase = 2;                     // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1;                     // Wait for press.
                }
            }

            return(null);
        }
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeKeys)
            {
                return(null);
            }

            if (detectFound.Count > 0)
            {
                if (!detectFound.IsPressed)
                {
                    if (detectPhase == 2)
                    {
                        var bindingSource = new KeyBindingSource(detectFound);
                        Reset();
                        return(bindingSource);
                    }
                }
            }

            var keyCombo = KeyCombo.Detect(listenOptions.IncludeModifiersAsFirstClassKeys);

            if (keyCombo.Count > 0)
            {
                if (detectPhase == 1)
                {
                    detectFound = keyCombo;
                    detectPhase = 2;                     // Wait for release.
                }
            }
            else
            {
                if (detectPhase == 0)
                {
                    detectPhase = 1;                     // Wait for press.
                }
            }

            return(null);
        }
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeControllers || device.IsUnknown)
			{
				return null;
			}

			if (detectFound != InputControlType.None)
			{
				if (!IsPressed( detectFound, device ))
				{
					if (detectPhase == 2)
					{
						var bindingSource = new DeviceBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var control = ListenForControl( listenOptions, device );
			if (control != InputControlType.None)
			{
				if (detectPhase == 1)
				{
					detectFound = control;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeKeys)
			{
				return null;
			}

			if (detectFound.Count > 0)
			{
				if (!detectFound.IsPressed)
				{
					if (detectPhase == 2)
					{
						var bindingSource = new KeyBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var keyCombo = KeyCombo.Detect( listenOptions.IncludeModifiersAsFirstClassKeys );
			if (keyCombo.Count > 0)
			{
				if (detectPhase == 1)
				{
					detectFound = keyCombo;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeMouseButtons)
			{
				return null;
			}

			if (detectFound != Mouse.None)
			{
				if (!MouseBindingSource.ButtonIsPressed( detectFound ))
				{
					if (detectPhase == 2)
					{
						var bindingSource = new MouseBindingSource( detectFound );
						Reset();
						return bindingSource;
					}
				}
			}

			var control = ListenForControl();
			if (control != Mouse.None)
			{
				if (detectPhase == 1)
				{
					detectFound = control;
					detectPhase = 2; // Wait for release.
				}
			}
			else
			{
				if (detectPhase == 0)
				{
					detectPhase = 1; // Wait for press.
				}
			}

			return null;
		}
示例#11
0
        public BindingSource Listen(BindingListenOptions listenOptions, InputDevice device)
        {
            if (!listenOptions.IncludeUnknownControllers || device.IsKnown)
            {
                return(null);
            }

            if (detectPhase == DetectPhase.WaitForControlRelease && detectFound)
            {
                if (!IsPressed(detectFound, device))
                {
                    var bindingSource = new UnknownDeviceBindingSource(detectFound);
                    Reset();
                    return(bindingSource);
                }
            }

            var control = ListenForControl(listenOptions, device);

            if (control)
            {
                if (detectPhase == DetectPhase.WaitForControlPress)
                {
                    detectFound = control;
                    detectPhase = DetectPhase.WaitForControlRelease;
                }
            }
            else
            {
                if (detectPhase == DetectPhase.WaitForInitialRelease)
                {
                    detectPhase = DetectPhase.WaitForControlPress;
                }
            }

            return(null);
        }
		public BindingSource Listen( BindingListenOptions listenOptions, InputDevice device )
		{
			if (!listenOptions.IncludeUnknownControllers || device.IsKnown)
			{
				return null;
			}

			if (detectPhase == DetectPhase.WaitForControlRelease && detectFound)
			{
				if (!IsPressed( detectFound, device ))
				{
					var bindingSource = new UnknownDeviceBindingSource( detectFound );
					Reset();
					return bindingSource;
				}
			}

			var control = ListenForControl( listenOptions, device );
			if (control)
			{
				if (detectPhase == DetectPhase.WaitForControlPress)
				{
					detectFound = control;
					detectPhase = DetectPhase.WaitForControlRelease;
				}
			}
			else
			{
				if (detectPhase == DetectPhase.WaitForInitialRelease)
				{
					detectPhase = DetectPhase.WaitForControlPress;
				}
			}

			return null;
		}
		UnknownDeviceControl ListenForControl( BindingListenOptions listenOptions, InputDevice device )
		{
			if (device.IsUnknown)
			{
				var unknownDevice = device as UnknownUnityInputDevice;
				if (unknownDevice != null)
				{
					var button = unknownDevice.GetFirstPressedButton();
					if (button)
					{
						return button;
					}

					var analog = unknownDevice.GetFirstPressedAnalog();
					if (analog)
					{
						return analog;
					}
				}
			}

			return UnknownDeviceControl.None;
		}
示例#14
0
        private void DetectBindings()
        {
            if (!IsListeningForBinding)
            {
                return;
            }
            BindingSource        bindingSource        = null;
            BindingListenOptions bindingListenOptions = ListenOptions ?? Owner.ListenOptions;
            int num = bindingSourceListeners.Length;

            for (int i = 0; i < num; i++)
            {
                bindingSource = bindingSourceListeners[i].Listen(bindingListenOptions, device);
                if (bindingSource != null)
                {
                    break;
                }
            }
            if (bindingSource == null || !bindingListenOptions.CallOnBindingFound(this, bindingSource))
            {
                return;
            }
            if (HasBinding(bindingSource))
            {
                if (bindingListenOptions.RejectRedundantBindings)
                {
                    bindingListenOptions.CallOnBindingRejected(this, bindingSource, BindingSourceRejectionType.DuplicateBindingOnActionSet);
                    return;
                }
                StopListeningForBinding();
                bindingListenOptions.CallOnBindingAdded(this, bindingSource);
                return;
            }
            if (bindingListenOptions.UnsetDuplicateBindingsOnSet)
            {
                int count = Owner.Actions.Count;
                for (int j = 0; j < count; j++)
                {
                    Owner.Actions[j].HardRemoveBinding(bindingSource);
                }
            }
            if (!bindingListenOptions.AllowDuplicateBindingsPerSet && Owner.HasBinding(bindingSource))
            {
                bindingListenOptions.CallOnBindingRejected(this, bindingSource, BindingSourceRejectionType.DuplicateBindingOnActionSet);
                return;
            }
            StopListeningForBinding();
            if (bindingListenOptions.ReplaceBinding == null)
            {
                if (bindingListenOptions.MaxAllowedBindingsPerType != 0)
                {
                    while (CountBindingsOfType(bindingSource.BindingSourceType) >= bindingListenOptions.MaxAllowedBindingsPerType)
                    {
                        RemoveFirstBindingOfType(bindingSource.BindingSourceType);
                    }
                }
                else if (bindingListenOptions.MaxAllowedBindings != 0)
                {
                    while (regularBindings.Count >= bindingListenOptions.MaxAllowedBindings)
                    {
                        int index = Mathf.Max(0, IndexOfFirstInvalidBinding());
                        regularBindings.RemoveAt(index);
                    }
                }
                AddBinding(bindingSource);
            }
            else
            {
                ReplaceBinding(bindingListenOptions.ReplaceBinding, bindingSource);
            }
            UpdateVisibleBindings();
            bindingListenOptions.CallOnBindingAdded(this, bindingSource);
        }