added: full logic and ability for downing and picking up allies
This commit is contained in:
@@ -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); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user