added: full logic and ability for downing and picking up allies

This commit is contained in:
Chris
2025-10-20 16:36:23 -04:00
parent 021e664320
commit 0bb10a8f46
10 changed files with 489 additions and 64 deletions

View File

@@ -2,16 +2,54 @@
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{
public class Unit : NetworkBehaviour, INetworkSerializeByMemcpy{
public string state;
public NetworkVariable<FixedString64Bytes> testSTate;
private FSMOwner fsm;
private UnitMovementHandler _movement;
internal UnitMovementHandler Movement{
get{
if (!_movement) {
_movement = GetComponent<UnitMovementHandler>();
}
return _movement;
}
}
private GraphOwner _graph;
internal GraphOwner Graph{
get{
if (!_graph) {
_graph = GetComponent<GraphOwner>();
}
return _graph;
}
}
private void Awake(){
fsm = GetComponent<FSMOwner>();
}
public virtual void Start(){
UnitStart();
}
public virtual void UnitStart(){ }
@@ -36,10 +74,17 @@ namespace Reset.Units{
UnitUpdate();
}
public virtual void SetNewPosition(Vector3 position){ }
public virtual void UnitUpdate(){ }
void UpdateGizmos(){
DrawOnlineStatusGizmo();
DrawStateGizmo();
}
private void DrawOnlineStatusGizmo(){
string onlineStatus = "Not Online";
Color onlineColor = Color.gray;
@@ -55,10 +100,44 @@ namespace Reset.Units{
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
}
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>();
}
// state = state.ToString().ToUpper();
try {
Draw.ingame.Label2D(transform.position + Vector3.up * 2.7f, testSTate.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);
}
[Rpc(SendTo.Owner)]
public void DoGraphEventRpc(string eventToSend){
Debug.Log(eventToSend);
GetComponent<FSMOwner>().SendEvent(eventToSend); }
}
}