...
This commit is contained in:
@ -1,19 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.MLAgents;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
private static GameManager instance;
|
||||
public static GameManager Instance => instance;
|
||||
private static GameManager _instance;
|
||||
public static GameManager Instance => _instance;
|
||||
|
||||
private static SimpleMultiAgentGroup defendersTeam = new SimpleMultiAgentGroup();
|
||||
private static SimpleMultiAgentGroup attackersTeam = new SimpleMultiAgentGroup();
|
||||
private static SimpleMultiAgentGroup _defendersTeam = new SimpleMultiAgentGroup();
|
||||
private static SimpleMultiAgentGroup _attackersTeam = new SimpleMultiAgentGroup();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance is null)
|
||||
instance = this;
|
||||
if (_instance is null)
|
||||
_instance = this;
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
@ -32,23 +33,23 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
var agent = item as NPC;
|
||||
if (agent.GetCharacter.Team == Team.Attackers)
|
||||
attackersTeam.RegisterAgent(item);
|
||||
_attackersTeam.RegisterAgent(item);
|
||||
else
|
||||
defendersTeam.RegisterAgent(item);
|
||||
_defendersTeam.RegisterAgent(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static SimpleMultiAgentGroup getAgentList(Team team)
|
||||
private static SimpleMultiAgentGroup GetAgentList(Team team)
|
||||
{
|
||||
if (team == Team.Attackers)
|
||||
return attackersTeam;
|
||||
return _attackersTeam;
|
||||
else
|
||||
return defendersTeam;
|
||||
return _defendersTeam;
|
||||
}
|
||||
|
||||
public static bool IsCloserToEnemyThanToNextNavPoint(NavPoint navPoint, Vector3 currentTransform, Team oppositeTeam)
|
||||
{
|
||||
var agentGroup = getAgentList(oppositeTeam);
|
||||
var agentGroup = GetAgentList(oppositeTeam);
|
||||
|
||||
var distToNavPoint = (currentTransform - navPoint.Position).magnitude;
|
||||
foreach (var agent in agentGroup.GetRegisteredAgents())
|
||||
@ -65,7 +66,7 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public static bool IsEnemyNearby(Vector3 currentTransform, Team oppositeTeam)
|
||||
{
|
||||
var agentGroup = getAgentList(oppositeTeam);
|
||||
var agentGroup = GetAgentList(oppositeTeam);
|
||||
|
||||
foreach (var agent in agentGroup.GetRegisteredAgents())
|
||||
if ((currentTransform - agent.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance)
|
||||
@ -84,18 +85,23 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public static bool IsHaveSeenByEnemy(Team oppositeTeam, Vector3 position)
|
||||
{
|
||||
var agentGroup = getAgentList(oppositeTeam);
|
||||
return GetVisibleEnemies(oppositeTeam, position).Count > 0 ? true : false;
|
||||
}
|
||||
|
||||
public static List<GameObject> GetVisibleEnemies(Team oppositeTeam, Vector3 position)
|
||||
{
|
||||
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))
|
||||
(npc.NpcBodyState.GetPointToHit(npc.gameObject) - position).normalized,
|
||||
out rayHit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) ||
|
||||
@ -103,15 +109,15 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
var player = CharacterFactory.Instance.player;
|
||||
if (Physics.Raycast(position,
|
||||
(player.GetComponent<MeshRenderer>().bounds.center - position).normalized,
|
||||
out rayHit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
(player.GetComponent<MeshRenderer>().bounds.center - position).normalized,
|
||||
out rayHit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
if (rayHit.collider.gameObject.GetComponent<ICharacter>() != null)
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void FlagCaptured(Team team)
|
||||
|
Reference in New Issue
Block a user