Definition at line 32 of file Utils.cs.
◆ GetSpawnedInServerOrClient()
static NetworkIdentity Mirror.Utils.GetSpawnedInServerOrClient |
( |
uint |
netId | ) |
|
|
static |
Definition at line 101 of file Utils.cs.
102 {
103
104
105 if (NetworkServer.active)
106 {
107 NetworkServer.spawned.TryGetValue(netId, out NetworkIdentity entry);
108 return entry;
109 }
110
111
112 if (NetworkClient.active)
113 {
114 NetworkClient.spawned.TryGetValue(netId, out NetworkIdentity entry);
115 return entry;
116 }
117
118 return null;
119 }
◆ GetTrueRandomUInt()
static uint Mirror.Utils.GetTrueRandomUInt |
( |
| ) |
|
|
static |
Definition at line 34 of file Utils.cs.
35 {
36
37 using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
38 {
39 byte[] bytes = new byte[4];
40 rng.GetBytes(bytes);
41 return BitConverter.ToUInt32(bytes, 0);
42 }
43 }
◆ IsPrefab()
static bool Mirror.Utils.IsPrefab |
( |
GameObject |
obj | ) |
|
|
static |
Definition at line 45 of file Utils.cs.
46 {
47#if UNITY_EDITOR
48 return UnityEditor.PrefabUtility.IsPartOfPrefabAsset(obj);
49#else
50 return false;
51#endif
52 }
◆ IsSceneObjectWithPrefabParent()
static bool Mirror.Utils.IsSceneObjectWithPrefabParent |
( |
GameObject |
gameObject, |
|
|
out GameObject |
prefab |
|
) |
| |
|
static |
Definition at line 54 of file Utils.cs.
55 {
56 prefab = null;
57
58#if UNITY_EDITOR
59 if (!UnityEditor.PrefabUtility.IsPartOfPrefabInstance(gameObject))
60 {
61 return false;
62 }
63 prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
64#endif
65
66 if (prefab == null)
67 {
68 Debug.LogError($"Failed to find prefab parent for scene object [name:{gameObject.name}]");
69 return false;
70 }
71 return true;
72 }
◆ PrettyBytes()
static string Mirror.Utils.PrettyBytes |
( |
long |
bytes | ) |
|
|
static |
Definition at line 84 of file Utils.cs.
85 {
86
87 if (bytes < 1024)
88 return $"{bytes} B";
89
90 else if (bytes < 1024L * 1024L)
91 return $"{(bytes / 1024f):F2} KB";
92
93 else if (bytes < 1024 * 1024L * 1024L)
94 return $"{(bytes / (1024f * 1024f)):F2} MB";
95
96 return $"{(bytes / (1024f * 1024f * 1024f)):F2} GB";
97 }