idk even stuff
parent
70dcf597c4
commit
21859b6349
|
|
@ -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);
|
||||
}
|
||||
|
||||
//
|
||||
/// <summary>
|
||||
/// This is called by <see cref="NetworkObject"/> when messages are received for this component
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a network player
|
||||
|
|
@ -53,10 +53,11 @@ namespace VelNetUnity
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// These are generally things that come from the "owner" and should be enacted locally, where appropriate
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
public abstract class NetworkSerializedObject : NetworkComponent
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
public static class BinaryWriterExtensions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ using System.IO;
|
|||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple class that will sync the position and rotation of a network object
|
||||
/// </summary>
|
||||
[AddComponentMenu("VelNetUnity/VelNet Sync Transform")]
|
||||
[AddComponentMenu("VelNet/VelNet Sync Transform")]
|
||||
public class SyncTransform : NetworkSerializedObject
|
||||
{
|
||||
public Vector3 targetPosition;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ using UnityEngine;
|
|||
using UnityEngine.Serialization;
|
||||
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
/// <summary>
|
||||
/// Added to the same object as DissonanceComms component. Only one in the scene.
|
||||
/// </summary>
|
||||
[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;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ using System.Linq;
|
|||
using Dissonance;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
/// <summary>
|
||||
/// This should be added to your player object
|
||||
/// </summary>
|
||||
[AddComponentMenu("VelNetUnity/Dissonance/VelNet Dissonance Player")]
|
||||
[AddComponentMenu("VelNet/Dissonance/VelNet Dissonance Player")]
|
||||
public class VelNetDissonancePlayer : NetworkComponent, IDissonancePlayer
|
||||
{
|
||||
private VelCommsNetwork comms;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
public class NetworkGUI : MonoBehaviour
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VelNetUnity
|
||||
namespace VelNet
|
||||
{
|
||||
public class PlayerController : NetworkSerializedObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VelNetUnity;
|
||||
using VelNet;
|
||||
|
||||
public class VelNetMan : MonoBehaviour
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "VelNetUnity",
|
||||
"rootNamespace": "VelNetUnity",
|
||||
"name": "VelNet",
|
||||
"rootNamespace": "VelNet",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
@ -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.",
|
||||
|
|
|
|||
Loading…
Reference in New Issue