Final commit
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 907ff02de47a55a4e971d73d25e7d006
|
||||
guid: 8fe13ad8c6843804c97b783914bc27b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
@ -9,29 +9,32 @@ namespace Animators.Leonid_Animator.Bot
|
||||
public class BotLocomotion : MonoBehaviour
|
||||
{
|
||||
private Vector3 _moveDirection;
|
||||
private Transform _myTransform;
|
||||
|
||||
private AnimatorHandler _myAnimatorHandler;
|
||||
private MovementController _movementController;
|
||||
private NPC _npc;
|
||||
private Rigidbody _myRigidbody;
|
||||
private NpcBodyState _crouchBuffer = NpcBodyState.Standing;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_myRigidbody = GetComponent<Rigidbody>();
|
||||
_myAnimatorHandler = GetComponent<AnimatorHandler>();
|
||||
_movementController = GetComponent<MovementController>();
|
||||
_npc = GetComponent<NPC>();
|
||||
|
||||
_myTransform = transform;
|
||||
_myAnimatorHandler.Initialize();
|
||||
}
|
||||
|
||||
private bool CrouchPressed(NpcBodyState state)
|
||||
{
|
||||
if (_crouchBuffer == state) return false;
|
||||
_crouchBuffer = state;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void UpdateAnimatorValues()
|
||||
{
|
||||
var movementDir = _movementController.Velocity;
|
||||
_myAnimatorHandler.UpdateAnimatorValues( Mathf.Clamp01(movementDir.magnitude), 0,
|
||||
false, _npc.NpcBodyState is NpcCrouchingState, _npc.IsFiring);
|
||||
false, CrouchPressed(_npc.NpcBodyState.State), _npc.IsFiring);
|
||||
}
|
||||
}
|
||||
}
|
@ -23,10 +23,12 @@ public class MovementController : MonoBehaviour
|
||||
public Vector3 Velocity => navMeshAgent.velocity;
|
||||
private Dictionary<int, NavPoint> _idNavPointDict;
|
||||
private NPC _myNpc;
|
||||
private Settings _settings;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||
_settings = SettingsReader.Instance.GetSettings;
|
||||
navMeshAgent.speed = _settings.MovementSpeed;
|
||||
_idNavPointDict = MapManager.Instance.IDToNavPoint;
|
||||
_myNpc = GetComponent<NPC>();
|
||||
_firePointTransform = transform.GetChild(0);
|
||||
@ -42,15 +44,23 @@ public class MovementController : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
print($"{_myNpc.NpcState.ToString()}, {_myNpc.GetCharacter.Team}");
|
||||
if (Velocity.magnitude > 0)
|
||||
_myNpc.ChangeBaseState(NpcEnumState.InRunning);
|
||||
else
|
||||
if (ReachedDestination())
|
||||
{
|
||||
_myNpc.ChangeBaseState(_idNavPointDict[PointStartID].navType == NavPointType.Cover
|
||||
_myNpc.ChangePointState(_idNavPointDict[PointStartID].navType == NavPointType.Cover
|
||||
? NpcEnumState.InCover
|
||||
: NpcEnumState.InDirectPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
_myNpc.ChangeBodyState(NpcBodyState.Standing);
|
||||
_myNpc.ChangePointState(NpcEnumState.InRunning);
|
||||
}
|
||||
|
||||
if (_myNpc.NpcBodyState.State == NpcBodyState.Crouching)
|
||||
navMeshAgent.speed = _settings.MovementSpeed / 2;
|
||||
else
|
||||
navMeshAgent.speed = _settings.MovementSpeed;
|
||||
|
||||
}
|
||||
|
||||
private void UpdateFlagPosition()
|
||||
@ -68,7 +78,7 @@ public class MovementController : MonoBehaviour
|
||||
{
|
||||
return MapManager.Instance.NavPoints
|
||||
.Where(point =>
|
||||
(transform.position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
(transform.position - point.Position).magnitude < _settings.MovementDistance)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -93,11 +103,13 @@ public class MovementController : MonoBehaviour
|
||||
navMeshAgent.isStopped = true;
|
||||
}
|
||||
|
||||
public void ReachedDestination()
|
||||
public bool ReachedDestination()
|
||||
{
|
||||
if (navMeshAgent.remainingDistance < float.Epsilon)
|
||||
if (navMeshAgent.remainingDistance < 0.1f)
|
||||
{
|
||||
PointStartID = PointEndID;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public bool IsFiring => _assistant.fireAnimation;
|
||||
|
||||
public void ChangeBaseState(NpcEnumState state)
|
||||
public void ChangePointState(NpcEnumState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
@ -51,6 +51,19 @@ public class NPC : Agent, ICharacter
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeBodyState(NpcBodyState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case global::NpcBodyState.Crouching:
|
||||
NpcBodyState = _crouchingState;
|
||||
break;
|
||||
case global::NpcBodyState.Standing:
|
||||
NpcBodyState = _standingState;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region UnityEvents and ML
|
||||
private void Awake()
|
||||
@ -96,7 +109,6 @@ public class NPC : Agent, ICharacter
|
||||
if (_navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
|
||||
NpcState = _directState;
|
||||
_flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||
}
|
||||
|
||||
@ -143,35 +155,41 @@ public class NPC : Agent, ICharacter
|
||||
} ;
|
||||
}
|
||||
|
||||
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
|
||||
{
|
||||
if (!NpcState.InCover)
|
||||
actionMask.SetActionEnabled(0,0,false);
|
||||
if (!NpcState.InDirectPoint)
|
||||
actionMask.SetActionEnabled(0,1,false);
|
||||
if (!NpcState.IsRunning)
|
||||
actionMask.SetActionEnabled(0,2,false);
|
||||
base.WriteDiscreteActionMask(actionMask);
|
||||
}
|
||||
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
var result = actions.DiscreteActions;
|
||||
if (result[0] == 0)
|
||||
{
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Cover)
|
||||
return;
|
||||
NpcState = _coverState;
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: Peek(); break;
|
||||
case 1: Cover(); break;
|
||||
case 2: Peek(); _moveController.GoToNextNavPoint(_navPointIdDict[result[2]]); break;
|
||||
case 2: Peek();
|
||||
_moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);
|
||||
break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
}
|
||||
}
|
||||
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;
|
||||
case 0:
|
||||
_moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);break;
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
@ -179,13 +197,11 @@ public class NPC : Agent, ICharacter
|
||||
}
|
||||
|
||||
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;
|
||||
case 0: _moveController.StopOnPath(); break;
|
||||
case 1: _moveController.ReturnToStartPoint(); break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MapManager : MonoBehaviour
|
||||
{
|
||||
@ -19,12 +21,20 @@ public class MapManager : MonoBehaviour
|
||||
Debug.LogError("Only 1 Instance");
|
||||
}
|
||||
|
||||
NavPoints = new List<NavPoint>();
|
||||
var navPointSet = GameObject.Find("NavPoint Set");
|
||||
var count = navPointSet.transform.childCount;
|
||||
for (var i=0; i < count; i++)
|
||||
NavPoints.Add(navPointSet.transform.GetChild(i)
|
||||
.gameObject.GetComponent<NavPoint>());
|
||||
// NavPoints = new List<NavPoint>();
|
||||
// var navPointSet = GameObject.Find("NavPoint Set");
|
||||
// var count = navPointSet.transform.childCount;
|
||||
// for (var i=0; i < count; i++)
|
||||
// NavPoints.Add(navPointSet.transform.GetChild(i)
|
||||
// .gameObject.GetComponent<NavPoint>());
|
||||
|
||||
var rootObjInScene = new List<GameObject>();
|
||||
var scene = SceneManager.GetActiveScene();
|
||||
scene.GetRootGameObjects(rootObjInScene);
|
||||
foreach (var t in rootObjInScene)
|
||||
{
|
||||
NavPoints = t.GetComponentsInChildren<NavPoint>(true).ToList();
|
||||
}
|
||||
NavPointSetToID();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class Log
|
||||
public class StatisticManager : MonoBehaviour
|
||||
{
|
||||
private Log _log = new Log();
|
||||
private LoggerSideChannel _myLoggerSideChannel;
|
||||
private LoggerSideChannel _myLoggerSideChannel = new LoggerSideChannel();
|
||||
private void Awake()
|
||||
{
|
||||
foreach (var npc in GameObject.FindObjectsOfType<NPC>())
|
||||
@ -25,6 +25,7 @@ public class StatisticManager : MonoBehaviour
|
||||
GlobalEventManager.OnCaptureFlag += RegisterWin;
|
||||
GlobalEventManager.OnTimeLeft += RegisterTimeOut;
|
||||
GameManager.OnResetScene += SendMessage;
|
||||
|
||||
}
|
||||
|
||||
private void RegisterDamage(int damage, Team team)
|
||||
|
@ -1,24 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Target : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
|
||||
public float health = 50f;
|
||||
|
||||
public void TakeDamage(float amount)
|
||||
{
|
||||
health -= amount;
|
||||
if (health <= 0f)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
void Die()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Weapons/Target.cs.meta
generated
11
Assets/Scripts/Weapons/Target.cs.meta
generated
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 954fb0076c55707429047d7d4a3e8ded
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user