public static PlayerActions CreateWithDefaultBindings()
		{
			var playerActions = new PlayerActions();

			playerActions.Fire.AddDefaultBinding( Key.Shift, Key.A );
			playerActions.Fire.AddDefaultBinding( InputControlType.Action1 );
			playerActions.Fire.AddDefaultBinding( Mouse.LeftButton );

			playerActions.Jump.AddDefaultBinding( Key.Space );
			playerActions.Jump.AddDefaultBinding( InputControlType.Action3 );
			playerActions.Jump.AddDefaultBinding( InputControlType.Back );

			playerActions.Up.AddDefaultBinding( Key.UpArrow );
			playerActions.Down.AddDefaultBinding( Key.DownArrow );
			playerActions.Left.AddDefaultBinding( Key.LeftArrow );
			playerActions.Right.AddDefaultBinding( Key.RightArrow );

			playerActions.Left.AddDefaultBinding( InputControlType.LeftStickLeft );
			playerActions.Right.AddDefaultBinding( InputControlType.LeftStickRight );
			playerActions.Up.AddDefaultBinding( InputControlType.LeftStickUp );
			playerActions.Down.AddDefaultBinding( InputControlType.LeftStickDown );

			playerActions.Left.AddDefaultBinding( InputControlType.DPadLeft );
			playerActions.Right.AddDefaultBinding( InputControlType.DPadRight );
			playerActions.Up.AddDefaultBinding( InputControlType.DPadUp );
			playerActions.Down.AddDefaultBinding( InputControlType.DPadDown );

			playerActions.Up.AddDefaultBinding( Mouse.PositiveY );
			playerActions.Down.AddDefaultBinding( Mouse.NegativeY );
			playerActions.Left.AddDefaultBinding( Mouse.NegativeX );
			playerActions.Right.AddDefaultBinding( Mouse.PositiveX );

			playerActions.ListenOptions.IncludeUnknownControllers = true;
			playerActions.ListenOptions.MaxAllowedBindings = 4;
//			playerActions.ListenOptions.MaxAllowedBindingsPerType = 1;
//			playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
//			playerActions.ListenOptions.IncludeMouseButtons = true;

			playerActions.ListenOptions.OnBindingFound = ( action, binding ) =>
			{
				if (binding == new KeyBindingSource( Key.Escape ))
				{
					action.StopListeningForBinding();
					return false;
				}
				return true;
			};

			playerActions.ListenOptions.OnBindingAdded += ( action, binding ) =>
			{
				Debug.Log( "Binding added... " + binding.DeviceName + ": " + binding.Name );
			};

			playerActions.ListenOptions.OnBindingRejected += ( action, binding, reason ) =>
			{
				Debug.Log( "Binding rejected... " + reason );
			};

			return playerActions;
		}
		void OnEnable()
		{
			// See PlayerActions.cs for this setup.
			playerActions = PlayerActions.CreateWithDefaultBindings();

			LoadBindings();
		}
		void OnEnable()
		{
			playerInput = new PlayerActions();

			playerInput.Fire.AddDefaultBinding( Key.Shift, Key.A );
			playerInput.Fire.AddDefaultBinding( InputControlType.Action1 );
			playerInput.Fire.AddDefaultBinding( Mouse.LeftButton );
			playerInput.Fire.AddDefaultBinding( Mouse.PositiveScrollWheel );

			playerInput.Jump.AddDefaultBinding( Key.Space );
			playerInput.Jump.AddDefaultBinding( InputControlType.Action3 );
			playerInput.Jump.AddDefaultBinding( InputControlType.Back );
			playerInput.Jump.AddDefaultBinding( InputControlType.System );
			playerInput.Jump.AddDefaultBinding( Mouse.NegativeScrollWheel );

			playerInput.Up.AddDefaultBinding( Key.UpArrow );
			playerInput.Down.AddDefaultBinding( Key.DownArrow );
			playerInput.Left.AddDefaultBinding( Key.LeftArrow );
			playerInput.Right.AddDefaultBinding( Key.RightArrow );

			playerInput.Left.AddDefaultBinding( InputControlType.LeftStickLeft );
			playerInput.Right.AddDefaultBinding( InputControlType.LeftStickRight );
			playerInput.Up.AddDefaultBinding( InputControlType.LeftStickUp );
			playerInput.Down.AddDefaultBinding( InputControlType.LeftStickDown );

			playerInput.Up.AddDefaultBinding( Mouse.PositiveY );
			playerInput.Down.AddDefaultBinding( Mouse.NegativeY );
			playerInput.Left.AddDefaultBinding( Mouse.NegativeX );
			playerInput.Right.AddDefaultBinding( Mouse.PositiveX );

			playerInput.ListenOptions.MaxAllowedBindings = 3;
//			playerInput.ListenOptions.MaxAllowedBindingsPerType = 1;

			playerInput.ListenOptions.OnBindingFound = ( action, binding ) =>
			{
				if (binding == new KeyBindingSource( Key.Escape ))
				{
					action.StopListeningForBinding();
					return false;
				}
				return true;
			};

			playerInput.ListenOptions.OnBindingAdded += ( action, binding ) =>
			{
				Debug.Log( "Added binding... " + binding.DeviceName + ": " + binding.Name );
			};

			LoadBindings();
		}
        public static PlayerActions CreateWithDefaultBindings()
        {
            var playerActions = new PlayerActions();

            playerActions.Fire.AddDefaultBinding(Key.Shift, Key.A);
            playerActions.Fire.AddDefaultBinding(InputControlType.Action1);
            playerActions.Fire.AddDefaultBinding(Mouse.LeftButton);
            playerActions.Fire.AddDefaultBinding(Mouse.PositiveScrollWheel);

            playerActions.Jump.AddDefaultBinding(Key.Space);
            playerActions.Jump.AddDefaultBinding(InputControlType.Action3);
            playerActions.Jump.AddDefaultBinding(InputControlType.Back);
            playerActions.Jump.AddDefaultBinding(InputControlType.System);
            playerActions.Jump.AddDefaultBinding(Mouse.NegativeScrollWheel);

            playerActions.Up.AddDefaultBinding(Key.UpArrow);
            playerActions.Down.AddDefaultBinding(Key.DownArrow);
            playerActions.Left.AddDefaultBinding(Key.LeftArrow);
            playerActions.Right.AddDefaultBinding(Key.RightArrow);

            playerActions.Left.AddDefaultBinding(InputControlType.LeftStickLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.LeftStickRight);
            playerActions.Up.AddDefaultBinding(InputControlType.LeftStickUp);
            playerActions.Down.AddDefaultBinding(InputControlType.LeftStickDown);

            playerActions.Left.AddDefaultBinding(InputControlType.DPadLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.DPadRight);
            playerActions.Up.AddDefaultBinding(InputControlType.DPadUp);
            playerActions.Down.AddDefaultBinding(InputControlType.DPadDown);

            playerActions.Up.AddDefaultBinding(Mouse.PositiveY);
            playerActions.Down.AddDefaultBinding(Mouse.NegativeY);
            playerActions.Left.AddDefaultBinding(Mouse.NegativeX);
            playerActions.Right.AddDefaultBinding(Mouse.PositiveX);

            playerActions.ListenOptions.IncludeUnknownControllers = true;
            playerActions.ListenOptions.MaxAllowedBindings        = 3;
//			playerActions.ListenOptions.MaxAllowedBindingsPerType = 1;
//			playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
//			playerActions.ListenOptions.IncludeMouseButtons = true;

            playerActions.ListenOptions.OnBindingFound = (action, binding) =>
            {
                if (binding == new KeyBindingSource(Key.Escape))
                {
                    action.StopListeningForBinding();
                    return(false);
                }
                return(true);
            };

            playerActions.ListenOptions.OnBindingAdded += (action, binding) =>
            {
                Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name);
            };

            playerActions.ListenOptions.OnBindingRejected += (action, binding, reason) =>
            {
                Debug.Log("Binding rejected... " + reason);
            };

            return(playerActions);
        }
