diff --git a/Assets/ML-Agents/Timers/Greatest_map_ever_timers.json b/Assets/ML-Agents/Timers/Greatest_map_ever_timers.json index 3ed5e46..9a97eb3 100644 --- a/Assets/ML-Agents/Timers/Greatest_map_ever_timers.json +++ b/Assets/ML-Agents/Timers/Greatest_map_ever_timers.json @@ -1 +1 @@ -{"count":1,"self":16.677081599999998,"total":16.6850819,"children":{"InitializeActuators":{"count":1,"self":0.0020011,"total":0.0020011,"children":null},"InitializeSensors":{"count":1,"self":0.0019998,"total":0.0019998,"children":null},"AgentSendState":{"count":1,"self":0.0020001,"total":0.0030001,"children":{"CollectObservations":{"count":1,"self":0.001,"total":0.001,"children":null}}}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1650121997","unity_version":"2019.4.35f1","command_line_arguments":"C:\\Program Files\\unityeditorfolder\\2019.4.35f1\\Editor\\Unity.exe -projectpath F:\\SigmaRiskManagment\\real shooter Git Version -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-BipJTP5Uk-fN-2Lss2TUJ -hubSessionId a1fe6f50-bcbd-11ec-b648-df8ff5c97a4c -accessToken K_G64_ace_5LgpX3riGrgGS92ESag4RH04Ti1lswMX8009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Greatest_map_ever","end_time_seconds":"1650122013"}} \ No newline at end of file +{"count":1,"self":16.593504,"total":17.166309,"children":{"InitializeActuators":{"count":2,"self":0.0019996,"total":0.0019996,"children":null},"InitializeSensors":{"count":2,"self":0.0030004,"total":0.0030004,"children":null},"AgentSendState":{"count":612,"self":0.016998,"total":0.549809,"children":{"CollectObservations":{"count":1224,"self":0.0230042,"total":0.0230042,"children":null},"WriteActionMask":{"count":1224,"self":0.0060088,"total":0.0060088,"children":null},"RequestDecision":{"count":1224,"self":0.503798,"total":0.503798,"children":null}}},"DecideAction":{"count":612,"self":0.0089991,"total":0.0089991,"children":null},"AgentAct":{"count":612,"self":0.006997,"total":0.006997,"children":null}},"gauges":{"My Behavior.CumulativeReward":{"count":14,"max":0,"min":0,"runningAverage":0,"value":0,"weightedAverage":0}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1650253950","unity_version":"2019.4.35f1","command_line_arguments":"C:\\Program Files\\unityeditorfolder\\2019.4.35f1\\Editor\\Unity.exe -projectpath F:\\SigmaRiskManagment\\real shooter Git Version -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-1IWpvtxiu_rvPpHhMWpzt -hubSessionId b1d8b690-be9f-11ec-92bc-6fd1276b6775 -accessToken D1AF5mitRE4Vh3s6p7rpmGuqcqvTsZJKmoGtSNfyNNs009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Greatest_map_ever","end_time_seconds":"1650253967"}} \ No newline at end of file diff --git a/Assets/Prefabs/Bot.prefab b/Assets/Prefabs/Bot.prefab index c15183f..eedbf35 100755 --- a/Assets/Prefabs/Bot.prefab +++ b/Assets/Prefabs/Bot.prefab @@ -17,6 +17,7 @@ GameObject: - component: {fileID: 2676446634235362783} - component: {fileID: 8656710265340117963} - component: {fileID: 778652956973742106} + - component: {fileID: 1208561866453126566} m_Layer: 0 m_Name: Bot m_TagString: Untagged @@ -115,7 +116,6 @@ MonoBehaviour: maxStep: 0 hasUpgradedFromAgentParameters: 1 MaxStep: 100 - moveController: {fileID: 778652956973742106} --- !u!114 &7805954453358028498 MonoBehaviour: m_ObjectHideFlags: 0 @@ -195,3 +195,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: navMeshAgent: {fileID: 8656710265340117963} +--- !u!114 &1208561866453126566 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2988578997639256874} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dd8012d5925524537b27131fef517017, type: 3} + m_Name: + m_EditorClassIdentifier: + m_SensorName: BufferSensor + m_ObservableSize: 5 + m_MaxNumObservables: 512 diff --git a/Assets/Scripts/Bots/CharacterFactory.cs b/Assets/Scripts/Bots/CharacterFactory.cs index 0e8ef59..e2c8be3 100644 --- a/Assets/Scripts/Bots/CharacterFactory.cs +++ b/Assets/Scripts/Bots/CharacterFactory.cs @@ -12,7 +12,8 @@ public class CharacterFactory : MonoBehaviour [SerializeField] private GameObject AIPrefab; [SerializeField] private GameObject PlayerPrefab; - private List Players; + private List Bots = new List(); + private GameObject Player; private void Awake() { @@ -44,6 +45,8 @@ public class CharacterFactory : MonoBehaviour if (humanDef == 1) InstanciateEntity(Team.Defenders, TypeAI.HumanAI, spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]); + + GameManager.OnResetScene += ResetCharacters; } private void InstanciateEntity(Team team, TypeAI typeAi, NavPoint spawnPoint) @@ -52,8 +55,40 @@ public class CharacterFactory : MonoBehaviour typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab, spawnPoint.position, Quaternion.identity); - - var character = gameObject.GetComponent(); - character.GetCharacter.Team = team; + gameobject.SetActive(true); + + if (typeAi == TypeAI.HumanAI) + { + gameobject.GetComponent().GetCharacter.Team = team; + Player = gameobject; + } + else + { + gameobject.GetComponent().GetCharacter.Team = team; + gameobject.GetComponent().currentPosition = spawnPoint; + Bots.Add(gameobject); + } + } + + private void ResetCharacters() + { + foreach (var bot in Bots) + { + var npc = bot.GetComponent(); + npc.ResetCharacter(); + if (npc.GetCharacter.Team == Team.Attackers) + bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position; + else + bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position; + } + var player = Player.GetComponent(); + if (player != null) + { + player.ResetCharacter(); + if (player.GetCharacter.Team == Team.Attackers) + Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position; + else + Player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Character/Character.cs b/Assets/Scripts/Character/Character.cs index a229718..50e7313 100644 --- a/Assets/Scripts/Character/Character.cs +++ b/Assets/Scripts/Character/Character.cs @@ -7,13 +7,9 @@ public class Character public Character() { + Debug.Log("init"); Condition = new CharacterCondition(); } - - public void ResetCharacter() - { - - } } public interface ICharacter diff --git a/Assets/Scripts/Character/MovementController.cs b/Assets/Scripts/Character/MovementController.cs index 387a805..20e1026 100644 --- a/Assets/Scripts/Character/MovementController.cs +++ b/Assets/Scripts/Character/MovementController.cs @@ -6,12 +6,12 @@ using UnityEngine.AI; [RequireComponent(typeof(NavMeshAgent))] public class MovementController : MonoBehaviour { - public NavPoint currentPosition { get; private set; } + public NavPoint currentPosition { get; set; } [SerializeField] private NavMeshAgent navMeshAgent; private void Start() { - navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed; + navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed; } public void MoveToRandomPoint() @@ -23,7 +23,7 @@ public class MovementController : MonoBehaviour public List getPointsCandidate() { return MapManager.navPoints - .Where(point => (currentPosition.position - point.position).magnitude <= SettingsReader.Instance.GetSettings.movementSpeed) + .Where(point => (currentPosition.position - point.position).magnitude < SettingsReader.Instance.GetSettings.movementSpeed) .ToList(); } diff --git a/Assets/Scripts/Character/NPC.cs b/Assets/Scripts/Character/NPC.cs index 6ff8f6d..1069d42 100644 --- a/Assets/Scripts/Character/NPC.cs +++ b/Assets/Scripts/Character/NPC.cs @@ -32,21 +32,21 @@ public class NPC : Agent, ICharacter AgentCharacter = new Character(); Condition = AgentCharacter.Condition; - } - private void Start() - { - AgentCharacter = new Character(); - Condition = AgentCharacter.Condition; moveController = gameObject.GetComponent(); bufferSensor = gameObject.GetComponent(); + } + - GameManager.OnResetScene += AgentCharacter.ResetCharacter; + public void ResetCharacter() + { + Condition = new CharacterCondition(); + EndEpisode(); } public override void OnEpisodeBegin() - { - + { + NPC_State = DirectState; } public override void CollectObservations(VectorSensor sensor) @@ -56,12 +56,9 @@ public class NPC : Agent, ICharacter sensor.AddObservation(Condition.Ammunition); sensor.AddObservation((int)NPC_State.State); - - var candidates = moveController.getPointsCandidate(); foreach (var point in candidates) { - bufferSensor.AppendObservation(new float[] { //1 position in navpointId (float)moveController.currentPosition.PointId, diff --git a/Assets/Scripts/Character/NPC.cs.meta b/Assets/Scripts/Character/NPC.cs.meta index 2ef6c68..232a1c0 100755 --- a/Assets/Scripts/Character/NPC.cs.meta +++ b/Assets/Scripts/Character/NPC.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: 200 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Character/Player.cs b/Assets/Scripts/Character/Player.cs index 53ddb64..e593f51 100644 --- a/Assets/Scripts/Character/Player.cs +++ b/Assets/Scripts/Character/Player.cs @@ -9,11 +9,15 @@ public class Player : MonoBehaviour, ICharacter public Character GetCharacter => PlayerCharacter; - private void Start() + private void Awake() { PlayerCharacter = new Character(); Condition = PlayerCharacter.Condition; - GameManager.OnResetScene += PlayerCharacter.ResetCharacter; + } + + public void ResetCharacter() + { + Condition = new CharacterCondition(); } public event Action OnKilledEvent; diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index bdbc7bc..54d1e1d 100755 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -1,5 +1,6 @@ using Unity.MLAgents; using UnityEngine; +using System; public class GameManager : MonoBehaviour { @@ -19,6 +20,8 @@ public class GameManager : MonoBehaviour private void Start() { + Academy.Instance.OnEnvironmentReset += ResetScene; + GlobalEventManager.onCaptureFlag += flagCaptured; GlobalEventManager.onTimeLeft += timeOut; @@ -77,4 +80,11 @@ public class GameManager : MonoBehaviour GlobalEventManager.onCaptureFlag -= flagCaptured; GlobalEventManager.onTimeLeft -= timeOut; } + + public static event Action OnResetScene; + private void ResetScene() + { + Debug.Log("Scene Reset"); + OnResetScene?.Invoke(); + } } diff --git a/Assets/Scripts/Pickups/AmmoPickUp.cs b/Assets/Scripts/Pickups/AmmoPickUp.cs index dffb264..506598d 100755 --- a/Assets/Scripts/Pickups/AmmoPickUp.cs +++ b/Assets/Scripts/Pickups/AmmoPickUp.cs @@ -13,7 +13,7 @@ public class AmmoPickUp : MonoBehaviour, IPickable public void PickObject(GameObject obj) { - obj.GetComponent()?.TakeAmmo(SettingsReader.Instance.GetSettings.ammunitionPickupAmount); + obj.GetComponent()?.GetCharacter.Condition.TakeAmmo(SettingsReader.Instance.GetSettings.ammunitionPickupAmount); gameObject.SetActive(false); } } diff --git a/Assets/Scripts/Pickups/ArmourPickUp.cs b/Assets/Scripts/Pickups/ArmourPickUp.cs index 075896c..86be289 100755 --- a/Assets/Scripts/Pickups/ArmourPickUp.cs +++ b/Assets/Scripts/Pickups/ArmourPickUp.cs @@ -13,7 +13,7 @@ public class ArmourPickUp : MonoBehaviour, IPickable public void PickObject(GameObject obj) { - obj.GetComponent()?.GiveArmour(SettingsReader.Instance.GetSettings.armourPickupAmount); + obj.GetComponent()?.GetCharacter.Condition.GiveArmour(SettingsReader.Instance.GetSettings.armourPickupAmount); gameObject.SetActive(false); } } diff --git a/Assets/Scripts/Pickups/HealthPickUp.cs b/Assets/Scripts/Pickups/HealthPickUp.cs index a3fffb4..f92345a 100755 --- a/Assets/Scripts/Pickups/HealthPickUp.cs +++ b/Assets/Scripts/Pickups/HealthPickUp.cs @@ -13,7 +13,7 @@ public class HealthPickUp : MonoBehaviour, IPickable public void PickObject(GameObject obj) { - obj.GetComponent()?.GiveHealth(SettingsReader.Instance.GetSettings.healthPickupAmount); + obj.GetComponent()?.GetCharacter.Condition.GiveHealth(SettingsReader.Instance.GetSettings.healthPickupAmount); gameObject.SetActive(false); } }