to new git
This commit is contained in:
@ -1,26 +1,28 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Unity;
|
|
||||||
|
|
||||||
public class CharacterFactory : MonoBehaviour
|
public class CharacterFactory : MonoBehaviour
|
||||||
{
|
{
|
||||||
private CharacterFactory instance;
|
private static CharacterFactory instance;
|
||||||
public CharacterFactory Instance { get { return instance; } }
|
public static CharacterFactory Instance => instance;
|
||||||
|
|
||||||
[SerializeField] private List<NavPoint> spawnPointsForDefendersTeam;
|
[SerializeField] private List<NavPoint> spawnPointsForDefendersTeam;
|
||||||
[SerializeField] private List<NavPoint> spawnPointsForAttackersTeam;
|
[SerializeField] private List<NavPoint> spawnPointsForAttackersTeam;
|
||||||
[SerializeField] private GameObject AIPrefab;
|
[SerializeField] private GameObject AIPrefab;
|
||||||
[SerializeField] private GameObject PlayerPrefab;
|
[SerializeField] private GameObject PlayerPrefab;
|
||||||
|
|
||||||
private List<GameObject> Bots = new List<GameObject>();
|
private List<GameObject> bots = new List<GameObject>();
|
||||||
private GameObject Player;
|
public GameObject player { get; private set; }
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
instance = this;
|
instance = this;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
|
Debug.LogError("Only 1 Instance");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@ -53,7 +55,7 @@ public class CharacterFactory : MonoBehaviour
|
|||||||
{
|
{
|
||||||
var gameobject = GameObject.Instantiate(
|
var gameobject = GameObject.Instantiate(
|
||||||
typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab,
|
typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab,
|
||||||
spawnPoint.position,
|
spawnPoint.Position,
|
||||||
Quaternion.identity);
|
Quaternion.identity);
|
||||||
gameobject.SetActive(true);
|
gameobject.SetActive(true);
|
||||||
if (team == Team.Attackers)
|
if (team == Team.Attackers)
|
||||||
@ -64,35 +66,49 @@ public class CharacterFactory : MonoBehaviour
|
|||||||
if (typeAi == TypeAI.HumanAI)
|
if (typeAi == TypeAI.HumanAI)
|
||||||
{
|
{
|
||||||
gameobject.GetComponent<Player>().GetCharacter.Team = team;
|
gameobject.GetComponent<Player>().GetCharacter.Team = team;
|
||||||
Player = gameobject;
|
player = gameobject;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
|
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
|
||||||
gameobject.GetComponent<MovementController>().CurrentNavPoint = spawnPoint;
|
gameobject.GetComponent<MovementController>().PointStartID = spawnPoint.PointId;
|
||||||
Bots.Add(gameobject);
|
bots.Add(gameobject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReSpawn(ICharacter character, ref Vector3 pos, ref int startPointId)
|
||||||
|
{
|
||||||
|
character.ResetCharacter();
|
||||||
|
var team = character.GetCharacter.Team;
|
||||||
|
NavPoint navPoint;
|
||||||
|
if (team == Team.Attackers)
|
||||||
|
navPoint = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)];
|
||||||
|
else
|
||||||
|
navPoint = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)];
|
||||||
|
|
||||||
|
pos = navPoint.Position;
|
||||||
|
startPointId = navPoint.PointId;
|
||||||
|
}
|
||||||
|
|
||||||
private void ResetCharacters()
|
private void ResetCharacters()
|
||||||
{
|
{
|
||||||
foreach (var bot in Bots)
|
foreach (var bot in bots)
|
||||||
{
|
{
|
||||||
var npc = bot.GetComponent<NPC>();
|
var npc = bot.GetComponent<NPC>();
|
||||||
npc.ResetCharacter();
|
npc.ResetCharacter();
|
||||||
if (npc.GetCharacter.Team == Team.Attackers)
|
if (npc.GetCharacter.Team == Team.Attackers)
|
||||||
bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position;
|
bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||||
else
|
else
|
||||||
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position;
|
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
|
||||||
}
|
}
|
||||||
Player player;
|
Player player;
|
||||||
if (TryGetComponent<Player>(out player))
|
if (TryGetComponent<Player>(out player))
|
||||||
{
|
{
|
||||||
player.ResetCharacter();
|
player.ResetCharacter();
|
||||||
if (player.GetCharacter.Team == Team.Attackers)
|
if (player.GetCharacter.Team == Team.Attackers)
|
||||||
Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position;
|
this.player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||||
else
|
else
|
||||||
Player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position;
|
this.player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,3 +3,14 @@
|
|||||||
Defenders,
|
Defenders,
|
||||||
Attackers,
|
Attackers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TeamExtension
|
||||||
|
{
|
||||||
|
public static Team GetOppositeTeam(this Team team)
|
||||||
|
{
|
||||||
|
if (team == Team.Attackers)
|
||||||
|
return Team.Defenders;
|
||||||
|
else
|
||||||
|
return Team.Attackers;
|
||||||
|
}
|
||||||
|
}
|
@ -7,12 +7,6 @@ public class Character
|
|||||||
|
|
||||||
public Character()
|
public Character()
|
||||||
{
|
{
|
||||||
Debug.Log("init");
|
|
||||||
Condition = new CharacterCondition();
|
Condition = new CharacterCondition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICharacter
|
|
||||||
{
|
|
||||||
Character GetCharacter { get; }
|
|
||||||
}
|
|
@ -45,6 +45,17 @@ public class CharacterCondition
|
|||||||
OnChangeArmourEvent?.Invoke(value);
|
OnChangeArmourEvent?.Invoke(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public int GetArmourPointsInQuantile()
|
||||||
|
{
|
||||||
|
if (armour < 25)
|
||||||
|
return 0;
|
||||||
|
else if (armour < 50)
|
||||||
|
return 1;
|
||||||
|
else if (armour < 75)
|
||||||
|
return 2;
|
||||||
|
else return 3;
|
||||||
|
}
|
||||||
|
|
||||||
private int ammo;
|
private int ammo;
|
||||||
public int Ammunition
|
public int Ammunition
|
||||||
{
|
{
|
||||||
@ -60,6 +71,11 @@ public class CharacterCondition
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CharacterCondition()
|
public CharacterCondition()
|
||||||
|
{
|
||||||
|
this.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
{
|
{
|
||||||
var settings = SettingsReader.Instance.GetSettings;
|
var settings = SettingsReader.Instance.GetSettings;
|
||||||
ammo = settings.MaxAmmo;
|
ammo = settings.MaxAmmo;
|
||||||
|
2
Assets/Scripts/Sensors.meta → Assets/Scripts/Character/Interfaces.meta
generated
Executable file → Normal file
2
Assets/Scripts/Sensors.meta → Assets/Scripts/Character/Interfaces.meta
generated
Executable file → Normal file
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 5e73ba257bc6b684c86edf9ecfd475ef
|
guid: f23b6db3be1e4cd469fd18dfe3e39764
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
5
Assets/Scripts/Character/Interfaces/ICharacter.cs
Normal file
5
Assets/Scripts/Character/Interfaces/ICharacter.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
public interface ICharacter
|
||||||
|
{
|
||||||
|
Character GetCharacter { get; }
|
||||||
|
void ResetCharacter();
|
||||||
|
}
|
2
Assets/Scripts/Sensors/SensorType.cs.meta → Assets/Scripts/Character/Interfaces/ICharacter.cs.meta
generated
Executable file → Normal file
2
Assets/Scripts/Sensors/SensorType.cs.meta → Assets/Scripts/Character/Interfaces/ICharacter.cs.meta
generated
Executable file → Normal file
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8f76201fe6436164789d10350a0fd6e2
|
guid: b6dfb78244ae35c4db1326d5f5b73375
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
17
Assets/Scripts/Character/Interfaces/INpcBaseState.cs
Normal file
17
Assets/Scripts/Character/Interfaces/INpcBaseState.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public interface INpcBaseState
|
||||||
|
{
|
||||||
|
NpcEnumState State { get; }
|
||||||
|
bool InCover { get; }
|
||||||
|
bool IsRunning { get; }
|
||||||
|
bool InDirectPoint { get; }
|
||||||
|
float HitChance { get; }
|
||||||
|
float DoDamageChance { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface INpcBaseBodyState
|
||||||
|
{
|
||||||
|
NpcBodyState State { get; }
|
||||||
|
Vector3 GetPointToHit(GameObject go);
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 4599c57bc5b1c3945847dead0f9f0ba4
|
guid: 58b7e1962495ada4c8e6ee6219c99a20
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@ -1,22 +1,30 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AI;
|
using UnityEngine.AI;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(NavMeshAgent))]
|
[RequireComponent(typeof(NavMeshAgent))]
|
||||||
public class MovementController : MonoBehaviour
|
public class MovementController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public NavPoint CurrentNavPoint { get; set; }
|
public int PointStartID { get; set; }
|
||||||
|
public int PointEndID { get; private set; }
|
||||||
public float FlagDistance { get; private set; }
|
public float FlagDistance { get; private set; }
|
||||||
private GameObject flag;
|
|
||||||
private const float updateFlagPositionDelay = 5;
|
private const float updateFlagPositionDelay = 5;
|
||||||
[SerializeField] private NavMeshAgent navMeshAgent;
|
private const float updateReachedDestinationDelay = 5;
|
||||||
|
|
||||||
private void Start()
|
[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 void Awake()
|
||||||
{
|
{
|
||||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||||
|
idNavPointDict = MapManager.IDToNavPoint;
|
||||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
|
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
|
||||||
|
InvokeRepeating(nameof(ReachedDestination), 0, updateReachedDestinationDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
@ -31,17 +39,45 @@ public class MovementController : MonoBehaviour
|
|||||||
|
|
||||||
public void MoveToRandomPoint()
|
public void MoveToRandomPoint()
|
||||||
{
|
{
|
||||||
Debug.Log(MapManager.navPoints == null);
|
Debug.Log(MapManager.NavPoints == null);
|
||||||
goToNextNavPoint(MapManager.navPoints[Random.Range(0, MapManager.navPoints.Count)]);
|
GoToNextNavPoint(MapManager.NavPoints[Random.Range(0, MapManager.NavPoints.Count)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NavPoint> getPointsCandidate()
|
public List<NavPoint> GetPointsCandidate()
|
||||||
{
|
{
|
||||||
return MapManager.navPoints
|
return MapManager.NavPoints
|
||||||
.Where(point => (CurrentNavPoint.position - point.position).magnitude < SettingsReader.Instance.GetSettings.MovementSpeed)
|
.Where(point =>
|
||||||
|
(idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goToNextNavPoint(NavPoint destination) =>
|
public void GoToNextNavPoint(NavPoint destination)
|
||||||
navMeshAgent.SetDestination(destination.position);
|
{
|
||||||
|
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
|
||||||
|
PointStartID = PointEndID;
|
||||||
|
PointEndID = destination.PointId;
|
||||||
|
navMeshAgent.SetDestination(destination.Position);
|
||||||
|
DistanceToGo = navMeshAgent.remainingDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReturnToStartPoint()
|
||||||
|
{
|
||||||
|
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
|
||||||
|
navMeshAgent.SetDestination(idNavPointDict[PointStartID].Position);
|
||||||
|
PointEndID = PointStartID;
|
||||||
|
PointStartID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopOnPath()
|
||||||
|
{
|
||||||
|
navMeshAgent.isStopped = true;
|
||||||
|
PointStartID = -1;
|
||||||
|
PointEndID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReachedDestination()
|
||||||
|
{
|
||||||
|
if ((navMeshAgent.isStopped == false) && (navMeshAgent.velocity.magnitude < 0.1))
|
||||||
|
PointStartID = PointEndID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,108 +1,170 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using System.Collections.Generic;
|
||||||
using Unity.MLAgents;
|
using Unity.MLAgents;
|
||||||
using Unity.MLAgents.Sensors;
|
|
||||||
using Unity.MLAgents.Actuators;
|
using Unity.MLAgents.Actuators;
|
||||||
|
using Unity.MLAgents.Sensors;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
[RequireComponent(typeof(MovementController))]
|
[RequireComponent(typeof(MovementController),typeof(BufferSensor))]
|
||||||
public class NPC : Agent, ICharacter
|
public class NPC : Agent, ICharacter
|
||||||
{
|
{
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public Character AgentCharacter;
|
private Character AgentCharacter;
|
||||||
public CharacterCondition Condition;
|
public CharacterCondition Condition;
|
||||||
private FlagZone flagZone;
|
private FlagZone flagZone = null;
|
||||||
|
|
||||||
public NPC_BaseState NPC_State { get; private set; }
|
public INpcBaseState NpcState { get; private set; }
|
||||||
|
public INpcBaseBodyState NpcBodyState { get; private set; }
|
||||||
|
|
||||||
public Character GetCharacter => AgentCharacter;
|
public Character GetCharacter => AgentCharacter;
|
||||||
|
|
||||||
private NPC_DirectPointState DirectState;
|
private NpcDirectPointState DirectState;
|
||||||
private NPC_InCoverState CoverState;
|
private NpcInCoverState CoverState;
|
||||||
private NPC_RunningState RunningState;
|
private NpcRunningState RunningState;
|
||||||
|
|
||||||
|
private NpcStandingState StandingState;
|
||||||
|
private NpcCrouchingState CrouchingState;
|
||||||
|
|
||||||
private MovementController moveController;
|
private MovementController moveController;
|
||||||
private BufferSensorComponent bufferSensor;
|
private BufferSensorComponent bufferSensor;
|
||||||
|
|
||||||
|
private Dictionary<int, NavPoint> navPointIdDict;
|
||||||
|
|
||||||
|
#region UnityEvents and ML
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
DirectState = new NPC_DirectPointState();
|
DirectState = new NpcDirectPointState();
|
||||||
CoverState = new NPC_InCoverState();
|
CoverState = new NpcInCoverState();
|
||||||
RunningState = new NPC_RunningState();
|
RunningState = new NpcRunningState();
|
||||||
NPC_State = DirectState;
|
NpcState = DirectState;
|
||||||
|
|
||||||
|
CrouchingState = new NpcCrouchingState();
|
||||||
|
StandingState = new NpcStandingState();
|
||||||
|
NpcBodyState = StandingState;
|
||||||
|
|
||||||
AgentCharacter = new Character();
|
AgentCharacter = new Character();
|
||||||
Condition = AgentCharacter.Condition;
|
Condition = AgentCharacter.Condition;
|
||||||
|
|
||||||
moveController = gameObject.GetComponent<MovementController>();
|
moveController = gameObject.GetComponent<MovementController>();
|
||||||
bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
|
bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
|
||||||
|
|
||||||
|
flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||||
|
if (flagZone == null)
|
||||||
|
Debug.LogError("Flag Is Not Setted");
|
||||||
|
|
||||||
|
navPointIdDict = MapManager.IDToNavPoint;
|
||||||
|
if (navPointIdDict is null)
|
||||||
|
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
public void ResetCharacter()
|
|
||||||
{
|
{
|
||||||
Condition = new CharacterCondition();
|
Debug.LogWarning("Pooled object was destroyed");
|
||||||
EndEpisode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEpisodeBegin()
|
public override void OnEpisodeBegin()
|
||||||
{
|
{
|
||||||
NPC_State = DirectState;
|
NpcState = DirectState;
|
||||||
flagZone = GameObject.FindObjectOfType<FlagZone>();
|
flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void CollectObservations(VectorSensor sensor)
|
public override void CollectObservations(VectorSensor sensor)
|
||||||
{
|
{
|
||||||
var candidates = moveController.getPointsCandidate();
|
var candidates = moveController.GetPointsCandidate();
|
||||||
|
|
||||||
sensor.AddObservation(Condition.HealthPoints);
|
//common sensors
|
||||||
sensor.AddObservation(Condition.ArmourPoints);
|
sensor.AddObservation(GameManager.IsHaveSeenByEnemy(AgentCharacter.Team.GetOppositeTeam(),
|
||||||
sensor.AddObservation(Condition.Ammunition);
|
NpcBodyState.GetPointToHit(gameObject)).ToInt());
|
||||||
sensor.AddObservation((int)NPC_State.State);
|
|
||||||
sensor.AddObservation((!flagZone.isNotOccup).ToInt());
|
|
||||||
sensor.AddObservation(AgentCharacter.LastTimeHit);
|
sensor.AddObservation(AgentCharacter.LastTimeHit);
|
||||||
|
sensor.AddObservation((!flagZone.IsNotOccup).ToInt());
|
||||||
sensor.AddObservation(Condition.GetHealthPointsInQuantile());
|
sensor.AddObservation(Condition.GetHealthPointsInQuantile());
|
||||||
|
sensor.AddObservation(Condition.GetArmourPointsInQuantile());
|
||||||
sensor.AddObservation(candidates.Count);
|
sensor.AddObservation(candidates.Count);
|
||||||
|
sensor.AddObservation(moveController.PointStartID);
|
||||||
|
sensor.AddObservation(moveController.PointEndID);
|
||||||
|
//state sensors
|
||||||
|
sensor.AddObservation((int)NpcState.State);
|
||||||
|
sensor.AddObservation((int)NpcBodyState.State);
|
||||||
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, AgentCharacter.Team));
|
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, AgentCharacter.Team));
|
||||||
|
sensor.AddObservation(navPointIdDict[moveController.PointStartID].DeathAttr);
|
||||||
|
sensor.AddObservation(navPointIdDict[moveController.PointEndID].DeathAttr);
|
||||||
|
sensor.AddObservation(moveController.FlagDistance);
|
||||||
|
|
||||||
|
//point sensors
|
||||||
foreach (var point in candidates)
|
foreach (var point in candidates)
|
||||||
{
|
{
|
||||||
Debug.Log((float)moveController.CurrentNavPoint.PointId);
|
|
||||||
|
|
||||||
bufferSensor.AppendObservation(new float[] {
|
bufferSensor.AppendObservation(new float[] {
|
||||||
//1 position in navpointId
|
point.DeathAttr,
|
||||||
(float)moveController.CurrentNavPoint.PointId,
|
(int)point.navType,
|
||||||
//2 distance to flag
|
|
||||||
moveController.FlagDistance,
|
|
||||||
//3 death count in point
|
|
||||||
moveController.CurrentNavPoint.DeathAttr,
|
|
||||||
//4 flagEnemyDistance
|
//4 flagEnemyDistance
|
||||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position).ToInt(),
|
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position).ToInt(),
|
||||||
//5 EnemyVsNavPointDistance
|
//5 EnemyVsNavPointDistance
|
||||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team).ToInt()
|
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team.GetOppositeTeam()).ToInt(),
|
||||||
});
|
//6 Have been seen by enemy in this point
|
||||||
|
GameManager.IsHaveSeenByEnemy(AgentCharacter.Team.GetOppositeTeam(),
|
||||||
}
|
point.Position).ToInt()
|
||||||
}
|
});
|
||||||
|
|
||||||
public override void Heuristic(in ActionBuffers actionsOut)
|
|
||||||
{
|
|
||||||
var discreteActionsOut = actionsOut.DiscreteActions;
|
|
||||||
if (Input.GetKeyDown(KeyCode.W))
|
|
||||||
{
|
|
||||||
discreteActionsOut[0] = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnActionReceived(ActionBuffers actions)
|
public override void OnActionReceived(ActionBuffers actions)
|
||||||
{
|
{
|
||||||
if (actions.DiscreteActions[0] == 1)
|
var result = actions.DiscreteActions;
|
||||||
|
if (result[0] == 0)
|
||||||
{
|
{
|
||||||
moveController.MoveToRandomPoint();
|
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Cover)
|
||||||
NPC_State = RunningState;
|
return;
|
||||||
|
NpcState = CoverState;
|
||||||
|
|
||||||
|
switch (result[1])
|
||||||
|
{
|
||||||
|
case 0: Peek(); break;
|
||||||
|
case 1: Cover(); break;
|
||||||
|
case 3: Peek(); moveController.GoToNextNavPoint(navPointIdDict[result[2]]); break;
|
||||||
|
case 4: NpcState = DirectState; break;
|
||||||
|
default: throw new ArgumentException("Undefined Action recieved");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result[0] == 1)
|
||||||
|
{
|
||||||
|
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Direction)
|
||||||
|
return;
|
||||||
|
switch (result[1])
|
||||||
|
{
|
||||||
|
case 0: moveController.GoToNextNavPoint(navPointIdDict[result[2]]);
|
||||||
|
NpcState = RunningState; break;
|
||||||
|
case 1: NpcState = DirectState; break;
|
||||||
|
default: throw new ArgumentException("Undefined Action recieved");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result[0] == 2)
|
||||||
|
{
|
||||||
|
if (moveController.PointStartID == moveController.PointEndID && moveController.PointEndID != -1)
|
||||||
|
return;
|
||||||
|
switch (result[1])
|
||||||
|
{
|
||||||
|
case 0: moveController.StopOnPath(); NpcState = DirectState; break;
|
||||||
|
case 1: moveController.ReturnToStartPoint(); NpcState = RunningState; break;
|
||||||
|
default: throw new ArgumentException("Undefined Action recieved");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public event Action<object> OnKilledEvent;
|
public event Action<NpcBodyState> OnChangePosition;
|
||||||
|
private void Peek()
|
||||||
|
{
|
||||||
|
OnChangePosition?.Invoke(global::NpcBodyState.Standing);
|
||||||
|
NpcBodyState = StandingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cover()
|
||||||
|
{
|
||||||
|
OnChangePosition?.Invoke(global::NpcBodyState.Crouching);
|
||||||
|
NpcBodyState = CrouchingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action<int, Team> OnDamageRecieved;
|
||||||
public void GetDamage(float damage)
|
public void GetDamage(float damage)
|
||||||
{
|
{
|
||||||
AgentCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
AgentCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||||
@ -111,13 +173,17 @@ public class NPC : Agent, ICharacter
|
|||||||
|
|
||||||
if (Condition.HealthPoints < 0)
|
if (Condition.HealthPoints < 0)
|
||||||
{
|
{
|
||||||
OnKilledEvent?.Invoke(this);
|
MapManager.AddDeathAttributeToPoints(moveController.PointStartID, moveController.PointEndID,
|
||||||
moveController.CurrentNavPoint.DeathAttr += 1;
|
moveController.DistanceToGo, moveController.RemainingDistance);
|
||||||
|
var pos = gameObject.transform.position;
|
||||||
|
var id = moveController.PointStartID;
|
||||||
|
CharacterFactory.Instance.ReSpawn(this, ref pos, ref id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
public void ResetCharacter()
|
||||||
{
|
{
|
||||||
Debug.LogWarning("Pooled object was destroyed");
|
Condition.Reset();
|
||||||
|
EndEpisode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
public enum NPC_EnumState
|
|
||||||
{
|
|
||||||
InCover,
|
|
||||||
InDirectPoint,
|
|
||||||
InRunning,
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface NPC_BaseState
|
|
||||||
{
|
|
||||||
NPC_EnumState State { get; }
|
|
||||||
bool InCover { get; }
|
|
||||||
bool IsRunning { get; }
|
|
||||||
bool InDirectPoint { get; }
|
|
||||||
float HitChance { get; }
|
|
||||||
float DoDamageChance { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NPC_DirectPointState : NPC_BaseState
|
|
||||||
{
|
|
||||||
public bool InCover => false;
|
|
||||||
public bool IsRunning => false;
|
|
||||||
public bool InDirectPoint => false;
|
|
||||||
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInDirectPoint;
|
|
||||||
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInDirectPoint;
|
|
||||||
public NPC_EnumState State => NPC_EnumState.InDirectPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NPC_RunningState : NPC_BaseState
|
|
||||||
{
|
|
||||||
public bool InCover => false;
|
|
||||||
public bool IsRunning => true;
|
|
||||||
public bool InDirectPoint => false;
|
|
||||||
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInRunning;
|
|
||||||
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInRunning;
|
|
||||||
public NPC_EnumState State => NPC_EnumState.InRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NPC_InCoverState : NPC_BaseState
|
|
||||||
{
|
|
||||||
public bool InCover => true;
|
|
||||||
public bool IsRunning => false;
|
|
||||||
public bool InDirectPoint => false;
|
|
||||||
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInCover;
|
|
||||||
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInCover;
|
|
||||||
public NPC_EnumState State => NPC_EnumState.InCover;
|
|
||||||
}
|
|
68
Assets/Scripts/Character/NpcState.cs
Normal file
68
Assets/Scripts/Character/NpcState.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public enum NpcEnumState
|
||||||
|
{
|
||||||
|
InCover,
|
||||||
|
InDirectPoint,
|
||||||
|
InRunning,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum NpcBodyState
|
||||||
|
{
|
||||||
|
Crouching,
|
||||||
|
Standing,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NpcCrouchingState : INpcBaseBodyState
|
||||||
|
{
|
||||||
|
public NpcBodyState State => NpcBodyState.Crouching;
|
||||||
|
|
||||||
|
public Vector3 GetPointToHit(GameObject go)
|
||||||
|
{
|
||||||
|
MeshRenderer meshRenderer;
|
||||||
|
go.TryGetComponent<MeshRenderer>(out meshRenderer);
|
||||||
|
return meshRenderer.bounds.center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NpcStandingState : INpcBaseBodyState
|
||||||
|
{
|
||||||
|
public NpcBodyState State => NpcBodyState.Standing;
|
||||||
|
|
||||||
|
public Vector3 GetPointToHit(GameObject go)
|
||||||
|
{
|
||||||
|
MeshRenderer meshRenderer;
|
||||||
|
go.TryGetComponent<MeshRenderer>(out meshRenderer);
|
||||||
|
return meshRenderer.bounds.center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NpcDirectPointState : INpcBaseState
|
||||||
|
{
|
||||||
|
public bool InCover => false;
|
||||||
|
public bool IsRunning => false;
|
||||||
|
public bool InDirectPoint => false;
|
||||||
|
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInDirectPoint;
|
||||||
|
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInDirectPoint;
|
||||||
|
public NpcEnumState State => NpcEnumState.InDirectPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NpcRunningState : INpcBaseState
|
||||||
|
{
|
||||||
|
public bool InCover => false;
|
||||||
|
public bool IsRunning => true;
|
||||||
|
public bool InDirectPoint => false;
|
||||||
|
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInRunning;
|
||||||
|
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInRunning;
|
||||||
|
public NpcEnumState State => NpcEnumState.InRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NpcInCoverState : INpcBaseState
|
||||||
|
{
|
||||||
|
public bool InCover => true;
|
||||||
|
public bool IsRunning => false;
|
||||||
|
public bool InDirectPoint => false;
|
||||||
|
public float HitChance => SettingsReader.Instance.GetSettings.GetHitChanceInCover;
|
||||||
|
public float DoDamageChance => SettingsReader.Instance.GetSettings.DoDamageChanceInCover;
|
||||||
|
public NpcEnumState State => NpcEnumState.InCover;
|
||||||
|
}
|
@ -15,9 +15,9 @@ public class Player : MonoBehaviour, ICharacter
|
|||||||
Condition = PlayerCharacter.Condition;
|
Condition = PlayerCharacter.Condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetCharacter()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
Condition = new CharacterCondition();
|
Debug.LogWarning("Pooled object was destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<object> OnKilledEvent;
|
public event Action<object> OnKilledEvent;
|
||||||
@ -31,8 +31,8 @@ public class Player : MonoBehaviour, ICharacter
|
|||||||
OnKilledEvent?.Invoke(this);
|
OnKilledEvent?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
public void ResetCharacter()
|
||||||
{
|
{
|
||||||
Debug.LogWarning("Pooled object was destroyed");
|
Condition = new CharacterCondition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Unity.Barracuda;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
using static scr_Models;
|
using static scr_Models;
|
||||||
|
|
||||||
@ -123,11 +119,11 @@ public class scr_CharacterController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
playerSettings.SpeedEffector = playerSettings.FallingSpeedEffector;
|
playerSettings.SpeedEffector = playerSettings.FallingSpeedEffector;
|
||||||
}
|
}
|
||||||
else if(playerStance == PlayerStance.Crouch)
|
else if (playerStance == PlayerStance.Crouch)
|
||||||
{
|
{
|
||||||
playerSettings.SpeedEffector = playerSettings.CrouchSpeedEffector;
|
playerSettings.SpeedEffector = playerSettings.CrouchSpeedEffector;
|
||||||
}
|
}
|
||||||
else if(playerStance == PlayerStance.Prone)
|
else if (playerStance == PlayerStance.Prone)
|
||||||
{
|
{
|
||||||
playerSettings.SpeedEffector = playerSettings.ProneSpeedEffector;
|
playerSettings.SpeedEffector = playerSettings.ProneSpeedEffector;
|
||||||
}
|
}
|
||||||
|
@ -3,73 +3,73 @@ using UnityEngine;
|
|||||||
|
|
||||||
public static class scr_Models
|
public static class scr_Models
|
||||||
{
|
{
|
||||||
#region Player
|
#region Player
|
||||||
|
|
||||||
public enum PlayerStance
|
public enum PlayerStance
|
||||||
{
|
{
|
||||||
Stand,
|
Stand,
|
||||||
Crouch,
|
Crouch,
|
||||||
Prone
|
Prone
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class PlayerSettingsModel
|
public class PlayerSettingsModel
|
||||||
{
|
{
|
||||||
[Header("View Settings")]
|
[Header("View Settings")]
|
||||||
public float ViewXSensetivity;
|
public float ViewXSensetivity;
|
||||||
public float ViewYSensetivity;
|
public float ViewYSensetivity;
|
||||||
|
|
||||||
public bool ViewXInverted;
|
public bool ViewXInverted;
|
||||||
public bool ViewYInverted;
|
public bool ViewYInverted;
|
||||||
|
|
||||||
[Header("Movement Settings")]
|
[Header("Movement Settings")]
|
||||||
public bool SprintingHold;
|
public bool SprintingHold;
|
||||||
public float MovementSmoothing;
|
public float MovementSmoothing;
|
||||||
|
|
||||||
[Header("Movement - Running")]
|
[Header("Movement - Running")]
|
||||||
public float RunningForwardSpeed;
|
public float RunningForwardSpeed;
|
||||||
public float RunningStrafeSpeed;
|
public float RunningStrafeSpeed;
|
||||||
|
|
||||||
[Header("Movement - Walking")]
|
[Header("Movement - Walking")]
|
||||||
public float WalkingForwardSpeed;
|
public float WalkingForwardSpeed;
|
||||||
public float WalkingBackwardSpeed;
|
public float WalkingBackwardSpeed;
|
||||||
public float WalkingStrafeSpeed;
|
public float WalkingStrafeSpeed;
|
||||||
|
|
||||||
[Header("Jumping")]
|
[Header("Jumping")]
|
||||||
public float JumpingHeight;
|
public float JumpingHeight;
|
||||||
public float JumpingFalloff;
|
public float JumpingFalloff;
|
||||||
public float FallingSmoothing;
|
public float FallingSmoothing;
|
||||||
|
|
||||||
[Header("Speed Effectors")]
|
[Header("Speed Effectors")]
|
||||||
public float SpeedEffector = 1;
|
public float SpeedEffector = 1;
|
||||||
public float CrouchSpeedEffector;
|
public float CrouchSpeedEffector;
|
||||||
public float ProneSpeedEffector;
|
public float ProneSpeedEffector;
|
||||||
public float FallingSpeedEffector;
|
public float FallingSpeedEffector;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class CharacterStance
|
public class CharacterStance
|
||||||
{
|
{
|
||||||
public float CameraHeight;
|
public float CameraHeight;
|
||||||
public CapsuleCollider StanceCollider;
|
public CapsuleCollider StanceCollider;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region - Weapons -
|
#region - Weapons -
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class WeaponSettingsModel
|
public class WeaponSettingsModel
|
||||||
{
|
{
|
||||||
[Header("Sway")]
|
[Header("Sway")]
|
||||||
public float SwayAmount;
|
public float SwayAmount;
|
||||||
public bool SwayYInverted;
|
public bool SwayYInverted;
|
||||||
public bool SwayXInverted;
|
public bool SwayXInverted;
|
||||||
public float SwaySmoothing;
|
public float SwaySmoothing;
|
||||||
public float SwayResetSmoothing;
|
public float SwayResetSmoothing;
|
||||||
public float SwayClampX;
|
public float SwayClampX;
|
||||||
public float SwayClampY;
|
public float SwayClampY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -1,76 +1,123 @@
|
|||||||
using Unity.MLAgents;
|
using System;
|
||||||
|
using Unity.MLAgents;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
|
||||||
|
|
||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static GameManager instance;
|
private static GameManager instance;
|
||||||
public static GameManager Instance { get { return instance; } }
|
public static GameManager Instance => instance;
|
||||||
|
|
||||||
private static SimpleMultiAgentGroup DefendersTeam = new SimpleMultiAgentGroup();
|
private static SimpleMultiAgentGroup defendersTeam = new SimpleMultiAgentGroup();
|
||||||
private static SimpleMultiAgentGroup AttackersTeam = new SimpleMultiAgentGroup();
|
private static SimpleMultiAgentGroup attackersTeam = new SimpleMultiAgentGroup();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (instance is null)
|
||||||
instance = this;
|
instance = this;
|
||||||
else if (Instance == this)
|
else
|
||||||
|
{
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
|
Debug.LogError("Only 1 Instance");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
Academy.Instance.OnEnvironmentReset += ResetScene;
|
Academy.Instance.OnEnvironmentReset += ResetScene;
|
||||||
|
|
||||||
GlobalEventManager.onCaptureFlag += flagCaptured;
|
GlobalEventManager.onCaptureFlag += FlagCaptured;
|
||||||
GlobalEventManager.onTimeLeft += timeOut;
|
GlobalEventManager.onTimeLeft += TimeOut;
|
||||||
|
|
||||||
var agents = GameObject.FindObjectsOfType<Agent>();
|
var agents = GameObject.FindObjectsOfType<Agent>();
|
||||||
foreach (var item in agents)
|
foreach (var item in agents)
|
||||||
{
|
{
|
||||||
var agent = item as NPC;
|
var agent = item as NPC;
|
||||||
if (agent.GetCharacter.Team == Team.Attackers)
|
if (agent.GetCharacter.Team == Team.Attackers)
|
||||||
AttackersTeam.RegisterAgent(agent);
|
attackersTeam.RegisterAgent(item);
|
||||||
else
|
else
|
||||||
DefendersTeam.RegisterAgent(agent);
|
defendersTeam.RegisterAgent(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCloserToEnemyThanToNextNavPoint(NavPoint navPoint, Vector3 currentTransform, Team team)
|
private static SimpleMultiAgentGroup getAgentList(Team team)
|
||||||
{
|
{
|
||||||
SimpleMultiAgentGroup agentGroup;
|
|
||||||
if (team == Team.Attackers)
|
if (team == Team.Attackers)
|
||||||
agentGroup = AttackersTeam;
|
return attackersTeam;
|
||||||
else
|
else
|
||||||
agentGroup = DefendersTeam;
|
return defendersTeam;
|
||||||
|
}
|
||||||
|
|
||||||
var distToNavPoint = (currentTransform - navPoint.position).magnitude;
|
public static bool IsCloserToEnemyThanToNextNavPoint(NavPoint navPoint, Vector3 currentTransform, Team oppositeTeam)
|
||||||
|
{
|
||||||
|
var agentGroup = getAgentList(oppositeTeam);
|
||||||
|
|
||||||
|
var distToNavPoint = (currentTransform - navPoint.Position).magnitude;
|
||||||
foreach (var agent in agentGroup.GetRegisteredAgents())
|
foreach (var agent in agentGroup.GetRegisteredAgents())
|
||||||
if (distToNavPoint > (currentTransform - agent.transform.position).magnitude)
|
if (distToNavPoint > (currentTransform - agent.transform.position).magnitude)
|
||||||
return true;
|
return true;
|
||||||
|
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
|
||||||
|
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
|
||||||
|
{
|
||||||
|
if (distToNavPoint > (currentTransform - CharacterFactory.Instance.player.transform.position).magnitude)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsEnemyNearby(Vector3 currentTransform, Team team)
|
public static bool IsEnemyNearby(Vector3 currentTransform, Team oppositeTeam)
|
||||||
{
|
{
|
||||||
SimpleMultiAgentGroup agentGroup;
|
var agentGroup = getAgentList(oppositeTeam);
|
||||||
if (team == Team.Attackers)
|
|
||||||
agentGroup = AttackersTeam;
|
|
||||||
else
|
|
||||||
agentGroup = DefendersTeam;
|
|
||||||
|
|
||||||
foreach (var agent in agentGroup.GetRegisteredAgents())
|
foreach (var agent in agentGroup.GetRegisteredAgents())
|
||||||
if ((currentTransform - agent.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
|
if ((currentTransform - agent.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
|
||||||
return true;
|
return true;
|
||||||
|
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
|
||||||
|
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
|
||||||
|
{
|
||||||
|
if ((currentTransform - CharacterFactory.Instance.player.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCloserToFlagFromNextNavPoint(NavPoint navPoint, Vector3 currentTransform)
|
public static bool IsCloserToFlagFromNextNavPoint(NavPoint navPoint, Vector3 currentTransform)
|
||||||
=> navPoint.FlagDistance < (currentTransform - GameObject.FindGameObjectWithTag("Flag").transform.position).magnitude;
|
=> navPoint.FlagDistance < (currentTransform - GameObject.FindGameObjectWithTag("Flag").transform.position).magnitude;
|
||||||
|
|
||||||
private void flagCaptured(Team team)
|
public static bool IsHaveSeenByEnemy(Team oppositeTeam, Vector3 position)
|
||||||
{
|
{
|
||||||
switch(team)
|
var agentGroup = getAgentList(oppositeTeam);
|
||||||
|
RaycastHit rayHit = new RaycastHit();
|
||||||
|
foreach (var agent in agentGroup.GetRegisteredAgents() )
|
||||||
|
{
|
||||||
|
var npc = agent as NPC;
|
||||||
|
if (Physics.Raycast(position,
|
||||||
|
(npc.NpcBodyState.GetPointToHit(npc.gameObject) - position).normalized,
|
||||||
|
out rayHit,
|
||||||
|
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||||
|
{
|
||||||
|
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
|
||||||
|
(SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders))
|
||||||
|
{
|
||||||
|
var player = CharacterFactory.Instance.player;
|
||||||
|
if (Physics.Raycast(position,
|
||||||
|
(player.GetComponent<MeshRenderer>().bounds.center - position).normalized,
|
||||||
|
out rayHit,
|
||||||
|
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||||
|
{
|
||||||
|
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FlagCaptured(Team team)
|
||||||
|
{
|
||||||
|
switch (team)
|
||||||
{
|
{
|
||||||
case Team.Attackers:
|
case Team.Attackers:
|
||||||
Debug.Log("Attackers Win");
|
Debug.Log("Attackers Win");
|
||||||
@ -78,21 +125,19 @@ public class GameManager : MonoBehaviour
|
|||||||
case Team.Defenders:
|
case Team.Defenders:
|
||||||
Debug.Log("Defenders Win");
|
Debug.Log("Defenders Win");
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
Debug.LogError("Unexpected Team");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
ResetScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timeOut()
|
private void TimeOut()
|
||||||
{
|
{
|
||||||
Debug.Log("Time is out");
|
ResetScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
GlobalEventManager.onCaptureFlag -= flagCaptured;
|
GlobalEventManager.onCaptureFlag -= FlagCaptured;
|
||||||
GlobalEventManager.onTimeLeft -= timeOut;
|
GlobalEventManager.onTimeLeft -= TimeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static event Action OnResetScene;
|
public static event Action OnResetScene;
|
||||||
|
@ -3,17 +3,62 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class MapManager : MonoBehaviour
|
public class MapManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static List<NavPoint> navPoints { get; private set; }
|
private static MapManager instance;
|
||||||
private void Start()
|
public static MapManager Instance => instance;
|
||||||
|
private static List<NavPoint> navPoints = new List<NavPoint>();
|
||||||
|
private static Dictionary<int, NavPoint> iDToNavPoint = new Dictionary<int, NavPoint>();
|
||||||
|
public static List<NavPoint> NavPoints { get => navPoints; private set => navPoints = value; }
|
||||||
|
public static Dictionary<int, NavPoint> IDToNavPoint { get => iDToNavPoint; private set => iDToNavPoint = value; }
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
{
|
{
|
||||||
var i = 0;
|
if (instance is null)
|
||||||
navPoints = new List<NavPoint>();
|
instance = this;
|
||||||
var navPointsGameObj = GameObject.FindGameObjectsWithTag("Point");
|
else
|
||||||
foreach (var gameobj in navPointsGameObj)
|
|
||||||
{
|
{
|
||||||
var navpoint = gameobj.GetComponent<NavPoint>();
|
Destroy(gameObject);
|
||||||
navpoint.PointId = i; i++;
|
Debug.LogError("Only 1 Instance");
|
||||||
navPoints.Add(navpoint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
var navPointSet = GameObject.Find("NavPoint Set");
|
||||||
|
var count = navPointSet.transform.childCount;
|
||||||
|
for (int i=0; i < count; i++)
|
||||||
|
NavPoints.Add(navPointSet.transform.GetChild(i)
|
||||||
|
.gameObject.GetComponent<NavPoint>());
|
||||||
|
|
||||||
|
NavPointSetToID();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NavPointSetToID()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
foreach (var navPoint in NavPoints)
|
||||||
|
{
|
||||||
|
IDToNavPoint.Add(i, navPoint);
|
||||||
|
navPoint.PointId = i;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddDeathAttributeToPoints(int startPoint, int endPoint,
|
||||||
|
float allDistance, float remainingDistance)
|
||||||
|
{
|
||||||
|
var startNavPoint = IDToNavPoint[startPoint];
|
||||||
|
var endNavPoint = IDToNavPoint[endPoint];
|
||||||
|
float coef;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
coef = remainingDistance / allDistance;
|
||||||
|
}
|
||||||
|
catch (System.ArithmeticException)
|
||||||
|
{
|
||||||
|
Debug.LogError("Path Length is zero");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startNavPoint.DeathAttr += 1 - coef;
|
||||||
|
endNavPoint.DeathAttr += coef;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System.Collections;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class TimeManager : MonoBehaviour
|
public class TimeManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -17,12 +15,14 @@ public class TimeManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.LogError("Only one Instance");
|
Debug.LogError("Only 1 Instance");
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
CurrentTime += Time.deltaTime;
|
CurrentTime += Time.deltaTime;
|
||||||
|
if (CurrentTime > SettingsReader.Instance.GetSettings.TimeOut)
|
||||||
|
GlobalEventManager.SendTimeout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System.Collections;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class FlagZone : MonoBehaviour
|
public class FlagZone : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -9,8 +7,8 @@ public class FlagZone : MonoBehaviour
|
|||||||
public float TimeStayDefenders { get; private set; }
|
public float TimeStayDefenders { get; private set; }
|
||||||
private int occupDefenders;
|
private int occupDefenders;
|
||||||
private int occupAttackers;
|
private int occupAttackers;
|
||||||
public bool isOccupBoth => (occupDefenders>0) && (occupAttackers>0);
|
public bool IsOccupBoth => (occupDefenders > 0) && (occupAttackers > 0);
|
||||||
public bool isNotOccup => (occupDefenders == 0) && (occupAttackers == 0);
|
public bool IsNotOccup => (occupDefenders == 0) && (occupAttackers == 0);
|
||||||
private float timeForWin;
|
private float timeForWin;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@ -24,7 +22,7 @@ public class FlagZone : MonoBehaviour
|
|||||||
}
|
}
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
switch(other.tag)
|
switch (other.tag)
|
||||||
{
|
{
|
||||||
case "Defender":
|
case "Defender":
|
||||||
occupDefenders++;
|
occupDefenders++;
|
||||||
@ -54,7 +52,7 @@ public class FlagZone : MonoBehaviour
|
|||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (isOccupBoth || isNotOccup)
|
if (IsOccupBoth || IsNotOccup)
|
||||||
{
|
{
|
||||||
TimeStayAttackers = 0;
|
TimeStayAttackers = 0;
|
||||||
TimeStayDefenders = 0;
|
TimeStayDefenders = 0;
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
public enum NavPointType
|
||||||
|
{
|
||||||
|
Cover,
|
||||||
|
Direction,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class NavPoint : MonoBehaviour
|
public class NavPoint : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Vector3 position => gameObject.transform.position;
|
public Vector3 Position => gameObject.transform.position;
|
||||||
public float FlagDistance { get; private set; }
|
public float FlagDistance { get; private set; }
|
||||||
|
|
||||||
|
public NavPointType navType = NavPointType.Direction;
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
public int? PointId;
|
public int PointId = 0;
|
||||||
public float DeathAttr = 0;
|
public float DeathAttr = 0;
|
||||||
public List<Vector3> EnemiesSeen = new List<Vector3>();
|
public List<Vector3> EnemiesSeen = new List<Vector3>();
|
||||||
//Here other attributes;
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - position).magnitude;
|
FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - Position).magnitude;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName ="Game Settings", menuName = "Game/Settings", order = 51)]
|
[CreateAssetMenu(fileName = "Game Settings", menuName = "Game/Settings", order = 51)]
|
||||||
public class Settings : ScriptableObject
|
public class Settings : ScriptableObject
|
||||||
{
|
{
|
||||||
public bool IsTesting;
|
public bool IsTesting;
|
||||||
@ -36,4 +36,6 @@ public class Settings : ScriptableObject
|
|||||||
public float DoDamageChanceInDirectPoint;
|
public float DoDamageChanceInDirectPoint;
|
||||||
public float DoDamageChanceInRunning;
|
public float DoDamageChanceInRunning;
|
||||||
public float DoDamageChanceInCover;
|
public float DoDamageChanceInCover;
|
||||||
|
|
||||||
|
public float CrouchingCoefficient;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
using System.Collections;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class SettingsReader : MonoBehaviour
|
public class SettingsReader : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static SettingsReader instance;
|
private static SettingsReader instance;
|
||||||
public static SettingsReader Instance { get { return instance; } }
|
public static SettingsReader Instance => instance;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
instance = this;
|
if (instance is null)
|
||||||
|
instance = this;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
Debug.LogError("Only 1 Instance");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField] private Settings gameSettings;
|
[SerializeField] private Settings gameSettings;
|
||||||
public Settings GetSettings { get { return gameSettings; } }
|
public Settings GetSettings => gameSettings;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class Statistics : MonoBehaviour
|
|
||||||
{
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(BoxCollider))]
|
[RequireComponent(typeof(BoxCollider))]
|
||||||
public class AmmoPickUp : MonoBehaviour, IPickable
|
public class AmmoPickUp : MonoBehaviour, IPickable
|
||||||
@ -11,6 +10,11 @@ public class AmmoPickUp : MonoBehaviour, IPickable
|
|||||||
PickObject(other.gameObject);
|
PickObject(other.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Pooled object was destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
public void PickObject(GameObject obj)
|
public void PickObject(GameObject obj)
|
||||||
{
|
{
|
||||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.TakeAmmo(SettingsReader.Instance.GetSettings.AmmunitionPickupAmount);
|
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.TakeAmmo(SettingsReader.Instance.GetSettings.AmmunitionPickupAmount);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(BoxCollider))]
|
[RequireComponent(typeof(BoxCollider))]
|
||||||
public class ArmourPickUp : MonoBehaviour, IPickable
|
public class ArmourPickUp : MonoBehaviour, IPickable
|
||||||
@ -11,6 +10,11 @@ public class ArmourPickUp : MonoBehaviour, IPickable
|
|||||||
PickObject(other.gameObject);
|
PickObject(other.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Pooled object was destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
public void PickObject(GameObject obj)
|
public void PickObject(GameObject obj)
|
||||||
{
|
{
|
||||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveArmour(SettingsReader.Instance.GetSettings.ArmourPickupAmount);
|
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveArmour(SettingsReader.Instance.GetSettings.ArmourPickupAmount);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(BoxCollider))]
|
[RequireComponent(typeof(BoxCollider))]
|
||||||
public class HealthPickUp : MonoBehaviour, IPickable
|
public class HealthPickUp : MonoBehaviour, IPickable
|
||||||
@ -11,6 +10,11 @@ public class HealthPickUp : MonoBehaviour, IPickable
|
|||||||
PickObject(other.gameObject);
|
PickObject(other.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Pooled object was destroyed");
|
||||||
|
}
|
||||||
|
|
||||||
public void PickObject(GameObject obj)
|
public void PickObject(GameObject obj)
|
||||||
{
|
{
|
||||||
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveHealth(SettingsReader.Instance.GetSettings.HealthPickupAmount);
|
obj.GetComponent<ICharacter>()?.GetCharacter.Condition.GiveHealth(SettingsReader.Instance.GetSettings.HealthPickupAmount);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
public interface IPickable
|
public interface IPickable
|
||||||
{
|
{
|
||||||
PickUpType type { get; }
|
PickUpType type { get; }
|
||||||
|
@ -44,25 +44,25 @@ public class PickUpSpawner : MonoBehaviour
|
|||||||
|
|
||||||
private IEnumerator SpawnNewPickUps()
|
private IEnumerator SpawnNewPickUps()
|
||||||
{
|
{
|
||||||
while(true)
|
while (true)
|
||||||
{
|
{
|
||||||
GameObject item;
|
GameObject item;
|
||||||
if(IsDisableCheck(out item))
|
if (IsDisableCheck(out item))
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(3);
|
yield return new WaitForSeconds(3);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
item.transform.position = spawnPoints[Random.Range(0, spawnPoints.Count)].position;
|
item.transform.position = spawnPoints[Random.Range(0, spawnPoints.Count)].Position;
|
||||||
item.SetActive(true);
|
item.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield return new WaitForSeconds(2);
|
yield return new WaitForSeconds(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsDisableCheck(out GameObject gameobj)
|
private bool IsDisableCheck(out GameObject gameobj)
|
||||||
{
|
{
|
||||||
foreach(var pick in pickups)
|
foreach (var pick in pickups)
|
||||||
{
|
{
|
||||||
if (!pick.activeInHierarchy)
|
if (!pick.activeInHierarchy)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
public enum SensorType
|
|
||||||
{
|
|
||||||
Visual,
|
|
||||||
Sound,
|
|
||||||
Other
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Unity.MLAgents.Sensors;
|
|
||||||
|
|
||||||
|
|
8
Assets/Scripts/Statistics.meta
generated
Normal file
8
Assets/Scripts/Statistics.meta
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a9f7f0a9faf11f49a433480722bffc5
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
19
Assets/Scripts/Statistics/Logger.cs
Normal file
19
Assets/Scripts/Statistics/Logger.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Logger
|
||||||
|
{
|
||||||
|
private const string directory = "/Logs/";
|
||||||
|
private const string baseName = "Log#";
|
||||||
|
|
||||||
|
public static void SaveLog<T>(T objToSerialize)
|
||||||
|
{
|
||||||
|
string dir = Application.persistentDataPath + directory;
|
||||||
|
if (!Directory.Exists(dir))
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
|
||||||
|
var logName = baseName + (Directory.GetFiles(dir).Length + 1).ToString();
|
||||||
|
string json = JsonUtility.ToJson(objToSerialize);
|
||||||
|
File.WriteAllText(dir + logName, json);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Statistics/Logger.cs.meta
generated
Normal file
11
Assets/Scripts/Statistics/Logger.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b3a1cec894fa98b4bbe20470f1e316c4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
51
Assets/Scripts/Statistics/StatisticManager.cs
Normal file
51
Assets/Scripts/Statistics/StatisticManager.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
internal class Log
|
||||||
|
{
|
||||||
|
public int damageTakenByDefs = 0;
|
||||||
|
public int damageTakenByAtc = 0;
|
||||||
|
|
||||||
|
public int AtcWin = 0;
|
||||||
|
public int DefWin = 0;
|
||||||
|
|
||||||
|
public int TimeOuts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StatisticManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
private Log log = new Log();
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
foreach (var npc in GameObject.FindObjectsOfType<NPC>())
|
||||||
|
npc.OnDamageRecieved += RegisterDamage;
|
||||||
|
|
||||||
|
GlobalEventManager.onCaptureFlag += RegisterWin;
|
||||||
|
GlobalEventManager.onTimeLeft += RegisterTimeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RegisterDamage(int damage, Team team)
|
||||||
|
{
|
||||||
|
if (team == Team.Attackers)
|
||||||
|
log.damageTakenByAtc += damage;
|
||||||
|
else
|
||||||
|
log.damageTakenByDefs += damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RegisterWin(Team team)
|
||||||
|
{
|
||||||
|
if (team == Team.Attackers)
|
||||||
|
log.AtcWin += 1;
|
||||||
|
else
|
||||||
|
log.DefWin += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RegisterTimeOut()
|
||||||
|
{
|
||||||
|
log.TimeOuts += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
Logger.SaveLog<Log>(log);
|
||||||
|
}
|
||||||
|
}
|
2
Assets/Scripts/Misc/Statistics.cs.meta → Assets/Scripts/Statistics/StatisticManager.cs.meta
generated
Executable file → Normal file
2
Assets/Scripts/Misc/Statistics.cs.meta → Assets/Scripts/Statistics/StatisticManager.cs.meta
generated
Executable file → Normal file
@ -4,7 +4,7 @@ MonoImporter:
|
|||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 300
|
||||||
icon: {instanceID: 0}
|
icon: {instanceID: 0}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using UnityEngine;
|
using System.Linq;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
using UnityObject = UnityEngine.Object;
|
using UnityObject = UnityEngine.Object;
|
||||||
|
|
||||||
[Serializable, DebuggerDisplay("Count = {Count}")]
|
[Serializable, DebuggerDisplay("Count = {Count}")]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
using static scr_Models;
|
using static scr_Models;
|
||||||
public class scr_WeaponController : MonoBehaviour
|
public class scr_WeaponController : MonoBehaviour
|
||||||
{
|
{
|
||||||
@ -34,7 +33,7 @@ public class scr_WeaponController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetWeaponRotation.y += settings.SwayAmount * (settings.SwayXInverted ? -characterController.input_View.x : characterController.input_View.x) * Time.deltaTime;
|
targetWeaponRotation.y += settings.SwayAmount * (settings.SwayXInverted ? -characterController.input_View.x : characterController.input_View.x) * Time.deltaTime;
|
||||||
targetWeaponRotation.x += settings.SwayAmount * (settings.SwayYInverted ? characterController.input_View.y : -characterController.input_View.y) * Time.deltaTime;
|
targetWeaponRotation.x += settings.SwayAmount * (settings.SwayYInverted ? characterController.input_View.y : -characterController.input_View.y) * Time.deltaTime;
|
||||||
//newWeaponRotation.x = Mathf.Clamp(newWeaponRotation.x, ViewClampYMin, ViewClampYMax);
|
//newWeaponRotation.x = Mathf.Clamp(newWeaponRotation.x, ViewClampYMin, ViewClampYMax);
|
||||||
|
|
||||||
targetWeaponRotation.x = Mathf.Clamp(targetWeaponRotation.x, -settings.SwayClampX, settings.SwayClampX);
|
targetWeaponRotation.x = Mathf.Clamp(targetWeaponRotation.x, -settings.SwayClampX, settings.SwayClampX);
|
||||||
|
Reference in New Issue
Block a user