maint: clean-up of some combat related classes and methods for clarity
This commit is contained in:
@@ -1,51 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Drawing;
|
||||
using NodeCanvas.BehaviourTrees;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.StateMachines;
|
||||
using Reset;
|
||||
using Reset.Units;
|
||||
using Unity.Collections;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class Unit : NetworkBehaviour, INetworkSerializeByMemcpy{
|
||||
|
||||
public string state;
|
||||
|
||||
public NetworkVariable<FixedString64Bytes> testSTate;
|
||||
|
||||
private FSMOwner fsm;
|
||||
// References
|
||||
private FSMOwner _fsm;
|
||||
internal FSMOwner FSM{
|
||||
get{ if (!_fsm) { _fsm = GetComponent<FSMOwner>(); } return _fsm; }
|
||||
}
|
||||
|
||||
private UnitMovementHandler _movement;
|
||||
internal UnitMovementHandler Movement{
|
||||
get{
|
||||
if (!_movement) {
|
||||
_movement = GetComponent<UnitMovementHandler>();
|
||||
}
|
||||
|
||||
return _movement;
|
||||
}
|
||||
get{ if (!_movement) { _movement = GetComponent<UnitMovementHandler>(); } return _movement; }
|
||||
}
|
||||
|
||||
private GraphOwner _graph;
|
||||
internal GraphOwner Graph{
|
||||
get{
|
||||
if (!_graph) {
|
||||
_graph = GetComponent<GraphOwner>();
|
||||
}
|
||||
|
||||
return _graph;
|
||||
}
|
||||
get{ if (!_graph) { _graph = GetComponent<GraphOwner>(); } return _graph; }
|
||||
}
|
||||
|
||||
private void Awake(){
|
||||
fsm = GetComponent<FSMOwner>();
|
||||
}
|
||||
|
||||
|
||||
// Debug and Gizmos
|
||||
public NetworkVariable<FixedString64Bytes> graphStateAsString;
|
||||
|
||||
public virtual void Start(){
|
||||
UnitStart();
|
||||
}
|
||||
@@ -67,17 +48,14 @@ namespace Reset.Units{
|
||||
|
||||
protected virtual void Update(){
|
||||
UpdateGizmos();
|
||||
}
|
||||
|
||||
// Draw Gizmos
|
||||
void UpdateGizmos(){
|
||||
if (GetComponent<IKillable>() != null) {
|
||||
GetComponent<IKillable>().DrawHealthDebug();
|
||||
}
|
||||
|
||||
UnitUpdate();
|
||||
}
|
||||
|
||||
public virtual void UnitUpdate(){ }
|
||||
|
||||
void UpdateGizmos(){
|
||||
|
||||
DrawOnlineStatusGizmo();
|
||||
DrawStateGizmo();
|
||||
}
|
||||
@@ -104,50 +82,34 @@ namespace Reset.Units{
|
||||
SetNewPosition(position);
|
||||
}
|
||||
|
||||
|
||||
public void SetNewPosition(Vector3 position){
|
||||
// Set position, disabling the character controller if one is available
|
||||
var contr = GetComponent<CharacterController>();
|
||||
|
||||
if (contr)
|
||||
contr.enabled = false;
|
||||
if (contr) contr.enabled = false;
|
||||
|
||||
transform.position = position;
|
||||
|
||||
if (contr)
|
||||
contr.enabled = true;
|
||||
if (contr) contr.enabled = true;
|
||||
}
|
||||
|
||||
|
||||
private void DrawStateGizmo(){
|
||||
if (fsm && UnitIsLocal()) {
|
||||
testSTate.Value = fsm.currentRootStateName;
|
||||
// if (UnitIsNetworked()) {
|
||||
// // state = fsm.currentRootStateName;
|
||||
// SendStateInformationRpc(fsm.currentRootStateName);
|
||||
// } else {
|
||||
// state = fsm.currentRootStateName;
|
||||
// }
|
||||
} else {
|
||||
fsm = GetComponent<FSMOwner>();
|
||||
// Get state from FSM
|
||||
if (UnitIsLocal()) {
|
||||
graphStateAsString.Value = FSM.currentRootStateName;
|
||||
}
|
||||
|
||||
// state = state.ToString().ToUpper();
|
||||
|
||||
// Draw state gizmo, regardless of if local or not
|
||||
try {
|
||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2.7f, testSTate.Value.ToString(), Color.red);
|
||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2.7f, graphStateAsString.Value.ToString(),
|
||||
Color.red);
|
||||
} catch (Exception e) {
|
||||
Debug.LogError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
public void SendStateInformationRpc(string newState){
|
||||
Debug.Log($"newstate! {newState}");
|
||||
state = newState;
|
||||
}
|
||||
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void TakeOwnershipRpc(ulong clientID){
|
||||
GetComponent<NetworkObject>().ChangeOwnership(clientID);
|
||||
public void TakeOwnershipRpc(ulong newOwnerID){
|
||||
GetComponent<NetworkObject>().ChangeOwnership(newOwnerID);
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
|
||||
Reference in New Issue
Block a user