2using System.Runtime.CompilerServices;
3using System.Security.Cryptography;
9 public delegate
void NetworkMessageDelegate(NetworkConnection conn, NetworkReader reader,
int channelId);
12 public delegate GameObject SpawnDelegate(Vector3 position, Guid assetId);
14 public delegate GameObject SpawnHandlerDelegate(SpawnMessage msg);
17 public delegate
void UnSpawnDelegate(GameObject spawned);
28 public const int Reliable = 0;
29 public const int Unreliable = 1;
34 public static uint GetTrueRandomUInt()
37 using (RNGCryptoServiceProvider rng =
new RNGCryptoServiceProvider())
39 byte[] bytes =
new byte[4];
41 return BitConverter.ToUInt32(bytes, 0);
45 public static bool IsPrefab(GameObject obj)
48 return UnityEditor.PrefabUtility.IsPartOfPrefabAsset(obj);
54 public static bool IsSceneObjectWithPrefabParent(GameObject gameObject, out GameObject prefab)
59 if (!UnityEditor.PrefabUtility.IsPartOfPrefabInstance(gameObject))
63 prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
68 Debug.LogError($
"Failed to find prefab parent for scene object [name:{gameObject.name}]");
76 [MethodImpl(MethodImplOptions.AggressiveInlining)]
77 public static bool IsPointInScreen(Vector2 point) =>
78 0 <= point.x && point.x < Screen.width &&
79 0 <= point.y && point.y < Screen.height;
84 public static string PrettyBytes(
long bytes)
90 else if (bytes < 1024L * 1024L)
91 return $
"{(bytes / 1024f):F2} KB";
93 else if (bytes < 1024 * 1024L * 1024L)
94 return $
"{(bytes / (1024f * 1024f)):F2} MB";
96 return $
"{(bytes / (1024f * 1024f * 1024f)):F2} GB";
100 [MethodImpl(MethodImplOptions.AggressiveInlining)]
NetworkClient with connection to server.
static bool active
active is true while a client is connecting/connected
static readonly Dictionary< uint, NetworkIdentity > spawned
All spawned NetworkIdentities by netId.
NetworkIdentity identifies objects across the network.
NetworkServer handles remote connections and has a local connection for a local client.
static bool active
active checks if the server has been started
static readonly Dictionary< uint, NetworkIdentity > spawned
All spawned NetworkIdentities by netId.