浏览代码

update restart logic

/hh-develop-fps_game_project
HH 4 年前
当前提交
a26b341f
共有 8 个文件被更改,包括 193 次插入77 次删除
  1. 8
      Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSAgentInput.cs
  2. 71
      Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.cs
  3. 51
      Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions
  4. 12
      Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent.prefab
  5. 27
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  6. 10
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs
  7. 83
      Project/Assets/ML-Agents/Examples/FPS_Game/Materials/Shield.mat
  8. 8
      Project/Assets/ML-Agents/Examples/FPS_Game/Materials/Shield.mat.meta

8
Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSAgentInput.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
//[ExecuteAlways]
public class FPSAgentInput : MonoBehaviour

// return false;
// }
void Update()
{
if (inputActions.UI.Restart.triggered)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
// Update is called once per frame
void FixedUpdate()

71
Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.cs


""expectedControlType"": ""Axis"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Restart"",
""type"": ""Button"",
""id"": ""82551a02-e3e9-4ef0-92d8-21d784984a6e"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
}
],
""bindings"": [

{
""name"": """",
""id"": ""2b94ae52-9bb0-478e-8e4c-bf6c747a5c7d"",
""path"": ""<Gamepad>/buttonEast"",
""path"": ""<Gamepad>/rightShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",

""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": """",
""id"": ""c63f34c8-a8e5-43b4-ba42-22de1f775994"",
""path"": ""<Keyboard>/r"",
""interactions"": ""Press"",
""processors"": """",
""groups"": """",
""action"": ""Restart"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
},

""name"": ""Controls"",
""type"": ""Button"",
""id"": ""bd885a35-fff9-4afb-a855-24fb9f6006c7"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Restart"",
""type"": ""Button"",
""id"": ""e94117bb-34b9-400e-98a4-5bcdc0e1ef18"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"

""action"": ""Controls"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""3558b9e6-24b3-420a-95a3-0bfd03222ba6"",
""path"": ""<Keyboard>/r"",
""interactions"": ""Press"",
""processors"": """",
""groups"": """",
""action"": ""Restart"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""b3ee58f5-8a7d-40c9-abc6-6694d289683d"",
""path"": ""<Gamepad>/buttonNorth"",
""interactions"": ""Press"",
""processors"": """",
""groups"": """",
""action"": ""Restart"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}

m_Player_RotateBody = m_Player.FindAction("RotateBody", throwIfNotFound: true);
m_Player_Dash = m_Player.FindAction("Dash", throwIfNotFound: true);
m_Player_Rotate = m_Player.FindAction("Rotate", throwIfNotFound: true);
m_Player_Restart = m_Player.FindAction("Restart", throwIfNotFound: true);
m_UI_Restart = m_UI.FindAction("Restart", throwIfNotFound: true);
}
public void Dispose()

private readonly InputAction m_Player_RotateBody;
private readonly InputAction m_Player_Dash;
private readonly InputAction m_Player_Rotate;
private readonly InputAction m_Player_Restart;
public struct PlayerActions
{
private @FPSPlayerInputActions m_Wrapper;

public InputAction @RotateBody => m_Wrapper.m_Player_RotateBody;
public InputAction @Dash => m_Wrapper.m_Player_Dash;
public InputAction @Rotate => m_Wrapper.m_Player_Rotate;
public InputAction @Restart => m_Wrapper.m_Player_Restart;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }

@Rotate.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRotate;
@Rotate.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRotate;
@Rotate.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRotate;
@Restart.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRestart;
@Restart.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRestart;
@Restart.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnRestart;
}
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
if (instance != null)

@Rotate.started += instance.OnRotate;
@Rotate.performed += instance.OnRotate;
@Rotate.canceled += instance.OnRotate;
@Restart.started += instance.OnRestart;
@Restart.performed += instance.OnRestart;
@Restart.canceled += instance.OnRestart;
}
}
}

private readonly InputActionMap m_UI;
private IUIActions m_UIActionsCallbackInterface;
private readonly InputAction m_UI_Controls;
private readonly InputAction m_UI_Restart;
public InputAction @Restart => m_Wrapper.m_UI_Restart;
public InputActionMap Get() { return m_Wrapper.m_UI; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }

@Controls.started -= m_Wrapper.m_UIActionsCallbackInterface.OnControls;
@Controls.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnControls;
@Controls.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnControls;
@Restart.started -= m_Wrapper.m_UIActionsCallbackInterface.OnRestart;
@Restart.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnRestart;
@Restart.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnRestart;
}
m_Wrapper.m_UIActionsCallbackInterface = instance;
if (instance != null)

@Controls.canceled += instance.OnControls;
@Restart.started += instance.OnRestart;
@Restart.performed += instance.OnRestart;
@Restart.canceled += instance.OnRestart;
}
}
}

void OnRotateBody(InputAction.CallbackContext context);
void OnDash(InputAction.CallbackContext context);
void OnRotate(InputAction.CallbackContext context);
void OnRestart(InputAction.CallbackContext context);
void OnRestart(InputAction.CallbackContext context);
}
}

51
Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions


