From 171805abc68368dc152d1cff139a0a779a7518a8 Mon Sep 17 00:00:00 2001 From: Gwilym Hughes Date: Tue, 24 Aug 2021 19:11:23 +0100 Subject: [PATCH 1/4] Removing {get; set;} from the Vectors and making the class Serializable --- .../Bearded Man Studios Inc/Scripts/Networking/Vector.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs index 9883f7b0..3f6dd2d2 100644 --- a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs +++ b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs @@ -2,13 +2,14 @@ namespace BeardedManStudios { + [System.Serializable] public struct Vector { - public float x { get; set; } + public float x; - public float y { get; set; } + public float y; - public float z { get; set; } + public float z; /// /// Get's the magnitude (pythagorean theorem) of this vector (the length From 5cc672e49a61883f89659dd5272440c43dbfa98b Mon Sep 17 00:00:00 2001 From: Gwilym Hughes Date: Tue, 24 Aug 2021 19:13:07 +0100 Subject: [PATCH 2/4] Adding comparisons to normal Vectors --- .../Scripts/Networking/Vector.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs index 3f6dd2d2..c5af5c7d 100644 --- a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs +++ b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Vector.cs @@ -55,6 +55,33 @@ public Vector(float x, float y, float z) : this() this.z = z; } + public static implicit operator UnityEngine.Vector3(Vector x) + { + return new UnityEngine.Vector3(x.x, x.y, x.z); + } + + public static implicit operator Vector(UnityEngine.Vector3 x) + { + return new Vector(x.x, x.y, x.z); + } + + public static bool operator ==(Vector lhs, Vector rhs) + { + // If both null, true + if(ReferenceEquals(lhs, rhs)) return true; + + // Else, any nulls are false + if(ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) return false; + + // Equals handles case of null on right side. + return lhs.Equals(rhs); + } + + public static bool operator !=(Vector lhs, Vector rhs) + { + return !(lhs == rhs); + } + /// /// Get's the dot product of this vector and another /// From ff3223b76f059a8f9eae00f022080af414103416 Mon Sep 17 00:00:00 2001 From: Gwilym Hughes Date: Tue, 24 Aug 2021 19:18:15 +0100 Subject: [PATCH 3/4] I had to add this in two places so it didnt double load the scene (i dont use automatic scene swapping) --- .../Bearded Man Studios Inc/Scripts/NetworkManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/NetworkManager.cs b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/NetworkManager.cs index b6b228e5..c322d099 100644 --- a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/NetworkManager.cs +++ b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/NetworkManager.cs @@ -465,6 +465,9 @@ protected virtual void ReadBinary(NetworkingPlayer player, Binary frame, NetWork if (scenesToLoad.Length == 0) return; + if (!automaticScenes) + return; + SceneManager.LoadScene(scenesToLoad[0], LoadSceneMode.Single); for (int i = 1; i < scenesToLoad.Length; i++) @@ -513,6 +516,9 @@ protected virtual void ReadBinary(NetworkingPlayer player, Binary frame, NetWork MainThreadManager.Run(() => { + if (!automaticScenes) + return; + // Load the scene that the server loaded in the same LoadSceneMode if (mode == LoadSceneMode.Additive) SceneManager.LoadSceneAsync(sceneIndex, LoadSceneMode.Additive); From edf7cbc1e821550aeaf0cbe2eb0e11a7ec7e6285 Mon Sep 17 00:00:00 2001 From: Gwilym Hughes Date: Tue, 24 Aug 2021 19:23:26 +0100 Subject: [PATCH 4/4] Added a friendly way to get the name of the RPC from the methodId - useful in making debug messages more readable --- .../Networking/Forge/Networking/Objects/NetworkObject.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Forge/Networking/Objects/NetworkObject.cs b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Forge/Networking/Objects/NetworkObject.cs index 8f07a240..c4f821ab 100644 --- a/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Forge/Networking/Objects/NetworkObject.cs +++ b/Forge Networking Remastered Unity/Assets/Bearded Man Studios Inc/Scripts/Networking/Forge/Networking/Objects/NetworkObject.cs @@ -171,6 +171,11 @@ public abstract class NetworkObject /// protected Dictionary inverseRpcLookup = new Dictionary(); + /// + /// Get the friendly name from the Method ID - useful for Debug output + /// + public string RPCName(byte methodId) => inverseRpcLookup[methodId]; + /// /// Is true if this object has been fully setup on the network ///