HH
4 年前
当前提交
f6b37bea
共有 11 个文件被更改,包括 566 次插入 和 59 次删除
-
29Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions
-
2Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions.meta
-
80Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
-
18Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentCubeMovement.cs
-
32Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/FPSAgent.cs
-
52Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSAgentInput.cs
-
11Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSAgentInput.cs.meta
-
390Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.cs
-
11Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.cs.meta
-
0/Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions
-
0/Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.InputSystem; |
|||
|
|||
public class FPSAgentInput : MonoBehaviour |
|||
{ |
|||
private FPSPlayerInputActions inputActions; |
|||
private FPSPlayerInputActions.PlayerActionMapActions actionMap; |
|||
private Gamepad gamepad; |
|||
|
|||
public Vector2 moveInput; |
|||
|
|||
public bool shootInput; |
|||
public bool jumpInput; |
|||
public bool dashInput; |
|||
public Vector2 rotateInput; |
|||
public bool shieldInput; |
|||
|
|||
// Start is called before the first frame update
|
|||
void Awake() |
|||
{ |
|||
inputActions = new FPSPlayerInputActions(); |
|||
actionMap = inputActions.PlayerActionMap; |
|||
} |
|||
void OnEnable() |
|||
{ |
|||
gamepad = Gamepad.current; |
|||
inputActions.Enable(); |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
inputActions.Disable(); |
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void FixedUpdate() |
|||
{ |
|||
// Vector2 move = gamepad.leftStick.ReadValue();
|
|||
|
|||
moveInput = actionMap.Walk.ReadValue<Vector2>(); |
|||
// shootInput = actionMap.Shoot.ReadValue<float>() > 0;
|
|||
shootInput = gamepad.rightTrigger.isPressed; |
|||
rotateInput = actionMap.RotateBody.ReadValue<Vector2>(); |
|||
// jumpInput = actionMap.Jump.ReadValue<float>() > 0;
|
|||
// jumpInput = actionMap.Jump.performed;
|
|||
jumpInput = gamepad.buttonSouth.isPressed; |
|||
dashInput = gamepad.buttonWest.isPressed; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8895a539297b24544aba7209546d2e36 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// GENERATED AUTOMATICALLY FROM 'Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions'
|
|||
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.InputSystem; |
|||
using UnityEngine.InputSystem.Utilities; |
|||
|
|||
public class @FPSPlayerInputActions : IInputActionCollection, IDisposable |
|||
{ |
|||
public InputActionAsset asset { get; } |
|||
public @FPSPlayerInputActions() |
|||
{ |
|||
asset = InputActionAsset.FromJson(@"{
|
|||
""name"": ""FPSPlayerInputActions"", |
|||
""maps"": [ |
|||
{ |
|||
""name"": ""Player Action Map"", |
|||
""id"": ""bb797917-97ca-47e1-b3c9-0572380e9376"", |
|||
""actions"": [ |
|||
{ |
|||
""name"": ""Walk"", |
|||
""type"": ""Value"", |
|||
""id"": ""2f9ecc77-85d9-4189-8faf-18dcf905d2d4"", |
|||
""expectedControlType"": ""Vector2"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""DashLeft"", |
|||
""type"": ""Button"", |
|||
""id"": ""1d14cda7-c4b3-4bb4-9ebb-f197aa5ed183"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""DashRight"", |
|||
""type"": ""Button"", |
|||
""id"": ""96db7975-8803-410a-863b-5f25b31019f4"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""Jump"", |
|||
""type"": ""Button"", |
|||
""id"": ""d2faa0a0-e027-4a5d-a155-870bb0ceaf7c"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""Shoot"", |
|||
""type"": ""Button"", |
|||
""id"": ""cbcb2a57-a474-46a7-b133-cf144f6de321"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""Shield"", |
|||
""type"": ""Button"", |
|||
""id"": ""ec97db61-8659-49c6-afaa-20b82a98e72b"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""RotateBody"", |
|||
""type"": ""Value"", |
|||
""id"": ""379999a6-e908-4242-ae2f-384e38bcb7cb"", |
|||
""expectedControlType"": ""Vector2"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
}, |
|||
{ |
|||
""name"": ""Dash"", |
|||
""type"": ""Button"", |
|||
""id"": ""49d5245a-a350-4f94-b4c8-cf578d61000b"", |
|||
""expectedControlType"": ""Button"", |
|||
""processors"": """", |
|||
""interactions"": """" |
|||
} |
|||
], |
|||
""bindings"": [ |
|||
{ |
|||
""name"": ""2D Vector"", |
|||
""id"": ""f7a4010c-91c6-422f-91e7-4b14cbdb214a"", |
|||
""path"": ""2DVector"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": true, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": ""up"", |
|||
""id"": ""0067bacb-5284-4358-8fbf-cbbd17bd4884"", |
|||
""path"": ""<Keyboard>/w"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": true |
|||
}, |
|||
{ |
|||
""name"": ""down"", |
|||
""id"": ""5e100fc2-94e3-4f73-8020-b6cbeed41b97"", |
|||
""path"": ""<Keyboard>/s"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": true |
|||
}, |
|||
{ |
|||
""name"": ""left"", |
|||
""id"": ""5eb9d69e-8df8-443c-93f4-447eeb52b75f"", |
|||
""path"": ""<Keyboard>/a"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": true |
|||
}, |
|||
{ |
|||
""name"": ""right"", |
|||
""id"": ""3b4de59c-d93c-4072-b11e-711ea8534593"", |
|||
""path"": ""<Keyboard>/d"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": true |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""6fdb596c-c0bb-4f37-b409-c235e9612acf"", |
|||
""path"": ""<Gamepad>/leftStick"", |
|||
""interactions"": """", |
|||
""processors"": ""StickDeadzone"", |
|||
""groups"": """", |
|||
""action"": ""Walk"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""14009289-6acb-4978-8838-01648248f103"", |
|||
""path"": ""<Gamepad>/leftShoulder"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""DashLeft"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""28ddf0bd-ea22-4069-ba60-ca41d4742bf9"", |
|||
""path"": ""<Gamepad>/buttonEast"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Jump"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""fe641861-0da7-43ba-8bd6-e95a17232a77"", |
|||
""path"": ""<Gamepad>/buttonSouth"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Shoot"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""2b94ae52-9bb0-478e-8e4c-bf6c747a5c7d"", |
|||
""path"": ""<Gamepad>/leftTrigger"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Shield"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""4df83c50-5bb2-497d-a713-237e1c5dc25a"", |
|||
""path"": ""<Gamepad>/rightShoulder"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""DashRight"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""0c0d917f-0af9-4575-b970-f441fd97db20"", |
|||
""path"": ""<Gamepad>/rightStick"", |
|||
""interactions"": """", |
|||
""processors"": ""StickDeadzone"", |
|||
""groups"": """", |
|||
""action"": ""RotateBody"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
}, |
|||
{ |
|||
""name"": """", |
|||
""id"": ""319796b1-6071-46f0-81dc-58b6bdb7d86a"", |
|||
""path"": ""<Gamepad>/buttonEast"", |
|||
""interactions"": """", |
|||
""processors"": """", |
|||
""groups"": """", |
|||
""action"": ""Dash"", |
|||
""isComposite"": false, |
|||
""isPartOfComposite"": false |
|||
} |
|||
] |
|||
} |
|||
], |
|||
""controlSchemes"": [] |
|||
}");
|
|||
// Player Action Map
|
|||
m_PlayerActionMap = asset.FindActionMap("Player Action Map", throwIfNotFound: true); |
|||
m_PlayerActionMap_Walk = m_PlayerActionMap.FindAction("Walk", throwIfNotFound: true); |
|||
m_PlayerActionMap_DashLeft = m_PlayerActionMap.FindAction("DashLeft", throwIfNotFound: true); |
|||
m_PlayerActionMap_DashRight = m_PlayerActionMap.FindAction("DashRight", throwIfNotFound: true); |
|||
m_PlayerActionMap_Jump = m_PlayerActionMap.FindAction("Jump", throwIfNotFound: true); |
|||
m_PlayerActionMap_Shoot = m_PlayerActionMap.FindAction("Shoot", throwIfNotFound: true); |
|||
m_PlayerActionMap_Shield = m_PlayerActionMap.FindAction("Shield", throwIfNotFound: true); |
|||
m_PlayerActionMap_RotateBody = m_PlayerActionMap.FindAction("RotateBody", throwIfNotFound: true); |
|||
m_PlayerActionMap_Dash = m_PlayerActionMap.FindAction("Dash", throwIfNotFound: true); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
UnityEngine.Object.Destroy(asset); |
|||
} |
|||
|
|||
public InputBinding? bindingMask |
|||
{ |
|||
get => asset.bindingMask; |
|||
set => asset.bindingMask = value; |
|||
} |
|||
|
|||
public ReadOnlyArray<InputDevice>? devices |
|||
{ |
|||
get => asset.devices; |
|||
set => asset.devices = value; |
|||
} |
|||
|
|||
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes; |
|||
|
|||
public bool Contains(InputAction action) |
|||
{ |
|||
return asset.Contains(action); |
|||
} |
|||
|
|||
public IEnumerator<InputAction> GetEnumerator() |
|||
{ |
|||
return asset.GetEnumerator(); |
|||
} |
|||
|
|||
IEnumerator IEnumerable.GetEnumerator() |
|||
{ |
|||
return GetEnumerator(); |
|||
} |
|||
|
|||
public void Enable() |
|||
{ |
|||
asset.Enable(); |
|||
} |
|||
|
|||
public void Disable() |
|||
{ |
|||
asset.Disable(); |
|||
} |
|||
|
|||
// Player Action Map
|
|||
private readonly InputActionMap m_PlayerActionMap; |
|||
private IPlayerActionMapActions m_PlayerActionMapActionsCallbackInterface; |
|||
private readonly InputAction m_PlayerActionMap_Walk; |
|||
private readonly InputAction m_PlayerActionMap_DashLeft; |
|||
private readonly InputAction m_PlayerActionMap_DashRight; |
|||
private readonly InputAction m_PlayerActionMap_Jump; |
|||
private readonly InputAction m_PlayerActionMap_Shoot; |
|||
private readonly InputAction m_PlayerActionMap_Shield; |
|||
private readonly InputAction m_PlayerActionMap_RotateBody; |
|||
private readonly InputAction m_PlayerActionMap_Dash; |
|||
public struct PlayerActionMapActions |
|||
{ |
|||
private @FPSPlayerInputActions m_Wrapper; |
|||
public PlayerActionMapActions(@FPSPlayerInputActions wrapper) { m_Wrapper = wrapper; } |
|||
public InputAction @Walk => m_Wrapper.m_PlayerActionMap_Walk; |
|||
public InputAction @DashLeft => m_Wrapper.m_PlayerActionMap_DashLeft; |
|||
public InputAction @DashRight => m_Wrapper.m_PlayerActionMap_DashRight; |
|||
public InputAction @Jump => m_Wrapper.m_PlayerActionMap_Jump; |
|||
public InputAction @Shoot => m_Wrapper.m_PlayerActionMap_Shoot; |
|||
public InputAction @Shield => m_Wrapper.m_PlayerActionMap_Shield; |
|||
public InputAction @RotateBody => m_Wrapper.m_PlayerActionMap_RotateBody; |
|||
public InputAction @Dash => m_Wrapper.m_PlayerActionMap_Dash; |
|||
public InputActionMap Get() { return m_Wrapper.m_PlayerActionMap; } |
|||
public void Enable() { Get().Enable(); } |
|||
public void Disable() { Get().Disable(); } |
|||
public bool enabled => Get().enabled; |
|||
public static implicit operator InputActionMap(PlayerActionMapActions set) { return set.Get(); } |
|||
public void SetCallbacks(IPlayerActionMapActions instance) |
|||
{ |
|||
if (m_Wrapper.m_PlayerActionMapActionsCallbackInterface != null) |
|||
{ |
|||
@Walk.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnWalk; |
|||
@Walk.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnWalk; |
|||
@Walk.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnWalk; |
|||
@DashLeft.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashLeft; |
|||
@DashLeft.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashLeft; |
|||
@DashLeft.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashLeft; |
|||
@DashRight.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashRight; |
|||
@DashRight.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashRight; |
|||
@DashRight.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDashRight; |
|||
@Jump.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnJump; |
|||
@Jump.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnJump; |
|||
@Jump.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnJump; |
|||
@Shoot.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShoot; |
|||
@Shoot.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShoot; |
|||
@Shoot.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShoot; |
|||
@Shield.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShield; |
|||
@Shield.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShield; |
|||
@Shield.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnShield; |
|||
@RotateBody.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotateBody; |
|||
@RotateBody.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotateBody; |
|||
@RotateBody.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotateBody; |
|||
@Dash.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDash; |
|||
@Dash.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDash; |
|||
@Dash.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnDash; |
|||
} |
|||
m_Wrapper.m_PlayerActionMapActionsCallbackInterface = instance; |
|||
if (instance != null) |
|||
{ |
|||
@Walk.started += instance.OnWalk; |
|||
@Walk.performed += instance.OnWalk; |
|||
@Walk.canceled += instance.OnWalk; |
|||
@DashLeft.started += instance.OnDashLeft; |
|||
@DashLeft.performed += instance.OnDashLeft; |
|||
@DashLeft.canceled += instance.OnDashLeft; |
|||
@DashRight.started += instance.OnDashRight; |
|||
@DashRight.performed += instance.OnDashRight; |
|||
@DashRight.canceled += instance.OnDashRight; |
|||
@Jump.started += instance.OnJump; |
|||
@Jump.performed += instance.OnJump; |
|||
@Jump.canceled += instance.OnJump; |
|||
@Shoot.started += instance.OnShoot; |
|||
@Shoot.performed += instance.OnShoot; |
|||
@Shoot.canceled += instance.OnShoot; |
|||
@Shield.started += instance.OnShield; |
|||
@Shield.performed += instance.OnShield; |
|||
@Shield.canceled += instance.OnShield; |
|||
@RotateBody.started += instance.OnRotateBody; |
|||
@RotateBody.performed += instance.OnRotateBody; |
|||
@RotateBody.canceled += instance.OnRotateBody; |
|||
@Dash.started += instance.OnDash; |
|||
@Dash.performed += instance.OnDash; |
|||
@Dash.canceled += instance.OnDash; |
|||
} |
|||
} |
|||
} |
|||
public PlayerActionMapActions @PlayerActionMap => new PlayerActionMapActions(this); |
|||
public interface IPlayerActionMapActions |
|||
{ |
|||
void OnWalk(InputAction.CallbackContext context); |
|||
void OnDashLeft(InputAction.CallbackContext context); |
|||
void OnDashRight(InputAction.CallbackContext context); |
|||
void OnJump(InputAction.CallbackContext context); |
|||
void OnShoot(InputAction.CallbackContext context); |
|||
void OnShield(InputAction.CallbackContext context); |
|||
void OnRotateBody(InputAction.CallbackContext context); |
|||
void OnDash(InputAction.CallbackContext context); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b0d62386793014275b4e214b4afdf539 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue