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 async void UnitStart(){ try { var netWaitResult = await WaitForNetwork(); if (netWaitResult) { } // OnlineStart(); Debug.Log("Done"); } catch { throw; } } public async Task WaitForNetwork(){ while (!NetworkManager.Singleton.IsConnectedClient) { await Awaitable.NextFrameAsync(); } return (NetworkManager.Singleton.IsConnectedClient); } 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() != null) { GetComponent().DrawHealthDebug(); } } 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); } protected override void OnNetworkPostSpawn(){ // GetComponent().AttachCamera(gameObject); } } }