浏览代码

added heuristic ai spawn

/hh-develop-fps_game_project
HH 4 年前
当前提交
31bdedb6
共有 12 个文件被更改,包括 3025 次插入14 次删除
  1. 31
      Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.cs
  2. 21
      Project/Assets/ML-Agents/Examples/FPS_Game/Input/FPSPlayerInputActions.inputactions
  3. 889
      Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
  4. 6
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentHealth.cs
  5. 58
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/GameController.cs
  6. 13
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/PlayerAIHeuristic.cs
  7. 2
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/Projectile.cs
  8. 2
      Project/ProjectSettings/DynamicsManager.asset
  9. 1001
      Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent_AI.prefab
  10. 7
      Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent_AI.prefab.meta
  11. 1001
      Project/Assets/New Terrain.asset
  12. 8
      Project/Assets/New Terrain.asset.meta

31
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"": ""319796b1-6071-46f0-81dc-58b6bdb7d86a"",
""path"": ""<Gamepad>/leftTrigger"",
""interactions"": ""Press"",
""interactions"": ""Press(pressPoint=0.75)"",
""processors"": """",
""groups"": """",
""action"": ""Dash"",

""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
}
]
}

m_PlayerActionMap_RotateBody = m_PlayerActionMap.FindAction("RotateBody", throwIfNotFound: true);
m_PlayerActionMap_Dash = m_PlayerActionMap.FindAction("Dash", throwIfNotFound: true);
m_PlayerActionMap_Rotate = m_PlayerActionMap.FindAction("Rotate", throwIfNotFound: true);
m_PlayerActionMap_Restart = m_PlayerActionMap.FindAction("Restart", throwIfNotFound: true);
}
public void Dispose()

private readonly InputAction m_PlayerActionMap_RotateBody;
private readonly InputAction m_PlayerActionMap_Dash;
private readonly InputAction m_PlayerActionMap_Rotate;
private readonly InputAction m_PlayerActionMap_Restart;
public struct PlayerActionMapActions
{
private @FPSPlayerInputActions m_Wrapper;

public InputAction @RotateBody => m_Wrapper.m_PlayerActionMap_RotateBody;
public InputAction @Dash => m_Wrapper.m_PlayerActionMap_Dash;
public InputAction @Rotate => m_Wrapper.m_PlayerActionMap_Rotate;
public InputAction @Restart => m_Wrapper.m_PlayerActionMap_Restart;
public InputActionMap Get() { return m_Wrapper.m_PlayerActionMap; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }

@Rotate.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotate;
@Rotate.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotate;
@Rotate.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRotate;
@Restart.started -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRestart;
@Restart.performed -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRestart;
@Restart.canceled -= m_Wrapper.m_PlayerActionMapActionsCallbackInterface.OnRestart;
}
m_Wrapper.m_PlayerActionMapActionsCallbackInterface = 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;
}
}
}

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

21
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": "319796b1-6071-46f0-81dc-58b6bdb7d86a",
"path": "<Gamepad>/leftTrigger",
"interactions": "Press",
"interactions": "Press(pressPoint=0.75)",
"processors": "",
"groups": "",
"action": "Dash",

"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
}
]
}

889
Project/Assets/ML-Agents/Examples/FPS_Game/Scenes/FPS_Game.unity
文件差异内容过多而无法显示
查看文件

6
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/AgentHealth.cs


{
GameController = FindObjectOfType<GameController>();
CurrentPercentage = 100;
UISlider.value = CurrentPercentage;
if (UISlider)
{
UISlider.value = CurrentPercentage;
}
if (bodyMesh)
{
startingColor = bodyMesh.sharedMaterial.color;

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


using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using Random = UnityEngine.Random;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour
{
[Header("GLOBAL SETTINGS")]

public bool triggerExplosion;
[Header("SPAWN POINTS")] public GameObject BlueSpawn;
public GameObject PurpleSpawn;
[Header("PLAYER PREFABS")]
public GameObject PlayerPrefab;
public GameObject AIPrefab;
public GameObject AITarget;
public Transform SpawnPlatform;
public int NumberOfEnemiesToSpawn = 3;
public enum PlayerType
{
Player, AI_Heuristic, AI_Agent
}
public enum GameMode
{
SinglePlayer, PVP_Single

// Start is called before the first frame update
void Awake()
{
if (PlayerPrefab && BlueSpawn)
{
var randomPos = Random.insideUnitSphere * 3;
randomPos.y = 0;
var go = Instantiate(PlayerPrefab, BlueSpawn.transform.position + randomPos, quaternion.identity);
go.SetActive(true);
AITarget = go;
}
if (AIPrefab && PurpleSpawn)
{
var randomPos = Random.insideUnitSphere * 5;
randomPos.y = 0;
var go = Instantiate(AIPrefab, PurpleSpawn.transform.position + randomPos, quaternion.identity);
go.SetActive(true);
}
for (int i = 0; i < NumberOfEnemiesToSpawn; i++)
{
if (AIPrefab && PurpleSpawn)
{
var randomPos = Random.insideUnitSphere * 40;
randomPos.y = 3;
var go = Instantiate(AIPrefab, SpawnPlatform.position + randomPos, quaternion.identity);
go.SetActive(true);
}
}
Rigidbody[] rbs = Resources.FindObjectsOfTypeAll<Rigidbody>();
foreach (var rb in rbs)

triggerExplosion = false;
AddExplosiveForcesToAllRB(transform.position);
}
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
void SetupPlayer()
{
}

13
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/PlayerAIHeuristic.cs


private AgentHealth agentHealth;
private MultiGunAlternating multiGunController;
private GameController gameController;
void Start()
void Awake()
gameController = FindObjectOfType<GameController>();
if (!target)
{
target = gameController.AITarget.transform;
}
canCurrentlySeeTarget = false;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, 50))

if (agentHealth && agentHealth.Dead)
{
return;
}
if (!target)
{
target = gameController.AITarget.transform;
}
Vector3 randomJitter = Random.insideUnitSphere * RandomRotationJitter;
randomJitter.y = 0;

2
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/Projectile.cs


if (aliveTime > pauseCollisionDetectionWaitTime)
{
selfDestructNow = true;
SelfDestruct();
}
foreach (var item in impactParticlePool.poolList)

2
Project/ProjectSettings/DynamicsManager.asset


m_EnableEnhancedDeterminism: 1
m_EnableUnifiedHeightmaps: 1
m_SolverType: 0
m_DefaultMaxAngularSpeed: 7
m_DefaultMaxAngularSpeed: 25

1001
Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent_AI.prefab
文件差异内容过多而无法显示
查看文件

7
Project/Assets/ML-Agents/Examples/FPS_Game/Prefabs/FPSAgent_AI.prefab.meta


fileFormatVersion: 2
guid: 6a2f6d60e715b493dad52cc5c9fd1e71
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/New Terrain.asset
文件差异内容过多而无法显示
查看文件

8
Project/Assets/New Terrain.asset.meta


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