idk even stuff

upm
Anton Franzluebbers 2022-01-07 15:57:09 -05:00
parent 70dcf597c4
commit 21859b6349
15 changed files with 51 additions and 50 deletions

View File

@ -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>

View File

@ -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;

View File

@ -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;
}

View File

@ -2,7 +2,7 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace VelNetUnity
namespace VelNet
{
public abstract class NetworkSerializedObject : NetworkComponent
{

View File

@ -1,7 +1,7 @@
using System.IO;
using UnityEngine;
namespace VelNetUnity
namespace VelNet
{
public static class BinaryWriterExtensions
{

View File

@ -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;

View File

@ -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,8 +332,7 @@ 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)
@ -366,7 +365,6 @@ namespace VelNetUnity
}
}
}
}
catch (Exception socketException)
@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -3,7 +3,7 @@ using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace VelNetUnity
namespace VelNet
{
public class NetworkGUI : MonoBehaviour
{

View File

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace VelNetUnity
namespace VelNet
{
public class PlayerController : NetworkSerializedObject
{

View File

@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VelNetUnity;
using VelNet;
public class VelNetMan : MonoBehaviour
{

View File

@ -1,6 +1,6 @@
{
"name": "VelNetUnity",
"rootNamespace": "VelNetUnity",
"name": "VelNet",
"rootNamespace": "VelNet",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -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.",