64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Threading.Tasks;
|
|
using Drawing;
|
|
using Reset;
|
|
using Reset.Units;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace Reset.Units{
|
|
public class Unit : NetworkBehaviour{
|
|
public virtual void Start(){
|
|
UnitStart();
|
|
}
|
|
|
|
public virtual void UnitStart(){ }
|
|
|
|
public bool UnitIsNetworked(){
|
|
return NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsHost;
|
|
}
|
|
|
|
public bool UnitIsLocal(){
|
|
if (UnitIsNetworked()) {
|
|
return IsOwner;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected virtual void Update(){
|
|
UpdateGizmos();
|
|
|
|
if (GetComponent<IKillable>() != null) {
|
|
GetComponent<IKillable>().DrawHealthDebug();
|
|
}
|
|
|
|
UnitUpdate();
|
|
}
|
|
|
|
public virtual void UnitUpdate(){ }
|
|
|
|
void UpdateGizmos(){
|
|
string onlineStatus = "Not Online";
|
|
Color onlineColor = Color.gray;
|
|
|
|
if (UnitIsNetworked() && UnitIsLocal()) {
|
|
onlineStatus = "Online, Owned";
|
|
onlineColor = Color.mediumSeaGreen;
|
|
} else if (UnitIsNetworked() && !IsSpawned) {
|
|
onlineStatus = "Not Spawned";
|
|
} else if (UnitIsNetworked()) {
|
|
onlineStatus = "Online, Not Owned";
|
|
onlineColor = Color.gold;
|
|
}
|
|
|
|
Draw.ingame.Label2D(transform.position + Vector3.up * 2.5f, onlineStatus, onlineColor);
|
|
}
|
|
|
|
[Rpc(SendTo.Owner)]
|
|
public void TakeOwnershipRpc(ulong clientID){
|
|
GetComponent<NetworkObject>().ChangeOwnership(clientID);
|
|
}
|
|
}
|
|
} |