"expectedControlType": "Axis",
"processors": "",
"interactions": ""
},
{
"name": "Restart",
"type": "Button",
"id": "82551a02-e3e9-4ef0-92d8-21d784984a6e",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
}
],
"bindings": [

{
"name": "",
"id": "2b94ae52-9bb0-478e-8e4c-bf6c747a5c7d",
"path": "<Gamepad>/buttonEast",
"path": "<Gamepad>/rightShoulder",
"interactions": "",
"processors": "",
"groups": "",

"action": "Rotate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "c63f34c8-a8e5-43b4-ba42-22de1f775994",
"path": "<Keyboard>/r",
"interactions": "Press",
"processors": "",
"groups": "",
"action": "Restart",
"isComposite": false,
"isPartOfComposite": false
}
]
},

"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "Restart",
"type": "Button",
"id": "e94117bb-34b9-400e-98a4-5bcdc0e1ef18",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
}
],
"bindings": [

"processors": "",
"groups": "",
"action": "Controls",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "3558b9e6-24b3-420a-95a3-0bfd03222ba6",
"path": "<Keyboard>/r",
"interactions": "Press",
"processors": "",
"groups": "",
"action": "Restart",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b3ee58f5-8a7d-40c9-abc6-6694d289683d",
"path": "<Gamepad>/buttonNorth",
"interactions": "Press",
"processors": "",
"groups": "",
"action": "Restart",
"isComposite": false,
"isPartOfComposite": false
}

12
Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent.prefab


m_ActionId: b309ca48-95aa-4032-bd7d-46dcaeb138d0
m_ActionName: Player Action Map/Rotate[/Keyboard/q,/Keyboard/e,/DualShock4GamepadHID/rightStick/left,/DualShock4GamepadHID/rightStick/right]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 82551a02-e3e9-4ef0-92d8-21d784984a6e
m_ActionName: Player Action Map/Restart[/Keyboard/r]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_MethodName: ToggleControlsUI

m_CallState: 2
m_ActionId: bd885a35-fff9-4afb-a855-24fb9f6006c7
m_ActionName: UI/Controls[/Keyboard/c,/XboxOneGampadMacOSWireless/start]
- m_PersistentCalls:
m_Calls: []
m_ActionId: e94117bb-34b9-400e-98a4-5bcdc0e1ef18
m_ActionName: UI/Restart[/Keyboard/r,/XboxOneGampadMacOSWireless/buttonNorth]
m_DefaultActionMap: Player
m_DefaultActionMap: bb797917-97ca-47e1-b3c9-0572380e9376
m_SplitScreenIndex: -1
m_Camera: {fileID: 1828481695}
--- !u!1 &7796409948114465862

m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: ec99cc74da6543b459e71a51834b037d, type: 2}
- {fileID: 2100000, guid: b062486683ec74e22999cf04bb63ee80, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

27
Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity


m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -170.22, y: 25}
m_SizeDelta: {x: 340.4464, y: 50}
m_AnchoredPosition: {x: -334.5, y: 25}
m_SizeDelta: {x: 669.03516, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &58198996
MonoBehaviour:

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Controls - Press C / Select
m_text: 'Controls - Press C / Select || Restart Scene: R / Btn North'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

m_margin: {x: 0, y: 0, z: 0, w: 0}
m_textInfo:
textComponent: {fileID: 58198996}
characterCount: 27
characterCount: 59
spaceCount: 5
wordCount: 5
spaceCount: 12
wordCount: 10
linkCount: 0
lineCount: 1
pageCount: 1

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Btn East: Shield'
m_text: 'RS: Shield'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

m_margin: {x: 0, y: 0, z: 0, w: 0}
m_textInfo:
textComponent: {fileID: 737556610}
characterCount: 16
characterCount: 10
spaceCount: 2
wordCount: 3
spaceCount: 1
wordCount: 2
linkCount: 0
lineCount: 1
pageCount: 1

objectReference: {fileID: 1732295774}
- target: {fileID: 4453630946124038627, guid: a0e7db83e097b4a3e96a89b390d1ebed,
type: 3}
propertyPath: m_ActionEvents.Array.data[8].m_PersistentCalls.m_Calls.Array.data[0].m_Target
propertyPath: m_ActionEvents.Array.data[7].m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 914861360}
- target: {fileID: 6753286230780216836, guid: a0e7db83e097b4a3e96a89b390d1ebed,

type: 3}
propertyPath: m_Name
value: FPSAgent
objectReference: {fileID: 0}
- target: {fileID: 7796409947774005658, guid: a0e7db83e097b4a3e96a89b390d1ebed,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8931083779362434129, guid: a0e7db83e097b4a3e96a89b390d1ebed,
type: 3}

10
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs


AddExplosiveForcesToAllRB(transform.position);
}
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
// if (Input.GetKeyDown(KeyCode.R))
// {
// SceneManager.LoadScene(SceneManager.GetActiveScene().name);
//
// }
}

83
Project/Assets/ML-Agents/Examples/FPS_Game/Materials/Shield.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Shield
m_Shader: {fileID: 45, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0.75
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 0.2}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.103, g: 0.103, b: 0.103, a: 1}

8
Project/Assets/ML-Agents/Examples/FPS_Game/Materials/Shield.mat.meta


fileFormatVersion: 2
guid: b062486683ec74e22999cf04bb63ee80
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存