Exemple #5
0
        public static PlayerActions CreateWithDefaultBindings()
        {
            var playerActions = new PlayerActions();

            // How to set up mutually exclusive keyboard bindings with a modifier key.
            // playerActions.Back.AddDefaultBinding( Key.Shift, Key.Tab );
            // playerActions.Next.AddDefaultBinding( KeyCombo.With( Key.Tab ).AndNot( Key.Shift ) );

            playerActions.Fire.AddDefaultBinding(Key.A);
            playerActions.Fire.AddDefaultBinding(InputControlType.Action1);
            // playerActions.Fire.AddDefaultBinding( Mouse.LeftButton );

            playerActions.Jump.AddDefaultBinding(Key.Space);
            playerActions.Jump.AddDefaultBinding(InputControlType.Action3);

            playerActions.Up.AddDefaultBinding(Key.UpArrow);
            playerActions.Down.AddDefaultBinding(Key.DownArrow);
            playerActions.Left.AddDefaultBinding(Key.LeftArrow);
            playerActions.Right.AddDefaultBinding(Key.RightArrow);

            playerActions.Left.AddDefaultBinding(InputControlType.LeftStickLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.LeftStickRight);
            playerActions.Up.AddDefaultBinding(InputControlType.LeftStickUp);
            playerActions.Down.AddDefaultBinding(InputControlType.LeftStickDown);

            playerActions.Left.AddDefaultBinding(InputControlType.DPadLeft);
            playerActions.Right.AddDefaultBinding(InputControlType.DPadRight);
            playerActions.Up.AddDefaultBinding(InputControlType.DPadUp);
            playerActions.Down.AddDefaultBinding(InputControlType.DPadDown);

            playerActions.Up.AddDefaultBinding(Mouse.PositiveY);
            playerActions.Down.AddDefaultBinding(Mouse.NegativeY);
            playerActions.Left.AddDefaultBinding(Mouse.NegativeX);
            playerActions.Right.AddDefaultBinding(Mouse.PositiveX);

            playerActions.ListenOptions.IncludeUnknownControllers = true;
            playerActions.ListenOptions.MaxAllowedBindings        = 4;
            //playerActions.ListenOptions.MaxAllowedBindingsPerType = 1;
            //playerActions.ListenOptions.AllowDuplicateBindingsPerSet = true;
            playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
            //playerActions.ListenOptions.IncludeMouseButtons = true;
            //playerActions.ListenOptions.IncludeModifiersAsFirstClassKeys = true;
            //playerActions.ListenOptions.IncludeMouseScrollWheel = true;

            playerActions.ListenOptions.OnBindingFound = (action, binding) =>
            {
                if (binding == new KeyBindingSource(Key.Escape))
                {
                    action.StopListeningForBinding();
                    return(false);
                }

                return(true);
            };

            playerActions.ListenOptions.OnBindingAdded += (action, binding) =>
            {
                Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name);

                // if (binding.BindingSourceType == BindingSourceType.DeviceBindingSource)
                // {
                //  var control = ((DeviceBindingSource) binding).Control;
                //  Debug.Log( control );
                // }
            };

            playerActions.ListenOptions.OnBindingRejected += (action, binding, reason) => { Debug.Log("Binding rejected... " + reason); };

            return(playerActions);
        }