idk even stuff

handTracking
Anton Franzluebbers 2022-01-07 15:57:09 -05:00
parent ca96e555b2
commit c3e3169982
26 changed files with 232 additions and 98 deletions

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;
@ -28,6 +28,10 @@ namespace VelNetUnity
public bool IsTracking => true;
private static readonly List<VelNetDissonancePlayer> allPlayers = new List<VelNetDissonancePlayer>();
/// <summary>
/// Only sends voice data to players in this list
/// </summary>
public List<int> closePlayers = new List<int>();
[Tooltip("Maximum distance to transmit voice data. 0 to always send voice to all players.")]
@ -50,12 +54,30 @@ namespace VelNetUnity
return;
}
}
private void OnEnable()
{
// add ourselves to the global list of all players in the scene
if (!allPlayers.Contains(this))
{
allPlayers.Add(this);
}
else
{
Debug.LogError("We're already in the player list 🐭", this);
}
}
private void OnDisable()
{
// remove ourselves from the global list of all players in the scene
allPlayers.Remove(this);
}
private void Start()
{
if (IsMine)
{
SetDissonanceID(comms.dissonanceId);
@ -71,7 +93,7 @@ namespace VelNetUnity
writer.Write(dissonanceID);
SendBytes(mem.ToArray());
};
VelNetManager.instance.SetupMessageGroup("close", closePlayers.ToArray());
VelNetManager.instance.SetupMessageGroup("voice", closePlayers);
}
}
@ -83,10 +105,12 @@ namespace VelNetUnity
using MemoryStream mem = new MemoryStream();
using BinaryWriter writer = new BinaryWriter(mem);
writer.Write((byte)MessageType.AudioData);
writer.Write(BitConverter.GetBytes(lastAudioId++));
writer.Write(lastAudioId++);
writer.Write(data.ToArray());
// send voice data unreliably
SendBytesToGroup("close", mem.ToArray(), false);
SendBytes(mem.ToArray(), false);
// SendBytesToGroup("voice", mem.ToArray());
}
/// <summary>
@ -147,9 +171,13 @@ namespace VelNetUnity
if (closePlayerListChanged)
{
VelNetManager.instance.SetupMessageGroup("close", closePlayers);
VelNetManager.instance.SetupMessageGroup("voice", closePlayers);
}
}
else
{
closePlayers = allPlayers.Select(p => p.Owner.userid).ToList();
}
// handle dissonance comms
@ -194,6 +222,7 @@ namespace VelNetUnity
if (dissonanceID == "") // I don't have this yet
{
dissonanceID = reader.ReadString();
// tell the comms network that this player joined the channel
comms.SetPlayerJoined(dissonanceID); // tell dissonance
comms.dissonanceComms.TrackPlayerPosition(this); // tell dissonance to track the remote player

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,9 +2,9 @@ using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace VelNetUnity
namespace VelNet
{
public class PlayerController : NetworkSerializedObject
public class PlayerController : NetworkComponent
{
public Vector3 targetPosition;
public Quaternion targetRotation;
@ -13,12 +13,13 @@ namespace VelNetUnity
// Update is called once per frame
private void Update()
{
if (!IsMine)
{
transform.position = Vector3.Lerp(transform.position, targetPosition, .1f);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, .1f);
}
else
// if (!IsMine)
// {
// transform.position = Vector3.Lerp(transform.position, targetPosition, .1f);
// transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, .1f);
// }
// else
if (IsMine)
{
Vector3 movement = new Vector3();
movement.x += Input.GetAxis("Horizontal");
@ -53,25 +54,29 @@ namespace VelNetUnity
}
}
protected override byte[] SendState()
//
// protected override byte[] SendState()
// {
// using MemoryStream mem = new MemoryStream();
// using BinaryWriter writer = new BinaryWriter(mem);
//
// writer.Write(transform.position);
// writer.Write(transform.rotation);
//
// return mem.ToArray();
// }
//
// protected override void ReceiveState(byte[] message)
// {
// using MemoryStream mem = new MemoryStream(message);
// using BinaryReader reader = new BinaryReader(mem);
//
// targetPosition = reader.ReadVector3();
// targetRotation = reader.ReadQuaternion();
// }
public override void ReceiveBytes(byte[] message)
{
using MemoryStream mem = new MemoryStream();
using BinaryWriter writer = new BinaryWriter(mem);
writer.Write(transform.position);
writer.Write(transform.rotation);
return mem.ToArray();
}
protected override void ReceiveState(byte[] message)
{
using MemoryStream mem = new MemoryStream(message);
using BinaryReader reader = new BinaryReader(mem);
targetPosition = reader.ReadVector3();
targetRotation = reader.ReadQuaternion();
throw new System.NotImplementedException();
}
}
}

