files add
This commit is contained in:
@ -9,27 +9,28 @@ public class MovementController : MonoBehaviour
|
||||
public int PointStartID { get; set; }
|
||||
public int PointEndID { get; private set; }
|
||||
public float FlagDistance { get; private set; }
|
||||
private const float updateFlagPositionDelay = 5;
|
||||
private const float updateReachedDestinationDelay = 5;
|
||||
private const float UpdateFlagPositionDelay = 5;
|
||||
private const float UpdateReachedDestinationDelay = 5;
|
||||
|
||||
[SerializeField] private NavMeshAgent navMeshAgent;
|
||||
[SerializeField] private GameObject flag;
|
||||
public float DistanceToGo { get; private set; }
|
||||
public float RemainingDistance => navMeshAgent.remainingDistance;
|
||||
private Dictionary<int, NavPoint> idNavPointDict;
|
||||
private Dictionary<int, NavPoint> _idNavPointDict;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||
idNavPointDict = MapManager.IDToNavPoint;
|
||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
|
||||
InvokeRepeating(nameof(ReachedDestination), 0, updateReachedDestinationDelay);
|
||||
_idNavPointDict = MapManager.Instance.IDToNavPoint;
|
||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, UpdateFlagPositionDelay);
|
||||
InvokeRepeating(nameof(ReachedDestination), 0, UpdateReachedDestinationDelay);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CancelInvoke(nameof(UpdateFlagPosition));
|
||||
CancelInvoke(nameof(ReachedDestination));
|
||||
}
|
||||
|
||||
private void UpdateFlagPosition()
|
||||
@ -39,14 +40,14 @@ public class MovementController : MonoBehaviour
|
||||
|
||||
public void MoveToRandomPoint()
|
||||
{
|
||||
GoToNextNavPoint(MapManager.NavPoints[Random.Range(0, MapManager.NavPoints.Count)]);
|
||||
GoToNextNavPoint(MapManager.Instance.NavPoints[Random.Range(0, MapManager.Instance.NavPoints.Count)]);
|
||||
}
|
||||
|
||||
public List<NavPoint> GetPointsCandidate()
|
||||
{
|
||||
return MapManager.NavPoints
|
||||
return MapManager.Instance.NavPoints
|
||||
.Where(point =>
|
||||
(idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
(_idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ public class MovementController : MonoBehaviour
|
||||
public void ReturnToStartPoint()
|
||||
{
|
||||
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
|
||||
navMeshAgent.SetDestination(idNavPointDict[PointStartID].Position);
|
||||
navMeshAgent.SetDestination(_idNavPointDict[PointStartID].Position);
|
||||
PointEndID = PointStartID;
|
||||
PointStartID = -1;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using Unity.MLAgents.Actuators;
|
||||
using Unity.MLAgents.Sensors;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MovementController),typeof(BufferSensor))]
|
||||
[RequireComponent(typeof(MovementController),typeof(BufferSensorComponent))]
|
||||
public class NPC : Agent, ICharacter
|
||||
{
|
||||
[HideInInspector]
|
||||
@ -47,12 +47,12 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
moveController = gameObject.GetComponent<MovementController>();
|
||||
bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
|
||||
|
||||
|
||||
flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||
if (flagZone == null)
|
||||
Debug.LogError("Flag Is Not Setted");
|
||||
|
||||
navPointIdDict = MapManager.IDToNavPoint;
|
||||
if (flagZone is null)
|
||||
Debug.LogError("Flag Is Not Set");
|
||||
|
||||
navPointIdDict = MapManager.Instance.IDToNavPoint;
|
||||
if (navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
}
|
||||
@ -64,12 +64,18 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
if (navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
|
||||
NpcState = DirectState;
|
||||
flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||
}
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
navPointIdDict = MapManager.Instance.IDToNavPoint;
|
||||
if (navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
var candidates = moveController.GetPointsCandidate();
|
||||
|
||||
//common sensors
|
||||
@ -93,13 +99,14 @@ public class NPC : Agent, ICharacter
|
||||
//point sensors
|
||||
foreach (var point in candidates)
|
||||
{
|
||||
var position = transform.position;
|
||||
bufferSensor.AppendObservation(new float[] {
|
||||
point.DeathAttr,
|
||||
(int)point.navType,
|
||||
//4 flagEnemyDistance
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position).ToInt(),
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, position).ToInt(),
|
||||
//5 EnemyVsNavPointDistance
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team.GetOppositeTeam()).ToInt(),
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point, position, AgentCharacter.Team.GetOppositeTeam()).ToInt(),
|
||||
//6 Have been seen by enemy in this point
|
||||
GameManager.IsHaveSeenByEnemy(AgentCharacter.Team.GetOppositeTeam(),
|
||||
point.Position).ToInt()
|
||||
@ -165,11 +172,12 @@ public class NPC : Agent, ICharacter
|
||||
}
|
||||
|
||||
public event Action<int, Team> OnDamageRecieved;
|
||||
public void GetDamage(float damage)
|
||||
public void GetDamage(int damage)
|
||||
{
|
||||
AgentCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||
Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
|
||||
Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
|
||||
OnDamageRecieved?.Invoke(damage, AgentCharacter.Team);
|
||||
|
||||
if (Condition.HealthPoints < 0)
|
||||
{
|
||||
|
@ -24,7 +24,6 @@ public class GameManager : MonoBehaviour
|
||||
private void Start()
|
||||
{
|
||||
Academy.Instance.OnEnvironmentReset += ResetScene;
|
||||
|
||||
GlobalEventManager.OnCaptureFlag += FlagCaptured;
|
||||
GlobalEventManager.OnTimeLeft += TimeOut;
|
||||
|
||||
|
@ -3,36 +3,36 @@ using UnityEngine;
|
||||
|
||||
public class MapManager : MonoBehaviour
|
||||
{
|
||||
private static MapManager instance;
|
||||
public static MapManager Instance => instance;
|
||||
[SerializeField] static List<NavPoint> _navPoints;
|
||||
public static List<NavPoint> NavPoints { get => _navPoints; private set => _navPoints = value; }
|
||||
public static Dictionary<int, NavPoint> IDToNavPoint {get; private set; }
|
||||
private static MapManager _instance;
|
||||
public static MapManager Instance => _instance;
|
||||
[SerializeField] private List<NavPoint> _navPoints;
|
||||
public List<NavPoint> NavPoints { get => _navPoints; private set => _navPoints = value; }
|
||||
public Dictionary<int, NavPoint> IDToNavPoint {get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance is null)
|
||||
instance = this;
|
||||
if (_instance is null)
|
||||
_instance = this;
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
Debug.LogError("Only 1 Instance");
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
NavPoints = new List<NavPoint>();
|
||||
var navPointSet = GameObject.Find("NavPoint Set");
|
||||
var count = navPointSet.transform.childCount;
|
||||
for (int i=0; i < count; i++)
|
||||
for (var i=0; i < count; i++)
|
||||
NavPoints.Add(navPointSet.transform.GetChild(i)
|
||||
.gameObject.GetComponent<NavPoint>());
|
||||
|
||||
print(NavPoints.Count);
|
||||
NavPointSetToID();
|
||||
}
|
||||
|
||||
|
||||
private void NavPointSetToID()
|
||||
{
|
||||
IDToNavPoint = new Dictionary<int, NavPoint>();
|
||||
int i = 0;
|
||||
foreach (var navPoint in NavPoints)
|
||||
{
|
||||
@ -45,8 +45,8 @@ public class MapManager : MonoBehaviour
|
||||
public static void AddDeathAttributeToPoints(int startPoint, int endPoint,
|
||||
float allDistance, float remainingDistance)
|
||||
{
|
||||
var startNavPoint = IDToNavPoint[startPoint];
|
||||
var endNavPoint = IDToNavPoint[endPoint];
|
||||
var startNavPoint = _instance.IDToNavPoint[startPoint];
|
||||
var endNavPoint = _instance.IDToNavPoint[endPoint];
|
||||
float coef;
|
||||
try
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 300
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
Reference in New Issue
Block a user