using FishNet.Object; using FishNet.Object.Synchronizing; using FishNet.Connection; using FishNet; using log4net; using System.Reflection; public class ClientInstance : NetworkBehaviour { private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); #region Sync private readonly SyncVar username = new(); #endregion #region Username public string Username { get => username.Value; set => username.Value = value; } #endregion #region Helper public static ClientInstance ReturnClientInstance(NetworkConnection conn) { if (InstanceFinder.IsServerStarted && conn != null) { // Expects the client instance to be the very first object of that connection NetworkObject nob = conn.FirstObject; return (nob == null) ? null : nob.GetComponent(); } else { Log.Warn("Unable to find client instance"); return null; } } #endregion }