diff --git a/Runtime/NetworkComponent.cs b/Runtime/NetworkComponent.cs index 0dead22..9b859bf 100644 --- a/Runtime/NetworkComponent.cs +++ b/Runtime/NetworkComponent.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace VelNetUnity +namespace VelNet { public abstract class NetworkComponent : MonoBehaviour { @@ -24,7 +24,6 @@ namespace VelNetUnity networkObject.SendBytesToGroup(this, group, message, reliable); } - // /// /// This is called by when messages are received for this component /// diff --git a/Runtime/NetworkObject.cs b/Runtime/NetworkObject.cs index e4139db..1193745 100644 --- a/Runtime/NetworkObject.cs +++ b/Runtime/NetworkObject.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace VelNetUnity +namespace VelNet { /// /// This is a base class for all objects that a player can instantiated/owned @@ -43,7 +43,7 @@ namespace VelNetUnity public void SendBytesToGroup(NetworkComponent component, string group, byte[] message, bool reliable = true) { - if (owner == null || !owner.isLocal) + if (!IsMine) { Debug.LogError("Can't send message if owner is null or not local", this); return; diff --git a/Runtime/NetworkPlayer.cs b/Runtime/NetworkPlayer.cs index 448c6b2..f84dafe 100644 --- a/Runtime/NetworkPlayer.cs +++ b/Runtime/NetworkPlayer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System; -namespace VelNetUnity +namespace VelNet { /// /// Represents a network player @@ -53,10 +53,11 @@ namespace VelNetUnity } } - + /// + /// These are generally things that come from the "owner" and should be enacted locally, where appropriate + /// public void HandleMessage(VelNetManager.Message m) { - //these are generally things that come from the "owner" and should be enacted locally, where appropriate //we need to parse the message //types of messages @@ -104,7 +105,7 @@ namespace VelNetUnity break; //we already have this one, ignore } - VelNetManager.InstantiateNetworkObject(networkId, prefabName, this); + VelNetManager.SomebodyInstantiatedNetworkObject(networkId, prefabName, this); break; } diff --git a/Runtime/NetworkSerializedObject.cs b/Runtime/NetworkSerializedObject.cs index 162ced2..ef1aa14 100644 --- a/Runtime/NetworkSerializedObject.cs +++ b/Runtime/NetworkSerializedObject.cs @@ -2,7 +2,7 @@ using UnityEngine; using UnityEngine.Serialization; -namespace VelNetUnity +namespace VelNet { public abstract class NetworkSerializedObject : NetworkComponent { diff --git a/Runtime/Util/BinaryWriterExtensions.cs b/Runtime/Util/BinaryWriterExtensions.cs index a07fc60..f122745 100644 --- a/Runtime/Util/BinaryWriterExtensions.cs +++ b/Runtime/Util/BinaryWriterExtensions.cs @@ -1,7 +1,7 @@ using System.IO; using UnityEngine; -namespace VelNetUnity +namespace VelNet { public static class BinaryWriterExtensions { diff --git a/Runtime/Util/SyncTransform.cs b/Runtime/Util/SyncTransform.cs index 5cb2b50..231a0eb 100644 --- a/Runtime/Util/SyncTransform.cs +++ b/Runtime/Util/SyncTransform.cs @@ -2,12 +2,12 @@ using System.IO; using UnityEngine; -namespace VelNetUnity +namespace VelNet { /// /// A simple class that will sync the position and rotation of a network object /// - [AddComponentMenu("VelNetUnity/VelNet Sync Transform")] + [AddComponentMenu("VelNet/VelNet Sync Transform")] public class SyncTransform : NetworkSerializedObject { public Vector3 targetPosition; diff --git a/Runtime/VelNetManager.cs b/Runtime/VelNetManager.cs index 140d231..b46ee81 100644 --- a/Runtime/VelNetManager.cs +++ b/Runtime/VelNetManager.cs @@ -7,9 +7,9 @@ using System.Threading; using UnityEngine; using System.Net; -namespace VelNetUnity +namespace VelNet { - [AddComponentMenu("VelNetUnity/VelNet Manager")] + [AddComponentMenu("VelNet/VelNet Manager")] public class VelNetManager : MonoBehaviour { public enum MessageType @@ -332,38 +332,36 @@ namespace VelNetUnity while (true) { // Get a stream object for reading - using (NetworkStream stream = socketConnection.GetStream()) + using NetworkStream stream = socketConnection.GetStream(); + int length; + // Read incomming stream into byte arrary. + while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) { - int length; - // Read incomming stream into byte arrary. - while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) + byte[] incommingData = new byte[length]; + Array.Copy(bytes, 0, incommingData, 0, length); + // Convert byte array to string message. + string serverMessage = Encoding.ASCII.GetString(incommingData); + string[] sections = serverMessage.Split('\n'); + if (sections.Length > 1) { - byte[] incommingData = new byte[length]; - Array.Copy(bytes, 0, incommingData, 0, length); - // Convert byte array to string message. - string serverMessage = Encoding.ASCII.GetString(incommingData); - string[] sections = serverMessage.Split('\n'); - if (sections.Length > 1) + lock (receivedMessages) { - lock (receivedMessages) + for (int i = 0; i < sections.Length - 1; i++) { - for (int i = 0; i < sections.Length - 1; i++) + if (i == 0) { - if (i == 0) - { - HandleMessage(partialMessage + sections[0]); - partialMessage = ""; - } - else - { - HandleMessage(sections[i]); - } + HandleMessage(partialMessage + sections[0]); + partialMessage = ""; + } + else + { + HandleMessage(sections[i]); } } } - - partialMessage = partialMessage + sections[sections.Length - 1]; } + + partialMessage = partialMessage + sections[sections.Length - 1]; } } } @@ -464,7 +462,7 @@ namespace VelNetUnity if (stream.CanWrite) { // Convert string message to byte array. - clientMessage = clientMessage + "\n"; //append a new line to delineate the message + clientMessage += "\n"; // append a new line to delineate the message byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(clientMessage); // Write byte array to socketConnection stream. stream.Write(clientMessageAsByteArray, 0, clientMessageAsByteArray.Length); @@ -538,9 +536,12 @@ namespace VelNetUnity newObject.prefabName = prefabName; newObject.owner = localPlayer; instance.objects.Add(newObject.networkId, newObject); + + // only sent to others, as I already instantiated this. Nice that it happens immediately. + instance.SendTo(MessageType.OTHERS, "7," + newObject.networkId + "," + prefabName); } - public static void InstantiateNetworkObject(string networkId, string prefabName, NetworkPlayer owner) + public static void SomebodyInstantiatedNetworkObject(string networkId, string prefabName, NetworkPlayer owner) { NetworkObject prefab = instance.prefabs.Find(p => p.name == prefabName); if (prefab == null) return; diff --git a/Samples~/DissonanceIntegration/VelCommsNetwork.cs b/Samples~/DissonanceIntegration/VelCommsNetwork.cs index 5633ee4..d3358c8 100644 --- a/Samples~/DissonanceIntegration/VelCommsNetwork.cs +++ b/Samples~/DissonanceIntegration/VelCommsNetwork.cs @@ -5,13 +5,13 @@ using UnityEngine; using UnityEngine.Serialization; -namespace VelNetUnity +namespace VelNet { /// /// Added to the same object as DissonanceComms component. Only one in the scene. /// [RequireComponent(typeof(DissonanceComms))] - [AddComponentMenu("VelNetUnity/Dissonance/VelNet Comms Network")] + [AddComponentMenu("VelNet/Dissonance/VelNet Comms Network")] public class VelCommsNetwork : MonoBehaviour, ICommsNetwork { public ConnectionStatus Status => manager.connected ? ConnectionStatus.Connected : ConnectionStatus.Disconnected; diff --git a/Samples~/DissonanceIntegration/VelNetDissonancePlayer.cs b/Samples~/DissonanceIntegration/VelNetDissonancePlayer.cs index 0ea2dba..72b9a38 100644 --- a/Samples~/DissonanceIntegration/VelNetDissonancePlayer.cs +++ b/Samples~/DissonanceIntegration/VelNetDissonancePlayer.cs @@ -5,12 +5,12 @@ using System.Linq; using Dissonance; using UnityEngine; -namespace VelNetUnity +namespace VelNet { /// /// This should be added to your player object /// - [AddComponentMenu("VelNetUnity/Dissonance/VelNet Dissonance Player")] + [AddComponentMenu("VelNet/Dissonance/VelNet Dissonance Player")] public class VelNetDissonancePlayer : NetworkComponent, IDissonancePlayer { private VelCommsNetwork comms; diff --git a/Samples~/Example/NetworkGUI.cs b/Samples~/Example/NetworkGUI.cs index 034466f..d8ca255 100644 --- a/Samples~/Example/NetworkGUI.cs +++ b/Samples~/Example/NetworkGUI.cs @@ -3,7 +3,7 @@ using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; -namespace VelNetUnity +namespace VelNet { public class NetworkGUI : MonoBehaviour { diff --git a/Samples~/Example/PlayerController.cs b/Samples~/Example/PlayerController.cs index aebafb5..f1886ba 100644 --- a/Samples~/Example/PlayerController.cs +++ b/Samples~/Example/PlayerController.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using UnityEngine; -namespace VelNetUnity +namespace VelNet { public class PlayerController : NetworkSerializedObject { diff --git a/Samples~/Example/VelNetMan.cs b/Samples~/Example/VelNetMan.cs index 00bf9e7..6988c1d 100644 --- a/Samples~/Example/VelNetMan.cs +++ b/Samples~/Example/VelNetMan.cs @@ -1,7 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using VelNetUnity; +using VelNet; public class VelNetMan : MonoBehaviour { diff --git a/VelNetUnity.asmdef b/VelNet.asmdef similarity index 81% rename from VelNetUnity.asmdef rename to VelNet.asmdef index 3422459..4a6f011 100644 --- a/VelNetUnity.asmdef +++ b/VelNet.asmdef @@ -1,6 +1,6 @@ { - "name": "VelNetUnity", - "rootNamespace": "VelNetUnity", + "name": "VelNet", + "rootNamespace": "VelNet", "references": [], "includePlatforms": [], "excludePlatforms": [], diff --git a/VelNetUnity.asmdef.meta b/VelNet.asmdef.meta similarity index 100% rename from VelNetUnity.asmdef.meta rename to VelNet.asmdef.meta diff --git a/package.json b/package.json index fcdbec8..9e4bd8d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "edu.uga.engr.vel.velnetunity", - "displayName": "VelNetUnity", + "name": "edu.uga.engr.vel.velnet", + "displayName": "VelNet", "version": "1.0.3", "unity": "2019.1", "description": "A custom networking library for Unity.",