View File

@ -31,7 +31,7 @@ Transform:
m_GameObject: {fileID: 6139051692386484099}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
@ -130,7 +130,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
networkObject: {fileID: 9102273340480352682}
serializationRateHz: 30
targetPosition: {x: 0, y: 0, z: 0}
targetRotation: {x: 0, y: 0, z: 0, w: 0}
--- !u!114 &1181612843795795320
@ -147,7 +146,5 @@ MonoBehaviour:
m_EditorClassIdentifier:
networkObject: {fileID: 9102273340480352682}
dissonanceID:
targetPosition: {x: 0, y: 0, z: 0}
targetRotation: {x: 0, y: 0, z: 0, w: 0}
closePlayers:
maxDistance: 0

View File

@ -58,7 +58,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8565720275311462453}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f1f9b0bbd93a484a987c51f1107ebe5, type: 3}
m_Name:

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

@ -1834,7 +1834,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 03a4d4e1a7fd74c7ab2eccca4ce168db, type: 3}
m_Name:
m_EditorClassIdentifier:
host: neko.ugavel.com
host: 129.159.107.234
port: 3290
udpConnected: 0
userid: -1
@ -3406,7 +3406,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8565720275311462455, guid: 6e4a023f70e01405e8b249a4488fe319, type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: 2
objectReference: {fileID: 0}
- target: {fileID: 8565720275311462455, guid: 6e4a023f70e01405e8b249a4488fe319, type: 3}
propertyPath: m_LocalPosition.z

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

View File

@ -99,7 +99,7 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"edu.uga.engr.vel.velnetunity": {
"edu.uga.engr.vel.velnet": {
"version": "file:VelNetUnity",
"depth": 0,
"source": "embedded",

View File

@ -68,6 +68,12 @@ PlayerSettings:
androidRenderOutsideSafeArea: 1
androidUseSwappy: 1
androidBlitType: 0
androidResizableWindow: 0
androidDefaultWindowWidth: 1920
androidDefaultWindowHeight: 1080
androidMinimumWindowWidth: 400
androidMinimumWindowHeight: 300
androidFullscreenMode: 1
defaultIsNativeResolution: 0
macRetinaSupport: 1
runInBackground: 1
@ -121,6 +127,7 @@ PlayerSettings:
vulkanEnableSetSRGBWrite: 0
vulkanEnablePreTransform: 0
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
m_SupportedAspectRatios:
4:3: 1
5:4: 1
@ -236,6 +243,7 @@ PlayerSettings:
useCustomGradlePropertiesTemplate: 0
useCustomProguardFile: 0
AndroidTargetArchitectures: 1
AndroidTargetDevices: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName:
@ -252,13 +260,106 @@ PlayerSettings:
height: 180
banner: {fileID: 0}
androidGamepadSupportLevel: 0
chromeosInputEmulation: 1
AndroidMinifyWithR8: 0
AndroidMinifyRelease: 0
AndroidMinifyDebug: 0
AndroidValidateAppBundleSize: 1
AndroidAppBundleSizeToValidate: 150
m_BuildTargetIcons: []
m_BuildTargetPlatformIcons: []
m_BuildTargetPlatformIcons:
- m_BuildTarget: Android
m_Icons:
- m_Textures: []
m_Width: 432
m_Height: 432
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 324
m_Height: 324
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 216
m_Height: 216
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 162
m_Height: 162
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 108
m_Height: 108
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 81
m_Height: 81
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 1
m_SubKind:
m_BuildTargetBatching:
- m_BuildTarget: Standalone
m_StaticBatching: 1
@ -346,6 +447,7 @@ PlayerSettings:
cameraUsageDescription:
locationUsageDescription:
microphoneUsageDescription: Allow voice communications
bluetoothUsageDescription:
switchNMETAOverride:
switchNetLibKey:
switchSocketMemoryPoolSize: 6144

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2020.3.16f1
m_EditorVersionWithRevision: 2020.3.16f1 (049d6eca3c44)
m_EditorVersion: 2020.3.23f1
m_EditorVersionWithRevision: 2020.3.23f1 (c5d91304a876)