mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 18:40:03 +00:00
remove custom types
This commit is contained in:
parent
f4f2e93b5e
commit
d9e5f6184f
@ -99,8 +99,8 @@ namespace QSB
|
||||
{
|
||||
var ident = go.AddComponent<QSBNetworkIdentity>();
|
||||
ident.LocalPlayerAuthority = true;
|
||||
ident.SetValue("m_AssetId", (QSBNetworkHash128)playerPrefab.GetComponent<NetworkIdentity>().assetId);
|
||||
ident.SetValue("m_SceneId", (QSBNetworkSceneId)playerPrefab.GetComponent<NetworkIdentity>().sceneId);
|
||||
ident.SetValue("m_AssetId", playerPrefab.GetComponent<NetworkIdentity>().assetId);
|
||||
ident.SetValue("m_SceneId", playerPrefab.GetComponent<NetworkIdentity>().sceneId);
|
||||
}
|
||||
|
||||
private void SetupNetworkTransform(GameObject go)
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Components
|
||||
{
|
||||
@ -14,9 +15,9 @@ namespace QuantumUNET.Components
|
||||
public bool IsServer => m_IsServer && QSBNetworkServer.active && m_IsServer;
|
||||
public bool HasAuthority { get; private set; }
|
||||
public QSBNetworkInstanceId NetId { get; private set; }
|
||||
public QSBNetworkSceneId SceneId => m_SceneId;
|
||||
public NetworkSceneId SceneId => m_SceneId;
|
||||
public QSBNetworkConnection ClientAuthorityOwner { get; private set; }
|
||||
public QSBNetworkHash128 AssetId => m_AssetId;
|
||||
public NetworkHash128 AssetId => m_AssetId;
|
||||
public bool IsLocalPlayer { get; private set; }
|
||||
public short PlayerControllerId { get; private set; } = -1;
|
||||
public QSBNetworkConnection ConnectionToServer { get; private set; }
|
||||
@ -64,7 +65,7 @@ namespace QuantumUNET.Components
|
||||
internal void RemoveSubIdentity(QSBNetworkIdentity identityToRemove)
|
||||
=> SubIdentities.Remove(identityToRemove);
|
||||
|
||||
internal void SetDynamicAssetId(QSBNetworkHash128 newAssetId)
|
||||
internal void SetDynamicAssetId(NetworkHash128 newAssetId)
|
||||
{
|
||||
if (!m_AssetId.IsValid() || m_AssetId.Equals(newAssetId))
|
||||
{
|
||||
@ -153,7 +154,7 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceSceneId(int newSceneId) => m_SceneId = new QSBNetworkSceneId((uint)newSceneId);
|
||||
public void ForceSceneId(int newSceneId) => m_SceneId = new NetworkSceneId((uint)newSceneId);
|
||||
|
||||
internal void UpdateClientServer(bool isClientFlag, bool isServerFlag)
|
||||
{
|
||||
@ -967,10 +968,10 @@ namespace QuantumUNET.Components
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private QSBNetworkSceneId m_SceneId;
|
||||
private NetworkSceneId m_SceneId;
|
||||
|
||||
[SerializeField]
|
||||
private QSBNetworkHash128 m_AssetId;
|
||||
private NetworkHash128 m_AssetId;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_ServerOnly;
|
||||
|
@ -1,12 +1,13 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectSpawnMessage : QSBMessageBase
|
||||
{
|
||||
public QSBNetworkInstanceId NetId;
|
||||
public QSBNetworkHash128 assetId;
|
||||
public NetworkHash128 assetId;
|
||||
public Vector3 Position;
|
||||
public byte[] Payload;
|
||||
public Quaternion Rotation;
|
||||
|
@ -1,12 +1,13 @@
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET.Messages
|
||||
{
|
||||
internal class QSBObjectSpawnSceneMessage : QSBMessageBase
|
||||
{
|
||||
public QSBNetworkInstanceId NetId;
|
||||
public QSBNetworkSceneId SceneId;
|
||||
public NetworkSceneId SceneId;
|
||||
public Vector3 Position;
|
||||
public byte[] Payload;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
public delegate GameObject QSBSpawnDelegate(Vector3 position, QSBNetworkHash128 assetId);
|
||||
public delegate GameObject QSBSpawnDelegate(Vector3 position, NetworkHash128 assetId);
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ namespace QuantumUNET
|
||||
|
||||
public static Dictionary<QSBNetworkInstanceId, QSBNetworkIdentity> Objects => s_NetworkScene.localObjects;
|
||||
|
||||
public static Dictionary<QSBNetworkHash128, GameObject> Prefabs => QSBNetworkScene.guidToPrefab;
|
||||
public static Dictionary<NetworkHash128, GameObject> Prefabs => QSBNetworkScene.guidToPrefab;
|
||||
|
||||
public static Dictionary<QSBNetworkSceneId, QSBNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
public static Dictionary<NetworkSceneId, QSBNetworkIdentity> SpawnableObjects { get; private set; }
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
@ -289,7 +289,7 @@ namespace QuantumUNET
|
||||
|
||||
internal static void PrepareToSpawnSceneObjects()
|
||||
{
|
||||
SpawnableObjects = new Dictionary<QSBNetworkSceneId, QSBNetworkIdentity>();
|
||||
SpawnableObjects = new Dictionary<NetworkSceneId, QSBNetworkIdentity>();
|
||||
foreach (var networkIdentity in Resources.FindObjectsOfTypeAll<QSBNetworkIdentity>())
|
||||
{
|
||||
if (!networkIdentity.gameObject.activeSelf)
|
||||
@ -309,7 +309,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static QSBNetworkIdentity SpawnSceneObject(QSBNetworkSceneId sceneId)
|
||||
internal static QSBNetworkIdentity SpawnSceneObject(NetworkSceneId sceneId)
|
||||
{
|
||||
QSBNetworkIdentity result;
|
||||
if (SpawnableObjects.ContainsKey(sceneId))
|
||||
@ -354,7 +354,7 @@ namespace QuantumUNET
|
||||
client.RegisterHandlerSafe(42, new QSBNetworkMessageDelegate(QSBNetworkAnimator.OnAnimationTriggerClientMessage));
|
||||
}
|
||||
|
||||
internal static string GetStringForAssetId(QSBNetworkHash128 assetId)
|
||||
internal static string GetStringForAssetId(NetworkHash128 assetId)
|
||||
{
|
||||
string result;
|
||||
if (QSBNetworkScene.GetPrefab(assetId, out var gameObject))
|
||||
@ -372,7 +372,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab, QSBNetworkHash128 newAssetId) => QSBNetworkScene.RegisterPrefab(prefab, newAssetId);
|
||||
public static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId) => QSBNetworkScene.RegisterPrefab(prefab, newAssetId);
|
||||
|
||||
public static void RegisterPrefab(GameObject prefab) => QSBNetworkScene.RegisterPrefab(prefab);
|
||||
|
||||
@ -380,9 +380,9 @@ namespace QuantumUNET
|
||||
|
||||
public static void UnregisterPrefab(GameObject prefab) => QSBNetworkScene.UnregisterPrefab(prefab);
|
||||
|
||||
public static void RegisterSpawnHandler(QSBNetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QSBNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
public static void RegisterSpawnHandler(NetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) => QSBNetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
|
||||
|
||||
public static void UnregisterSpawnHandler(QSBNetworkHash128 assetId) => QSBNetworkScene.UnregisterSpawnHandler(assetId);
|
||||
public static void UnregisterSpawnHandler(NetworkHash128 assetId) => QSBNetworkScene.UnregisterSpawnHandler(assetId);
|
||||
|
||||
public static void ClearSpawners() => QSBNetworkScene.ClearSpawners();
|
||||
|
||||
|
@ -1,129 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
[Serializable]
|
||||
public struct QSBNetworkHash128
|
||||
{
|
||||
public byte i0;
|
||||
public byte i1;
|
||||
public byte i2;
|
||||
public byte i3;
|
||||
public byte i4;
|
||||
public byte i5;
|
||||
public byte i6;
|
||||
public byte i7;
|
||||
public byte i8;
|
||||
public byte i9;
|
||||
public byte i10;
|
||||
public byte i11;
|
||||
public byte i12;
|
||||
public byte i13;
|
||||
public byte i14;
|
||||
public byte i15;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
i0 = 0;
|
||||
i1 = 0;
|
||||
i2 = 0;
|
||||
i3 = 0;
|
||||
i4 = 0;
|
||||
i5 = 0;
|
||||
i6 = 0;
|
||||
i7 = 0;
|
||||
i8 = 0;
|
||||
i9 = 0;
|
||||
i10 = 0;
|
||||
i11 = 0;
|
||||
i12 = 0;
|
||||
i13 = 0;
|
||||
i14 = 0;
|
||||
i15 = 0;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
=> (i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | i8 | i9 | i10 | i11 | i12 | i13 | i14 | i15) != 0;
|
||||
|
||||
private static int HexToNumber(char c)
|
||||
{
|
||||
int result;
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
result = c - '0';
|
||||
}
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
{
|
||||
result = c - 'a' + '\n';
|
||||
}
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
{
|
||||
result = c - 'A' + '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static QSBNetworkHash128 Parse(string text)
|
||||
{
|
||||
var length = text.Length;
|
||||
if (length < 32)
|
||||
{
|
||||
var str = "";
|
||||
for (var i = 0; i < 32 - length; i++)
|
||||
{
|
||||
str += "0";
|
||||
}
|
||||
text = str + text;
|
||||
}
|
||||
QSBNetworkHash128 result;
|
||||
result.i0 = (byte)(HexToNumber(text[0]) * 16 + HexToNumber(text[1]));
|
||||
result.i1 = (byte)(HexToNumber(text[2]) * 16 + HexToNumber(text[3]));
|
||||
result.i2 = (byte)(HexToNumber(text[4]) * 16 + HexToNumber(text[5]));
|
||||
result.i3 = (byte)(HexToNumber(text[6]) * 16 + HexToNumber(text[7]));
|
||||
result.i4 = (byte)(HexToNumber(text[8]) * 16 + HexToNumber(text[9]));
|
||||
result.i5 = (byte)(HexToNumber(text[10]) * 16 + HexToNumber(text[11]));
|
||||
result.i6 = (byte)(HexToNumber(text[12]) * 16 + HexToNumber(text[13]));
|
||||
result.i7 = (byte)(HexToNumber(text[14]) * 16 + HexToNumber(text[15]));
|
||||
result.i8 = (byte)(HexToNumber(text[16]) * 16 + HexToNumber(text[17]));
|
||||
result.i9 = (byte)(HexToNumber(text[18]) * 16 + HexToNumber(text[19]));
|
||||
result.i10 = (byte)(HexToNumber(text[20]) * 16 + HexToNumber(text[21]));
|
||||
result.i11 = (byte)(HexToNumber(text[22]) * 16 + HexToNumber(text[23]));
|
||||
result.i12 = (byte)(HexToNumber(text[24]) * 16 + HexToNumber(text[25]));
|
||||
result.i13 = (byte)(HexToNumber(text[26]) * 16 + HexToNumber(text[27]));
|
||||
result.i14 = (byte)(HexToNumber(text[28]) * 16 + HexToNumber(text[29]));
|
||||
result.i15 = (byte)(HexToNumber(text[30]) * 16 + HexToNumber(text[31]));
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0:x2}{1:x2}{2:x2}{3:x2}{4:x2}{5:x2}{6:x2}{7:x2}{8:x2}{9:x2}{10:x2}{11:x2}{12:x2}{13:x2}{14:x2}{15:x2}", new object[]
|
||||
{
|
||||
i0,
|
||||
i1,
|
||||
i2,
|
||||
i3,
|
||||
i4,
|
||||
i5,
|
||||
i6,
|
||||
i7,
|
||||
i8,
|
||||
i9,
|
||||
i10,
|
||||
i11,
|
||||
i12,
|
||||
i13,
|
||||
i14,
|
||||
i15
|
||||
});
|
||||
}
|
||||
|
||||
public static explicit operator QSBNetworkHash128(NetworkHash128 v)
|
||||
=> Parse(v.ToString());
|
||||
}
|
||||
}
|
@ -7,11 +7,11 @@ namespace QuantumUNET
|
||||
{
|
||||
internal class QSBNetworkScene
|
||||
{
|
||||
internal static Dictionary<QSBNetworkHash128, GameObject> guidToPrefab { get; } = new Dictionary<QSBNetworkHash128, GameObject>();
|
||||
internal static Dictionary<NetworkHash128, GameObject> guidToPrefab { get; } = new Dictionary<NetworkHash128, GameObject>();
|
||||
|
||||
internal static Dictionary<QSBNetworkHash128, QSBSpawnDelegate> spawnHandlers { get; } = new Dictionary<QSBNetworkHash128, QSBSpawnDelegate>();
|
||||
internal static Dictionary<NetworkHash128, QSBSpawnDelegate> spawnHandlers { get; } = new Dictionary<NetworkHash128, QSBSpawnDelegate>();
|
||||
|
||||
internal static Dictionary<QSBNetworkHash128, UnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<QSBNetworkHash128, UnSpawnDelegate>();
|
||||
internal static Dictionary<NetworkHash128, UnSpawnDelegate> unspawnHandlers { get; } = new Dictionary<NetworkHash128, UnSpawnDelegate>();
|
||||
|
||||
internal Dictionary<QSBNetworkInstanceId, QSBNetworkIdentity> localObjects { get; } = new Dictionary<QSBNetworkInstanceId, QSBNetworkIdentity>();
|
||||
|
||||
@ -92,7 +92,7 @@ namespace QuantumUNET
|
||||
|
||||
internal void ClearLocalObjects() => localObjects.Clear();
|
||||
|
||||
internal static void RegisterPrefab(GameObject prefab, QSBNetworkHash128 newAssetId)
|
||||
internal static void RegisterPrefab(GameObject prefab, NetworkHash128 newAssetId)
|
||||
{
|
||||
var component = prefab.GetComponent<QSBNetworkIdentity>();
|
||||
if (component)
|
||||
@ -127,7 +127,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool GetPrefab(QSBNetworkHash128 assetId, out GameObject prefab)
|
||||
internal static bool GetPrefab(NetworkHash128 assetId, out GameObject prefab)
|
||||
{
|
||||
bool result;
|
||||
if (!assetId.IsValid())
|
||||
@ -155,13 +155,13 @@ namespace QuantumUNET
|
||||
unspawnHandlers.Clear();
|
||||
}
|
||||
|
||||
public static void UnregisterSpawnHandler(QSBNetworkHash128 assetId)
|
||||
public static void UnregisterSpawnHandler(NetworkHash128 assetId)
|
||||
{
|
||||
spawnHandlers.Remove(assetId);
|
||||
unspawnHandlers.Remove(assetId);
|
||||
}
|
||||
|
||||
internal static void RegisterSpawnHandler(QSBNetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
internal static void RegisterSpawnHandler(NetworkHash128 assetId, QSBSpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
|
||||
{
|
||||
if (spawnHandler == null || unspawnHandler == null)
|
||||
{
|
||||
@ -216,7 +216,7 @@ namespace QuantumUNET
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool GetSpawnHandler(QSBNetworkHash128 assetId, out QSBSpawnDelegate handler)
|
||||
internal static bool GetSpawnHandler(NetworkHash128 assetId, out QSBSpawnDelegate handler)
|
||||
{
|
||||
bool result;
|
||||
if (spawnHandlers.ContainsKey(assetId))
|
||||
@ -232,7 +232,7 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool InvokeUnSpawnHandler(QSBNetworkHash128 assetId, GameObject obj)
|
||||
internal static bool InvokeUnSpawnHandler(NetworkHash128 assetId, GameObject obj)
|
||||
{
|
||||
bool result;
|
||||
if (unspawnHandlers.ContainsKey(assetId) && unspawnHandlers[assetId] != null)
|
||||
|
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QuantumUNET
|
||||
{
|
||||
[Serializable]
|
||||
public struct QSBNetworkSceneId
|
||||
{
|
||||
public uint Value => m_Value;
|
||||
|
||||
[SerializeField]
|
||||
private uint m_Value;
|
||||
|
||||
public QSBNetworkSceneId(uint value)
|
||||
{
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
=> m_Value == 0U;
|
||||
|
||||
public override int GetHashCode()
|
||||
=> (int)m_Value;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is QSBNetworkSceneId id && this == id;
|
||||
|
||||
public static bool operator ==(QSBNetworkSceneId c1, QSBNetworkSceneId c2)
|
||||
=> c1.m_Value == c2.m_Value;
|
||||
|
||||
public static bool operator !=(QSBNetworkSceneId c1, QSBNetworkSceneId c2)
|
||||
=> c1.m_Value != c2.m_Value;
|
||||
|
||||
public override string ToString() => m_Value.ToString();
|
||||
|
||||
public static explicit operator QSBNetworkSceneId(NetworkSceneId v)
|
||||
{
|
||||
return new QSBNetworkSceneId
|
||||
{
|
||||
m_Value = v.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1430,14 +1430,14 @@ namespace QuantumUNET
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool SpawnWithClientAuthority(GameObject obj, QSBNetworkHash128 assetId, QSBNetworkConnection conn)
|
||||
public static bool SpawnWithClientAuthority(GameObject obj, NetworkHash128 assetId, QSBNetworkConnection conn)
|
||||
{
|
||||
Spawn(obj, assetId);
|
||||
var component = obj.GetComponent<QSBNetworkIdentity>();
|
||||
return !(component == null) && component.IsServer && component.AssignClientAuthority(conn);
|
||||
}
|
||||
|
||||
public static void Spawn(GameObject obj, QSBNetworkHash128 assetId)
|
||||
public static void Spawn(GameObject obj, NetworkHash128 assetId)
|
||||
{
|
||||
if (VerifyCanSpawn(obj))
|
||||
{
|
||||
|
@ -121,12 +121,10 @@
|
||||
<Compile Include="Components\QSBNetworkManagerUNET.cs" />
|
||||
<Compile Include="Messages\QSBNetworkMessage.cs" />
|
||||
<Compile Include="Messages\QSBNetworkMessageDelegate.cs" />
|
||||
<Compile Include="QSBNetworkHash128.cs" />
|
||||
<Compile Include="QSBNetworkInstanceId.cs" />
|
||||
<Compile Include="QSBNetworkMessageHandlers.cs" />
|
||||
<Compile Include="Transport\QSBNetworkReader.cs" />
|
||||
<Compile Include="QSBNetworkScene.cs" />
|
||||
<Compile Include="QSBNetworkSceneId.cs" />
|
||||
<Compile Include="QSBNetworkServer.cs" />
|
||||
<Compile Include="QSBNetworkServerSimple.cs" />
|
||||
<Compile Include="Components\QSBNetworkTransform.cs" />
|
||||
|
@ -164,7 +164,7 @@ namespace QuantumUNET.Transport
|
||||
|
||||
public QSBNetworkInstanceId ReadNetworkId() => new QSBNetworkInstanceId(ReadPackedUInt32());
|
||||
|
||||
public QSBNetworkSceneId ReadSceneId() => new QSBNetworkSceneId(ReadPackedUInt32());
|
||||
public NetworkSceneId ReadSceneId() => new NetworkSceneId(ReadPackedUInt32());
|
||||
|
||||
public byte ReadByte() => m_buf.ReadByte();
|
||||
|
||||
@ -363,9 +363,9 @@ namespace QuantumUNET.Transport
|
||||
};
|
||||
}
|
||||
|
||||
public QSBNetworkHash128 ReadNetworkHash128()
|
||||
public NetworkHash128 ReadNetworkHash128()
|
||||
{
|
||||
QSBNetworkHash128 result;
|
||||
NetworkHash128 result;
|
||||
result.i0 = ReadByte();
|
||||
result.i1 = ReadByte();
|
||||
result.i2 = ReadByte();
|
||||
|
@ -154,7 +154,7 @@ namespace QuantumUNET.Transport
|
||||
|
||||
public void Write(QSBNetworkInstanceId value) => WritePackedUInt32(value.Value);
|
||||
|
||||
public void Write(QSBNetworkSceneId value) => WritePackedUInt32(value.Value);
|
||||
public void Write(NetworkSceneId value) => WritePackedUInt32(value.Value);
|
||||
|
||||
public void Write(char value) => m_Buffer.WriteByte((byte)value);
|
||||
|
||||
@ -373,7 +373,7 @@ namespace QuantumUNET.Transport
|
||||
Write(value.m33);
|
||||
}
|
||||
|
||||
public void Write(QSBNetworkHash128 value)
|
||||
public void Write(NetworkHash128 value)
|
||||
{
|
||||
Write(value.i0);
|
||||
Write(value.i1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user