kirill loh
This commit is contained in:
@ -12,7 +12,8 @@ public class CharacterFactory : MonoBehaviour
|
||||
[SerializeField] private GameObject AIPrefab;
|
||||
[SerializeField] private GameObject PlayerPrefab;
|
||||
|
||||
private List<GameObject> Players;
|
||||
private List<GameObject> Bots = new List<GameObject>();
|
||||
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<ICharacter>();
|
||||
character.GetCharacter.Team = team;
|
||||
gameobject.SetActive(true);
|
||||
|
||||
if (typeAi == TypeAI.HumanAI)
|
||||
{
|
||||
gameobject.GetComponent<Player>().GetCharacter.Team = team;
|
||||
Player = gameobject;
|
||||
}
|
||||
else
|
||||
{
|
||||
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
|
||||
gameobject.GetComponent<MovementController>().currentPosition = spawnPoint;
|
||||
Bots.Add(gameobject);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCharacters()
|
||||
{
|
||||
foreach (var bot in Bots)
|
||||
{
|
||||
var npc = bot.GetComponent<NPC>();
|
||||
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<Player>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,13 +7,9 @@ public class Character
|
||||
|
||||
public Character()
|
||||
{
|
||||
Debug.Log("init");
|
||||
Condition = new CharacterCondition();
|
||||
}
|
||||
|
||||
public void ResetCharacter()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICharacter
|
||||
|
@ -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<NavPoint> 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();
|
||||
}
|
||||
|
||||
|
@ -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<MovementController>();
|
||||
bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
|
2
Assets/Scripts/Character/NPC.cs.meta
generated
2
Assets/Scripts/Character/NPC.cs.meta
generated
@ -4,7 +4,7 @@ MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: 200
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
@ -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<object> OnKilledEvent;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class AmmoPickUp : MonoBehaviour, IPickable
|
||||
|
||||
public void PickObject(GameObject obj)
|
||||
{
|
||||
obj.GetComponent<CharacterCondition>()?.TakeAmmo(SettingsReader.Instance.GetSettings.ammunitionPickupAmount);
|
||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.TakeAmmo(SettingsReader.Instance.GetSettings.ammunitionPickupAmount);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class ArmourPickUp : MonoBehaviour, IPickable
|
||||
|
||||
public void PickObject(GameObject obj)
|
||||
{
|
||||
obj.GetComponent<CharacterCondition>()?.GiveArmour(SettingsReader.Instance.GetSettings.armourPickupAmount);
|
||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveArmour(SettingsReader.Instance.GetSettings.armourPickupAmount);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class HealthPickUp : MonoBehaviour, IPickable
|
||||
|
||||
public void PickObject(GameObject obj)
|
||||
{
|
||||
obj.GetComponent<CharacterCondition>()?.GiveHealth(SettingsReader.Instance.GetSettings.healthPickupAmount);
|
||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveHealth(SettingsReader.Instance.GetSettings.healthPickupAmount);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user