123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Runtime.InteropServices;
- using System.Security.Cryptography;
- using UnityEngine;
- namespace Mirror
- {
-
- public delegate void NetworkMessageDelegate(NetworkConnection conn, NetworkReader reader, int channelId);
-
- public delegate GameObject SpawnDelegate(Vector3 position, Guid assetId);
- public delegate GameObject SpawnHandlerDelegate(SpawnMessage msg);
-
- public delegate void UnSpawnDelegate(GameObject spawned);
-
- public enum MirrorInvokeType
- {
- Command,
- ClientRpc
- }
-
- [Obsolete("Version has never been used, neither by UNET nor by Mirror.")]
- public enum Version
- {
- Current = 1
- }
-
-
-
-
-
-
-
- public static class Channels
- {
- public const int Reliable = 0;
- public const int Unreliable = 1;
-
- [Obsolete("Use Channels.Reliable instead")]
- public const int DefaultReliable = Reliable;
-
- [Obsolete("Use Channels.Unreliable instead")]
- public const int DefaultUnreliable = Unreliable;
- }
-
- [StructLayout(LayoutKind.Explicit)]
- internal struct UIntFloat
- {
- [FieldOffset(0)]
- public float floatValue;
- [FieldOffset(0)]
- public uint intValue;
- }
- [StructLayout(LayoutKind.Explicit)]
- internal struct UIntDouble
- {
- [FieldOffset(0)]
- public double doubleValue;
- [FieldOffset(0)]
- public ulong longValue;
- }
- [StructLayout(LayoutKind.Explicit)]
- internal struct UIntDecimal
- {
- [FieldOffset(0)]
- public ulong longValue1;
- [FieldOffset(8)]
- public ulong longValue2;
- [FieldOffset(0)]
- public decimal decimalValue;
- }
- public static class Utils
- {
- public static uint GetTrueRandomUInt()
- {
-
- using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
- {
- byte[] bytes = new byte[4];
- rng.GetBytes(bytes);
- return BitConverter.ToUInt32(bytes, 0);
- }
- }
- public static bool IsPrefab(GameObject obj)
- {
- #if UNITY_EDITOR
- return UnityEditor.PrefabUtility.IsPartOfPrefabAsset(obj);
- #else
- return false;
- #endif
- }
- public static bool IsSceneObjectWithPrefabParent(GameObject gameObject, out GameObject prefab)
- {
- prefab = null;
- #if UNITY_EDITOR
- if (!UnityEditor.PrefabUtility.IsPartOfPrefabInstance(gameObject))
- {
- return false;
- }
- prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
- #endif
- if (prefab == null)
- {
- Debug.LogError("Failed to find prefab parent for scene object [name:" + gameObject.name + "]");
- return false;
- }
- return true;
- }
-
-
- public static bool IsPointInScreen(Vector2 point) =>
- 0 <= point.x && point.x < Screen.width &&
- 0 <= point.y && point.y < Screen.height;
- }
- }
|