diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/PlayerActions.cs |
+ init
Diffstat (limited to 'GameCode/PlayerActions.cs')
-rw-r--r-- | GameCode/PlayerActions.cs | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/GameCode/PlayerActions.cs b/GameCode/PlayerActions.cs new file mode 100644 index 0000000..8c6d6f1 --- /dev/null +++ b/GameCode/PlayerActions.cs @@ -0,0 +1,131 @@ +using System; +using InControl; + +public class PlayerActions : PlayerActionSet +{ + public PlayerAction Fire; + + public PlayerAction Block; + + public PlayerAction Jump; + + public PlayerAction Left; + + public PlayerAction Right; + + public PlayerAction Up; + + public PlayerAction Down; + + public PlayerTwoAxisAction Move; + + public PlayerTwoAxisAction Aim; + + public PlayerAction AimLeft; + + public PlayerAction AimRight; + + public PlayerAction AimUp; + + public PlayerAction AimDown; + + public PlayerAction Start; + + public PlayerActions() + { + Fire = CreatePlayerAction("Fire"); + Start = CreatePlayerAction("Start"); + Block = CreatePlayerAction("Block"); + Jump = CreatePlayerAction("Jump"); + Left = CreatePlayerAction("Move Left"); + Right = CreatePlayerAction("Move Right"); + Up = CreatePlayerAction("Move Up"); + Down = CreatePlayerAction("Move Down"); + AimLeft = CreatePlayerAction("Aim Left"); + AimRight = CreatePlayerAction("Aim Right"); + AimUp = CreatePlayerAction("Aim Up"); + AimDown = CreatePlayerAction("Aim Down"); + Move = CreateTwoAxisPlayerAction(Left, Right, Down, Up); + Aim = CreateTwoAxisPlayerAction(AimLeft, AimRight, AimDown, AimUp); + } + + public static PlayerActions CreateWithKeyboardBindings() + { + PlayerActions playerActions = new PlayerActions(); + playerActions.Fire.AddDefaultBinding(Mouse.LeftButton); + playerActions.Block.AddDefaultBinding(Mouse.RightButton); + playerActions.Jump.AddDefaultBinding(Key.Space); + playerActions.Up.AddDefaultBinding(Key.W); + playerActions.Down.AddDefaultBinding(Key.S); + playerActions.Left.AddDefaultBinding(Key.A); + playerActions.Right.AddDefaultBinding(Key.D); + playerActions.Start.AddDefaultBinding(Key.Return); + playerActions.ListenOptions.IncludeUnknownControllers = true; + playerActions.ListenOptions.MaxAllowedBindings = 4u; + playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true; + playerActions.ListenOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding) + { + if (binding == new KeyBindingSource(Key.Escape)) + { + action.StopListeningForBinding(); + return false; + } + return true; + }; + BindingListenOptions bindingListenOptions = playerActions.ListenOptions; + bindingListenOptions.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(bindingListenOptions.OnBindingAdded, (Action<PlayerAction, BindingSource>)delegate(PlayerAction action, BindingSource binding) + { + Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name); + }); + BindingListenOptions bindingListenOptions2 = playerActions.ListenOptions; + bindingListenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(bindingListenOptions2.OnBindingRejected, (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)delegate(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason) + { + Debug.Log("Binding rejected... " + reason); + }); + return playerActions; + } + + public static PlayerActions CreateWithControllerBindings() + { + PlayerActions playerActions = new PlayerActions(); + playerActions.Fire.AddDefaultBinding(InputControlType.Action3); + playerActions.Fire.AddDefaultBinding(InputControlType.RightTrigger); + playerActions.Block.AddDefaultBinding(InputControlType.Action2); + playerActions.Block.AddDefaultBinding(InputControlType.LeftTrigger); + playerActions.Jump.AddDefaultBinding(InputControlType.Action1); + playerActions.Jump.AddDefaultBinding(InputControlType.LeftBumper); + playerActions.Jump.AddDefaultBinding(InputControlType.RightBumper); + playerActions.Start.AddDefaultBinding(InputControlType.Start); + playerActions.Left.AddDefaultBinding(InputControlType.LeftStickLeft); + playerActions.Right.AddDefaultBinding(InputControlType.LeftStickRight); + playerActions.Up.AddDefaultBinding(InputControlType.LeftStickUp); + playerActions.Down.AddDefaultBinding(InputControlType.LeftStickDown); + playerActions.AimLeft.AddDefaultBinding(InputControlType.RightStickLeft); + playerActions.AimRight.AddDefaultBinding(InputControlType.RightStickRight); + playerActions.AimUp.AddDefaultBinding(InputControlType.RightStickUp); + playerActions.AimDown.AddDefaultBinding(InputControlType.RightStickDown); + playerActions.ListenOptions.IncludeUnknownControllers = true; + playerActions.ListenOptions.MaxAllowedBindings = 4u; + playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true; + playerActions.ListenOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding) + { + if (binding == new KeyBindingSource(Key.Escape)) + { + action.StopListeningForBinding(); + return false; + } + return true; + }; + BindingListenOptions bindingListenOptions = playerActions.ListenOptions; + bindingListenOptions.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(bindingListenOptions.OnBindingAdded, (Action<PlayerAction, BindingSource>)delegate(PlayerAction action, BindingSource binding) + { + Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name); + }); + BindingListenOptions bindingListenOptions2 = playerActions.ListenOptions; + bindingListenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(bindingListenOptions2.OnBindingRejected, (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)delegate(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason) + { + Debug.Log("Binding rejected... " + reason); + }); + return playerActions; + } +} |