merge
commit
eaf80a2dff
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8adda10125f861c4ab834bb9bd2056b5
|
||||
guid: b34f6c4b68ec079449bfb4be05fbfec7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class MouseDragger : MonoBehaviour
|
|||
{
|
||||
foreach (string draggableTag in draggableTags)
|
||||
{
|
||||
if (hit.transform.CompareTag(draggableTag) || hit.transform.parent == null || hit.transform.parent.CompareTag(draggableTag))
|
||||
if (hit.transform.CompareTag(draggableTag) || (hit.transform.parent != null && hit.transform.parent.CompareTag(draggableTag)))
|
||||
{
|
||||
NetworkObject netObj = hit.transform.GetComponent<NetworkObject>();
|
||||
netObj ??= hit.transform.GetComponentInParent<NetworkObject>();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Dissonance;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
|
@ -8,22 +10,16 @@ namespace VelNet
|
|||
{
|
||||
public class NetworkGUI : MonoBehaviour
|
||||
{
|
||||
[FormerlySerializedAs("networkManager")] public VelNetManager velNetManager;
|
||||
[FormerlySerializedAs("networkManager")]
|
||||
public VelNetManager velNetManager;
|
||||
|
||||
public InputField userInput;
|
||||
public InputField sendInput;
|
||||
public InputField roomInput;
|
||||
public Text messages;
|
||||
public List<string> messageBuffer;
|
||||
public Dropdown microphones;
|
||||
DissonanceComms comms;
|
||||
|
||||
public void HandleSend()
|
||||
{
|
||||
if (sendInput.text != "")
|
||||
{
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.OTHERS, sendInput.text);
|
||||
}
|
||||
}
|
||||
private DissonanceComms comms;
|
||||
|
||||
public void HandleLogin()
|
||||
{
|
||||
|
|
@ -33,6 +29,14 @@ namespace VelNet
|
|||
}
|
||||
}
|
||||
|
||||
public void HandleGetRooms()
|
||||
{
|
||||
if (VelNetManager.instance.connected)
|
||||
{
|
||||
VelNetManager.GetRooms();
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleJoin()
|
||||
{
|
||||
if (roomInput.text != "")
|
||||
|
|
@ -51,23 +55,17 @@ namespace VelNet
|
|||
{
|
||||
comms = FindObjectOfType<DissonanceComms>();
|
||||
microphones.AddOptions(new List<string>(Microphone.devices));
|
||||
VelNetManager.MessageReceived += (m) =>
|
||||
{
|
||||
string s = m.type + ":" + m.sender + ":" + m.text;
|
||||
messageBuffer.Add(s);
|
||||
messages.text = "";
|
||||
|
||||
|
||||
if (messageBuffer.Count > 10)
|
||||
{
|
||||
messageBuffer.RemoveAt(0);
|
||||
StartCoroutine(testes());
|
||||
}
|
||||
|
||||
foreach (string msg in messageBuffer)
|
||||
IEnumerator testes()
|
||||
{
|
||||
messages.text = messages.text + msg + "\n";
|
||||
}
|
||||
};
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
HandleLogin();
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
HandleJoin();
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void handleMicrophoneSelection()
|
||||
|
|
|
|||
|
|
@ -1,25 +1,30 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace VelNet
|
||||
{
|
||||
public class PlayerController : NetworkComponent
|
||||
public class PlayerController : NetworkSerializedObjectStream
|
||||
{
|
||||
public Vector3 targetPosition;
|
||||
public Quaternion targetRotation;
|
||||
private Renderer rend;
|
||||
public Color color;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rend = GetComponent<MeshRenderer>();
|
||||
if (IsMine)
|
||||
{
|
||||
color = new Color(Random.Range(0, 1f), Random.Range(0, 1f), Random.Range(0, 1f));
|
||||
rend.material.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
Vector3 movement = new Vector3();
|
||||
|
|
@ -43,37 +48,35 @@ namespace VelNet
|
|||
|
||||
if (Input.GetKeyDown(KeyCode.Backspace))
|
||||
{
|
||||
foreach (KeyValuePair<string, NetworkObject> kvp in VelNetManager.instance.objects.Where(kvp => !kvp.Value.ownershipLocked))
|
||||
foreach (string key in VelNetManager.instance.objects
|
||||
.Where(kvp => !kvp.Value.ownershipLocked)
|
||||
.Select(kvp => kvp.Key).ToArray())
|
||||
{
|
||||
VelNetManager.NetworkDestroy(kvp.Key);
|
||||
VelNetManager.NetworkDestroy(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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)
|
||||
protected override void SendState(BinaryWriter binaryWriter)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
binaryWriter.Write(color);
|
||||
}
|
||||
|
||||
protected override void ReceiveState(BinaryReader binaryReader)
|
||||
{
|
||||
// Color newColor = binaryReader.ReadColor();
|
||||
Color newColor;
|
||||
newColor.r = binaryReader.ReadSingle();
|
||||
newColor.g = binaryReader.ReadSingle();
|
||||
newColor.b = binaryReader.ReadSingle();
|
||||
newColor.a = binaryReader.ReadSingle();
|
||||
if (newColor != color)
|
||||
{
|
||||
rend.material.color = newColor;
|
||||
}
|
||||
|
||||
color = newColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,86 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &2802320351940726854
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6602982999811082154}
|
||||
- component: {fileID: 6433756913090684124}
|
||||
- component: {fileID: 6919422133110223353}
|
||||
m_Layer: 0
|
||||
m_Name: Dissonance Range
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6602982999811082154
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2802320351940726854}
|
||||
m_LocalRotation: {x: -0.70710635, y: -0, z: -0, w: 0.7071073}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 8, y: 0.1, z: 8}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3076416102083120807}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
|
||||
--- !u!33 &6433756913090684124
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2802320351940726854}
|
||||
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &6919422133110223353
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2802320351940726854}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 6fad1ca32acea73489c2c4b898cdb9d4, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!1 &6139051692386484099
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -33,7 +114,8 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
||||
m_Children: []
|
||||
m_Children:
|
||||
- {fileID: 6602982999811082154}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
@ -113,12 +195,13 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
ownershipLocked: 1
|
||||
networkId:
|
||||
sceneNetworkId: 0
|
||||
prefabName:
|
||||
isSceneObject: 0
|
||||
syncedComponents:
|
||||
- {fileID: -4404668399269848200}
|
||||
- {fileID: 7564913803199044469}
|
||||
- {fileID: 1181612843795795320}
|
||||
- {fileID: 7564913803199044469}
|
||||
--- !u!114 &-4404668399269848200
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -132,8 +215,9 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
networkObject: {fileID: 9102273340480352682}
|
||||
targetPosition: {x: 0, y: 0, z: 0}
|
||||
targetRotation: {x: 0, y: 0, z: 0, w: 0}
|
||||
serializationRateHz: 30
|
||||
hybridOnChangeCompression: 1
|
||||
color: {r: 0, g: 0, b: 0, a: 0}
|
||||
--- !u!114 &1181612843795795320
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -147,9 +231,10 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
networkObject: {fileID: 9102273340480352682}
|
||||
useTcp: 0
|
||||
dissonanceID:
|
||||
closePlayers:
|
||||
maxDistance: 0
|
||||
maxDistance: 2
|
||||
--- !u!114 &7564913803199044469
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -163,7 +248,8 @@ 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}
|
||||
smoothness: 0.1
|
||||
serializationRateHz: 60
|
||||
hybridOnChangeCompression: 1
|
||||
useLocalTransform: 0
|
||||
teleportDistance: 0
|
||||
teleportAngle: 0
|
||||
|
|
|
|||
|
|
@ -16,4 +16,9 @@ public class SyncedTextbox : NetworkSerializedObjectStream
|
|||
{
|
||||
text.text = binaryReader.ReadString();
|
||||
}
|
||||
|
||||
public void TakeOwnership()
|
||||
{
|
||||
networkObject.TakeOwnership();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,100 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &6003361529827848619
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7099230484513283147}
|
||||
- component: {fileID: 8811139817265458480}
|
||||
- component: {fileID: 3776025769317911085}
|
||||
- component: {fileID: 1426238303320144522}
|
||||
m_Layer: 0
|
||||
m_Name: Cube
|
||||
m_TagString: TestSphere
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7099230484513283147
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6003361529827848619}
|
||||
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_Children: []
|
||||
m_Father: {fileID: 8565720275311462455}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &8811139817265458480
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6003361529827848619}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &3776025769317911085
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6003361529827848619}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!65 &1426238303320144522
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6003361529827848619}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &8565720275311462453
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -13,7 +108,7 @@ GameObject:
|
|||
- component: {fileID: 8565720275311462452}
|
||||
m_Layer: 0
|
||||
m_Name: TestNetworkedGameObject
|
||||
m_TagString: TestSphere
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
|
|
@ -29,7 +124,7 @@ Transform:
|
|||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 8565720276181857624}
|
||||
- {fileID: 7099230484513283147}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
@ -66,99 +161,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
networkObject: {fileID: 3951900052977689805}
|
||||
serializationRateHz: 60
|
||||
hybridOnChangeCompression: 1
|
||||
useLocalTransform: 0
|
||||
--- !u!1 &8565720276181857625
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 8565720276181857624}
|
||||
- component: {fileID: 8565720276181857605}
|
||||
- component: {fileID: 8565720276181857626}
|
||||
- component: {fileID: 8565720276181857627}
|
||||
m_Layer: 0
|
||||
m_Name: Sphere
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &8565720276181857624
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8565720276181857625}
|
||||
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_Children: []
|
||||
m_Father: {fileID: 8565720275311462455}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &8565720276181857605
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8565720276181857625}
|
||||
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &8565720276181857626
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8565720276181857625}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!135 &8565720276181857627
|
||||
SphereCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8565720276181857625}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
teleportDistance: 0
|
||||
teleportAngle: 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: TransparentMat
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: 3000
|
||||
stringTagMap:
|
||||
RenderType: Transparent
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 10
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _Mode: 3
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 0
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 0
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 0.03137255}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fad1ca32acea73489c2c4b898cdb9d4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 009dc4ba29f14b649beb8c3eaad89f15
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d1b34f106c04378428823df374b0e07c
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 112000000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,323 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 12
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 256
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 1
|
||||
m_PVRDenoiserTypeDirect: 1
|
||||
m_PVRDenoiserTypeIndirect: 1
|
||||
m_PVRDenoiserTypeAO: 1
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_LightingSettings: {fileID: 0}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &516411417
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 516411421}
|
||||
- component: {fileID: 516411420}
|
||||
- component: {fileID: 516411419}
|
||||
- component: {fileID: 516411418}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &516411418
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516411417}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 233344de094f11341bdb834d564708dc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
host: 127.0.0.1
|
||||
port: 80
|
||||
udpConnected: 0
|
||||
userid: -1
|
||||
room:
|
||||
connected: 0
|
||||
prefabs: []
|
||||
sceneObjects: []
|
||||
deletedSceneObjects: []
|
||||
--- !u!81 &516411419
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516411417}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &516411420
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516411417}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &516411421
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 516411417}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &756322628
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 756322630}
|
||||
- component: {fileID: 756322629}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &756322629
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 756322628}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 1
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 4
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_UseViewFrustumForShadowCasterCull: 1
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &756322630
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 756322628}
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2e6e0ddeb76e51b46afc0f0a43386ff2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#if UNITY_EDITOR
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace VelNet.Editor
|
||||
{
|
||||
public class EditorUtils : MonoBehaviour
|
||||
{
|
||||
[MenuItem("VelNet/Check For Duplicate NetworkIds", false, 10)]
|
||||
private static void CheckDuplicateNetworkIds()
|
||||
{
|
||||
NetworkObject[] objs = FindObjectsOfType<NetworkObject>();
|
||||
Dictionary<int, NetworkObject> ids = new Dictionary<int, NetworkObject>();
|
||||
foreach (NetworkObject o in objs)
|
||||
{
|
||||
if (!o.isSceneObject) continue;
|
||||
|
||||
if (ids.ContainsKey(o.sceneNetworkId) || o.sceneNetworkId < 100)
|
||||
{
|
||||
if (ids.ContainsKey(o.sceneNetworkId))
|
||||
{
|
||||
Debug.Log($"Found duplicated id: {o.name} {ids[o.sceneNetworkId].name}", o);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Found duplicated id: {o.name} {o.sceneNetworkId}", o);
|
||||
}
|
||||
|
||||
o.sceneNetworkId = 100;
|
||||
while (ids.ContainsKey(o.sceneNetworkId))
|
||||
{
|
||||
o.sceneNetworkId += 1;
|
||||
}
|
||||
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(o);
|
||||
EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
ids.Add(o.sceneNetworkId, o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f2f5f489d44f614c96bcf8f493c787d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "VelNet.Editor",
|
||||
"rootNamespace": "VelNet.Editor",
|
||||
"references": [
|
||||
"GUID:1e55e2c4387020247a1ae212bbcbd381"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ae0703a992a8fe347978b1cd2dd2d7a9
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -62,7 +62,7 @@ namespace VelNet
|
|||
}
|
||||
else
|
||||
{
|
||||
owner.SendMessage(this, index.ToString(), message, reliable);
|
||||
VelNetPlayer.SendMessage(this, (byte)index, message, reliable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,15 +76,15 @@ namespace VelNet
|
|||
|
||||
// send the message and an identifier for which component it belongs to
|
||||
int index = syncedComponents.IndexOf(component);
|
||||
owner.SendGroupMessage(this, group, index.ToString(), message, reliable);
|
||||
VelNetPlayer.SendGroupMessage(this, group, (byte)index, message, reliable);
|
||||
}
|
||||
|
||||
public void ReceiveBytes(string identifier, byte[] message)
|
||||
public void ReceiveBytes(byte componentIdx, byte[] message)
|
||||
{
|
||||
// send the message to the right component
|
||||
try
|
||||
{
|
||||
syncedComponents[int.Parse(identifier)].ReceiveBytes(message);
|
||||
syncedComponents[componentIdx].ReceiveBytes(message);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -128,6 +128,7 @@ namespace VelNet
|
|||
foreach (NetworkComponent c in comps)
|
||||
{
|
||||
c.networkObject = t;
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(c);
|
||||
}
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ namespace VelNet
|
|||
{
|
||||
public static class BinaryWriterExtensions
|
||||
{
|
||||
#region Writers
|
||||
|
||||
public static void Write(this BinaryWriter writer, Vector3 v)
|
||||
{
|
||||
writer.Write(v.x);
|
||||
|
|
@ -23,6 +25,18 @@ namespace VelNet
|
|||
writer.Write(q.w);
|
||||
}
|
||||
|
||||
public static void Write(this BinaryWriter writer, Color c)
|
||||
{
|
||||
writer.Write(c.r);
|
||||
writer.Write(c.g);
|
||||
writer.Write(c.b);
|
||||
writer.Write(c.a);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Readers
|
||||
|
||||
public static Vector3 ReadVector3(this BinaryReader reader)
|
||||
{
|
||||
return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
|
||||
|
|
@ -38,6 +52,35 @@ namespace VelNet
|
|||
);
|
||||
}
|
||||
|
||||
public static Color ReadColor(this BinaryReader reader)
|
||||
{
|
||||
return new Color(
|
||||
reader.ReadSingle(),
|
||||
reader.ReadSingle(),
|
||||
reader.ReadSingle(),
|
||||
reader.ReadSingle()
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public static bool BytesSame(byte[] b1, byte[] b2)
|
||||
{
|
||||
if (b1 == null && b2 != null) return false; // only one null
|
||||
if (b1 != null && b2 == null) return false; // only one null
|
||||
if (b1 == null) return true; // both null
|
||||
|
||||
// length doesn't match
|
||||
if (b1.Length != b2.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if any bytes are different
|
||||
return !b1.Where((t, i) => t != b2[i]).Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compresses the list of bools into bytes using a bitmask
|
||||
/// </summary>
|
||||
|
|
@ -88,6 +131,5 @@ namespace VelNet
|
|||
{
|
||||
return (b & (1 << index)) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace VelNet
|
||||
{
|
||||
|
|
@ -9,6 +9,15 @@ namespace VelNet
|
|||
[Tooltip("Send rate of this object. This caps out at the framerate of the game.")]
|
||||
public float serializationRateHz = 30;
|
||||
|
||||
/// <summary>
|
||||
/// If the data hasn't changed, only sends updates across the network at 1Hz
|
||||
/// </summary>
|
||||
public bool hybridOnChangeCompression = true;
|
||||
|
||||
private byte[] lastSentBytes;
|
||||
private double lastSendTime;
|
||||
private const double slowSendInterval = 2;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
StartCoroutine(SendMessageUpdate());
|
||||
|
|
@ -18,9 +27,31 @@ namespace VelNet
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
if (IsMine)
|
||||
try
|
||||
{
|
||||
SendBytes(SendState());
|
||||
if (IsMine && enabled)
|
||||
{
|
||||
byte[] newBytes = SendState();
|
||||
if (hybridOnChangeCompression)
|
||||
{
|
||||
if (Time.timeAsDouble - lastSendTime > slowSendInterval || !BinaryWriterExtensions.BytesSame(lastSentBytes, newBytes))
|
||||
{
|
||||
SendBytes(newBytes);
|
||||
lastSendTime = Time.timeAsDouble;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SendBytes(newBytes);
|
||||
lastSendTime = Time.timeAsDouble;
|
||||
}
|
||||
|
||||
lastSentBytes = newBytes;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(1f / serializationRateHz);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace VelNet
|
||||
{
|
||||
|
|
@ -11,6 +10,16 @@ namespace VelNet
|
|||
[Tooltip("Send rate of this object. This caps out at the framerate of the game.")]
|
||||
public float serializationRateHz = 30;
|
||||
|
||||
/// <summary>
|
||||
/// If the data hasn't changed, only sends updates across the network at 1Hz
|
||||
/// </summary>
|
||||
public bool hybridOnChangeCompression = true;
|
||||
|
||||
private byte[] lastSentBytes;
|
||||
private double lastSendTime;
|
||||
private const double slowSendInterval = 2;
|
||||
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
StartCoroutine(SendMessageUpdate());
|
||||
|
|
@ -22,12 +31,28 @@ namespace VelNet
|
|||
{
|
||||
try
|
||||
{
|
||||
if (IsMine)
|
||||
if (IsMine && enabled)
|
||||
{
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
SendState(writer);
|
||||
SendBytes(mem.ToArray());
|
||||
|
||||
byte[] newBytes = mem.ToArray();
|
||||
if (hybridOnChangeCompression)
|
||||
{
|
||||
if (Time.timeAsDouble - lastSendTime > slowSendInterval || !BinaryWriterExtensions.BytesSame(lastSentBytes, newBytes))
|
||||
{
|
||||
SendBytes(newBytes);
|
||||
lastSendTime = Time.timeAsDouble;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SendBytes(newBytes);
|
||||
lastSendTime = Time.timeAsDouble;
|
||||
}
|
||||
|
||||
lastSentBytes = newBytes;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
|
|
@ -8,20 +7,36 @@ using System.Threading;
|
|||
using UnityEngine;
|
||||
using System.Net;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.IO;
|
||||
|
||||
namespace VelNet
|
||||
{
|
||||
[AddComponentMenu("VelNet/VelNet Manager")]
|
||||
public class VelNetManager : MonoBehaviour
|
||||
{
|
||||
public enum MessageType
|
||||
public enum MessageSendType
|
||||
{
|
||||
OTHERS = 0,
|
||||
ALL = 1,
|
||||
OTHERS_ORDERED = 2,
|
||||
ALL_ORDERED = 3
|
||||
MESSAGE_OTHERS_ORDERED = 7,
|
||||
MESSAGE_ALL_ORDERED = 8,
|
||||
MESSAGE_LOGIN = 0,
|
||||
MESSAGE_GETROOMS = 1,
|
||||
MESSAGE_JOINROOM = 2,
|
||||
MESSAGE_OTHERS = 3,
|
||||
MESSAGE_ALL = 4,
|
||||
MESSAGE_GROUP = 5,
|
||||
MESSAGE_SETGROUP = 6
|
||||
};
|
||||
|
||||
public enum MessageType : byte
|
||||
{
|
||||
ObjectSync,
|
||||
TakeOwnership,
|
||||
Instantiate,
|
||||
Destroy,
|
||||
DeleteSceneObjects,
|
||||
Custom
|
||||
}
|
||||
|
||||
public string host;
|
||||
public int port;
|
||||
|
||||
|
|
@ -34,10 +49,11 @@ namespace VelNet
|
|||
private Thread clientReceiveThread;
|
||||
private Thread clientReceiveThreadUDP;
|
||||
public int userid = -1;
|
||||
private int messagesReceived = 0;
|
||||
|
||||
public readonly Dictionary<int, VelNetPlayer> players = new Dictionary<int, VelNetPlayer>();
|
||||
|
||||
#region Callbacks
|
||||
|
||||
/// <summary>
|
||||
/// We just joined a room
|
||||
/// string - the room name
|
||||
|
|
@ -61,9 +77,13 @@ namespace VelNet
|
|||
public static Action<VelNetPlayer> OnPlayerLeft;
|
||||
|
||||
public static Action OnConnectedToServer;
|
||||
public static Action<Message> MessageReceived;
|
||||
public static Action OnLoggedIn;
|
||||
public static Action<string[], int> RoomsReceived;
|
||||
public static Action<RoomsMessage> RoomsReceived;
|
||||
|
||||
public static Action<Message> MessageReceived;
|
||||
public static Action<byte[]> CustomMessageReceived;
|
||||
|
||||
#endregion
|
||||
|
||||
public bool connected;
|
||||
|
||||
|
|
@ -100,13 +120,59 @@ namespace VelNet
|
|||
|
||||
public static bool IsConnected => instance != null && instance.connected && instance.udpConnected;
|
||||
|
||||
//this is for sending udp packets
|
||||
private static readonly byte[] toSend = new byte[1024];
|
||||
|
||||
// Use this for initialization
|
||||
public class Message
|
||||
public abstract class Message
|
||||
{
|
||||
}
|
||||
|
||||
public class ListedRoom
|
||||
{
|
||||
public string name;
|
||||
public int numUsers;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Room Name: " + name + "\tUsers: " + numUsers;
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginMessage : Message
|
||||
{
|
||||
public int userId;
|
||||
}
|
||||
|
||||
public class RoomsMessage : Message
|
||||
{
|
||||
public List<ListedRoom> rooms;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Join("\n", rooms);
|
||||
}
|
||||
}
|
||||
|
||||
public class JoinMessage : Message
|
||||
{
|
||||
public int userId;
|
||||
public string room;
|
||||
}
|
||||
|
||||
public class DataMessage : Message
|
||||
{
|
||||
public int senderId;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
public class ChangeMasterMessage : Message
|
||||
{
|
||||
public int masterId;
|
||||
}
|
||||
|
||||
public class ConnectedMessage : Message
|
||||
{
|
||||
public int type;
|
||||
public string text;
|
||||
public int sender;
|
||||
}
|
||||
|
||||
public readonly List<Message> receivedMessages = new List<Message>();
|
||||
|
|
@ -123,24 +189,13 @@ namespace VelNet
|
|||
SceneManager.sceneLoaded += (scene, mode) =>
|
||||
{
|
||||
// add all local network objects
|
||||
sceneObjects = FindObjectsOfType<NetworkObject>().Where(o=>o.isSceneObject).ToArray();
|
||||
sceneObjects = FindObjectsOfType<NetworkObject>().Where(o => o.isSceneObject).ToArray();
|
||||
};
|
||||
}
|
||||
|
||||
private IEnumerator Start()
|
||||
private void Start()
|
||||
{
|
||||
ConnectToTcpServer();
|
||||
yield return null;
|
||||
|
||||
try
|
||||
{
|
||||
OnConnectedToServer?.Invoke();
|
||||
}
|
||||
// prevent errors in subscribers from breaking our code
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -151,6 +206,15 @@ namespace VelNet
|
|||
//Debug.Log(messagesReceived++);
|
||||
receivedMessages.Add(m);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
MessageReceived?.Invoke(m);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -160,12 +224,26 @@ namespace VelNet
|
|||
//the main thread, which can do Unity stuff
|
||||
foreach (Message m in receivedMessages)
|
||||
{
|
||||
switch (m.type)
|
||||
switch (m)
|
||||
{
|
||||
// when you join the server
|
||||
case 0:
|
||||
userid = m.sender;
|
||||
Debug.Log("Joined server");
|
||||
case ConnectedMessage msg:
|
||||
{
|
||||
try
|
||||
{
|
||||
OnConnectedToServer?.Invoke();
|
||||
}
|
||||
// prevent errors in subscribers from breaking our code
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case LoginMessage lm:
|
||||
{
|
||||
userid = lm.userId;
|
||||
Debug.Log("Joined server " + userid);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -179,11 +257,29 @@ namespace VelNet
|
|||
|
||||
//start the udp thread
|
||||
clientReceiveThreadUDP = new Thread(ListenForDataUDP);
|
||||
clientReceiveThreadUDP.IsBackground = true;
|
||||
clientReceiveThreadUDP.Start();
|
||||
|
||||
break;
|
||||
// if this message is for me, that means I joined a new room...
|
||||
case 2 when userid == m.sender:
|
||||
}
|
||||
case RoomsMessage rm:
|
||||
{
|
||||
Debug.Log("Got Rooms Message:\n" + rm);
|
||||
|
||||
try
|
||||
{
|
||||
RoomsReceived?.Invoke(rm);
|
||||
}
|
||||
// prevent errors in subscribers from breaking our code
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case JoinMessage jm:
|
||||
{
|
||||
if (userid == jm.userId) //this is us
|
||||
{
|
||||
string oldRoom = LocalPlayer?.room;
|
||||
|
||||
|
|
@ -191,21 +287,20 @@ namespace VelNet
|
|||
players.Clear();
|
||||
masterPlayer = null;
|
||||
|
||||
if (m.text != "")
|
||||
if (jm.room != "")
|
||||
{
|
||||
VelNetPlayer player = new VelNetPlayer
|
||||
{
|
||||
isLocal = true,
|
||||
userid = m.sender,
|
||||
room = m.text
|
||||
userid = jm.userId,
|
||||
room = jm.room
|
||||
};
|
||||
|
||||
players.Add(userid, player);
|
||||
if (m.text != "")
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
OnJoinedRoom?.Invoke(m.text);
|
||||
OnJoinedRoom?.Invoke(jm.room);
|
||||
}
|
||||
// prevent errors in subscribers from breaking our code
|
||||
catch (Exception e)
|
||||
|
|
@ -213,7 +308,6 @@ namespace VelNet
|
|||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// we just left a room
|
||||
else
|
||||
{
|
||||
|
|
@ -244,37 +338,34 @@ namespace VelNet
|
|||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// not for me, a player is joining or leaving
|
||||
case 2:
|
||||
else
|
||||
{
|
||||
VelNetPlayer me = players[userid];
|
||||
|
||||
if (me.room != m.text)
|
||||
if (me.room != jm.room)
|
||||
{
|
||||
// we got a left message, kill it
|
||||
// change ownership of all objects to master
|
||||
List<string> deleteObjects = new List<string>();
|
||||
foreach ((string key, NetworkObject value) in objects)
|
||||
foreach (KeyValuePair<string, NetworkObject> kvp in objects)
|
||||
{
|
||||
if (value.owner == players[m.sender]) // the owner is the player that left
|
||||
if (kvp.Value.owner == players[jm.userId]) // the owner is the player that left
|
||||
{
|
||||
// if this object has locked ownership, delete it
|
||||
if (value.ownershipLocked)
|
||||
if (kvp.Value.ownershipLocked)
|
||||
{
|
||||
deleteObjects.Add(value.networkId);
|
||||
deleteObjects.Add(kvp.Value.networkId);
|
||||
}
|
||||
// I'm the local master player, so can take ownership immediately
|
||||
else if (me.isLocal && me == masterPlayer)
|
||||
{
|
||||
TakeOwnership(key);
|
||||
TakeOwnership(kvp.Key);
|
||||
}
|
||||
// the master player left, so everyone should set the owner null (we should get a new master shortly)
|
||||
else if (players[m.sender] == masterPlayer)
|
||||
else if (players[jm.userId] == masterPlayer)
|
||||
{
|
||||
value.owner = null;
|
||||
kvp.Value.owner = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -282,12 +373,14 @@ namespace VelNet
|
|||
// TODO this may check for ownership in the future. We don't need ownership here
|
||||
deleteObjects.ForEach(NetworkDestroy);
|
||||
|
||||
VelNetPlayer removedPlayer = players[m.sender];
|
||||
players.Remove(m.sender);
|
||||
VelNetPlayer leftPlayer = players[jm.userId];
|
||||
players.Remove(jm.userId);
|
||||
|
||||
try
|
||||
{
|
||||
OnPlayerLeft?.Invoke(removedPlayer);
|
||||
OnPlayerLeft?.Invoke(leftPlayer);
|
||||
}
|
||||
// prevent errors in subscribers from breaking our code
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
|
|
@ -299,10 +392,10 @@ namespace VelNet
|
|||
VelNetPlayer player = new VelNetPlayer
|
||||
{
|
||||
isLocal = false,
|
||||
room = m.text,
|
||||
userid = m.sender
|
||||
room = jm.room,
|
||||
userid = jm.userId
|
||||
};
|
||||
players.Add(m.sender, player);
|
||||
players.Add(jm.userId, player);
|
||||
try
|
||||
{
|
||||
OnPlayerJoined?.Invoke(player);
|
||||
|
|
@ -313,27 +406,28 @@ namespace VelNet
|
|||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// generic message
|
||||
case 3:
|
||||
if (players.ContainsKey(m.sender))
|
||||
case DataMessage dm:
|
||||
{
|
||||
players[m.sender]?.HandleMessage(m);
|
||||
if (players.ContainsKey(dm.senderId))
|
||||
{
|
||||
players[dm.senderId]?.HandleMessage(dm);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Received message from player that doesn't exist: " + m.text);
|
||||
Debug.LogError("Received message from player that doesn't exist ");
|
||||
}
|
||||
|
||||
break;
|
||||
// change master player (this should only happen when the first player joins or if the master player leaves)
|
||||
case 4:
|
||||
}
|
||||
case ChangeMasterMessage cm:
|
||||
{
|
||||
if (masterPlayer == null)
|
||||
{
|
||||
masterPlayer = players[m.sender];
|
||||
masterPlayer = players[cm.masterId];
|
||||
|
||||
// no master player yet, add the scene objects
|
||||
|
||||
|
|
@ -346,12 +440,20 @@ namespace VelNet
|
|||
sceneObjects[i].networkId = -1 + "-" + sceneObjects[i].sceneNetworkId;
|
||||
sceneObjects[i].owner = masterPlayer;
|
||||
sceneObjects[i].isSceneObject = true; // needed for special handling when deleted
|
||||
|
||||
if (objects.ContainsKey(sceneObjects[i].networkId))
|
||||
{
|
||||
Debug.LogError($"Duplicate NetworkID: {sceneObjects[i].networkId} {sceneObjects[i].name} {objects[sceneObjects[i].networkId]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
objects.Add(sceneObjects[i].networkId, sceneObjects[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
masterPlayer = players[m.sender];
|
||||
masterPlayer = players[cm.masterId];
|
||||
}
|
||||
|
||||
masterPlayer.SetAsMasterPlayer();
|
||||
|
|
@ -366,7 +468,7 @@ namespace VelNet
|
|||
}
|
||||
}
|
||||
|
||||
MessageReceived?.Invoke(m);
|
||||
//MessageReceived?.Invoke(m);
|
||||
}
|
||||
|
||||
receivedMessages.Clear();
|
||||
|
|
@ -376,6 +478,8 @@ namespace VelNet
|
|||
private void OnApplicationQuit()
|
||||
{
|
||||
socketConnection?.Close();
|
||||
clientReceiveThreadUDP?.Abort();
|
||||
clientReceiveThread?.Abort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -386,7 +490,6 @@ namespace VelNet
|
|||
try
|
||||
{
|
||||
clientReceiveThread = new Thread(ListenForData);
|
||||
clientReceiveThread.IsBackground = true;
|
||||
clientReceiveThread.Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -395,77 +498,30 @@ namespace VelNet
|
|||
}
|
||||
}
|
||||
|
||||
private void HandleMessage(string s) // this parses messages from the server, and adds them to a queue to be processed on the main thread
|
||||
{
|
||||
// Debug.Log("Received: " + s);
|
||||
Message m = new Message();
|
||||
string[] sections = s.Split(':');
|
||||
if (sections.Length <= 0) return;
|
||||
|
||||
int type = int.Parse(sections[0]);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0: // logged in message
|
||||
{
|
||||
if (sections.Length > 1)
|
||||
{
|
||||
m.type = type;
|
||||
m.sender = int.Parse(sections[1]);
|
||||
m.text = "";
|
||||
AddMessage(m);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // room info message
|
||||
{
|
||||
break;
|
||||
}
|
||||
case 2: // joined room message
|
||||
{
|
||||
if (sections.Length > 2)
|
||||
{
|
||||
m.type = 2;
|
||||
int user_id = int.Parse(sections[1]);
|
||||
m.sender = user_id;
|
||||
string new_room = sections[2];
|
||||
m.text = new_room;
|
||||
|
||||
AddMessage(m);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 3: // text message
|
||||
{
|
||||
if (sections.Length > 2)
|
||||
{
|
||||
m.type = 3;
|
||||
m.sender = int.Parse(sections[1]);
|
||||
m.text = sections[2];
|
||||
AddMessage(m);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 4: // change master client
|
||||
{
|
||||
if (sections.Length > 1)
|
||||
{
|
||||
m.type = 4;
|
||||
m.sender = int.Parse(sections[1]);
|
||||
AddMessage(m);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs in background clientReceiveThread; Listens for incomming data.
|
||||
/// Runs in background clientReceiveThread; Listens for incoming data.
|
||||
/// </summary>
|
||||
private static byte[] ReadExact(Stream stream, int N)
|
||||
{
|
||||
byte[] toReturn = new byte[N];
|
||||
|
||||
int numRead = 0;
|
||||
int numLeft = N;
|
||||
while (numLeft > 0)
|
||||
{
|
||||
numRead += stream.Read(toReturn, numRead, numLeft);
|
||||
numLeft = N - numRead;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static int GetIntFromBytes(byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToInt32(BitConverter.IsLittleEndian ? bytes.Reverse().ToArray() : bytes, 0);
|
||||
}
|
||||
|
||||
private void ListenForData()
|
||||
{
|
||||
connected = true;
|
||||
|
|
@ -473,41 +529,85 @@ namespace VelNet
|
|||
{
|
||||
socketConnection = new TcpClient(host, port);
|
||||
socketConnection.NoDelay = true;
|
||||
byte[] bytes = new byte[1024];
|
||||
string partialMessage = "";
|
||||
// Get a stream object for reading
|
||||
NetworkStream stream = socketConnection.GetStream();
|
||||
using BinaryReader reader = new BinaryReader(stream);
|
||||
//now we are connected, so add a message to the queue
|
||||
AddMessage(new ConnectedMessage());
|
||||
while (true)
|
||||
{
|
||||
// Get a stream object for reading
|
||||
using NetworkStream stream = socketConnection.GetStream();
|
||||
int length;
|
||||
// Read incomming stream into byte arrary.
|
||||
while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
|
||||
|
||||
//read a byte
|
||||
MessageSendType type = (MessageSendType)stream.ReadByte();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
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)
|
||||
//login
|
||||
case MessageSendType.MESSAGE_LOGIN:
|
||||
{
|
||||
lock (receivedMessages)
|
||||
{
|
||||
for (int i = 0; i < sections.Length - 1; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
HandleMessage(partialMessage + sections[0]);
|
||||
partialMessage = "";
|
||||
LoginMessage m = new LoginMessage();
|
||||
m.userId = GetIntFromBytes(ReadExact(stream, 4)); //not really the sender...
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
else
|
||||
//rooms
|
||||
case MessageSendType.MESSAGE_GETROOMS:
|
||||
{
|
||||
HandleMessage(sections[i]);
|
||||
}
|
||||
}
|
||||
RoomsMessage m = new RoomsMessage();
|
||||
m.rooms = new List<ListedRoom>();
|
||||
int N = GetIntFromBytes(ReadExact(stream, 4)); //the size of the payload
|
||||
byte[] utf8data = ReadExact(stream, N);
|
||||
string roomMessage = Encoding.UTF8.GetString(utf8data);
|
||||
|
||||
|
||||
string[] sections = roomMessage.Split(',');
|
||||
foreach (string s in sections)
|
||||
{
|
||||
string[] pieces = s.Split(':');
|
||||
if (pieces.Length == 2)
|
||||
{
|
||||
ListedRoom lr = new ListedRoom();
|
||||
lr.name = pieces[0];
|
||||
lr.numUsers = int.Parse(pieces[1]);
|
||||
m.rooms.Add(lr);
|
||||
}
|
||||
}
|
||||
|
||||
partialMessage = partialMessage + sections[sections.Length - 1];
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
//joined
|
||||
case MessageSendType.MESSAGE_JOINROOM:
|
||||
{
|
||||
JoinMessage m = new JoinMessage();
|
||||
m.userId = GetIntFromBytes(ReadExact(stream, 4));
|
||||
int N = stream.ReadByte();
|
||||
byte[] utf8data = ReadExact(stream, N); //the room name, encoded as utf-8
|
||||
m.room = Encoding.UTF8.GetString(utf8data);
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
//data
|
||||
case MessageSendType.MESSAGE_OTHERS:
|
||||
// case MessageSendType.MESSAGE_OTHERS_ORDERED:
|
||||
// case MessageSendType.MESSAGE_ALL:
|
||||
// case MessageSendType.MESSAGE_ALL_ORDERED:
|
||||
{
|
||||
DataMessage m = new DataMessage();
|
||||
m.senderId = GetIntFromBytes(ReadExact(stream, 4));
|
||||
int N = GetIntFromBytes(ReadExact(stream, 4)); //the size of the payload
|
||||
m.data = ReadExact(stream, N); //the message
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
//new master
|
||||
case MessageSendType.MESSAGE_ALL:
|
||||
{
|
||||
ChangeMasterMessage m = new ChangeMasterMessage();
|
||||
m.masterId = GetIntFromBytes(ReadExact(stream, 4)); //sender is the new master
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -539,9 +639,9 @@ namespace VelNet
|
|||
byte[] buffer = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
string welcome = userid + ":0:Hello";
|
||||
byte[] data = Encoding.ASCII.GetBytes(welcome);
|
||||
udpSocket.SendTo(data, data.Length, SocketFlags.None, RemoteEndPoint);
|
||||
buffer[0] = 0;
|
||||
Array.Copy(get_be_bytes(userid), 0, buffer, 1, 4);
|
||||
udpSocket.SendTo(buffer, 5, SocketFlags.None, RemoteEndPoint);
|
||||
|
||||
if (udpSocket.Available == 0)
|
||||
{
|
||||
|
|
@ -558,18 +658,24 @@ namespace VelNet
|
|||
while (true)
|
||||
{
|
||||
int numReceived = udpSocket.Receive(buffer);
|
||||
|
||||
string message = Encoding.UTF8.GetString(buffer, 0, numReceived);
|
||||
|
||||
string[] sections = message.Split(':');
|
||||
if (sections[0] == "0")
|
||||
switch (buffer[0])
|
||||
{
|
||||
case 0:
|
||||
Debug.Log("UDP connected");
|
||||
}
|
||||
|
||||
if (sections[0] == "3")
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
HandleMessage(message);
|
||||
DataMessage m = new DataMessage();
|
||||
//we should get the sender address
|
||||
byte[] senderBytes = new byte[4];
|
||||
Array.Copy(buffer, 1, senderBytes, 0, 4);
|
||||
m.senderId = GetIntFromBytes(senderBytes);
|
||||
byte[] messageBytes = new byte[numReceived - 5];
|
||||
Array.Copy(buffer, 5, messageBytes, 0, messageBytes.Length);
|
||||
m.data = messageBytes;
|
||||
AddMessage(m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -579,22 +685,20 @@ namespace VelNet
|
|||
}
|
||||
}
|
||||
|
||||
private static void SendUdpMessage(string message)
|
||||
private static void SendUdpMessage(byte[] message, int N)
|
||||
{
|
||||
if (instance.udpSocket == null || !instance.udpConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(message);
|
||||
//Debug.Log("Attempting to send: " + message);
|
||||
instance.udpSocket.SendTo(data, data.Length, SocketFlags.None, instance.RemoteEndPoint);
|
||||
instance.udpSocket.SendTo(message, N, SocketFlags.None, instance.RemoteEndPoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send message to server using socket connection.
|
||||
/// </summary>
|
||||
private static void SendNetworkMessage(string clientMessage)
|
||||
private static void SendTcpMessage(byte[] message) //we can assume that this message is already formatted, so we just send it
|
||||
{
|
||||
// Debug.Log("Sent: " + clientMessage);
|
||||
if (instance.socketConnection == null)
|
||||
|
|
@ -608,11 +712,7 @@ namespace VelNet
|
|||
NetworkStream stream = instance.socketConnection.GetStream();
|
||||
if (stream.CanWrite)
|
||||
{
|
||||
// Convert string message to byte array.
|
||||
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);
|
||||
stream.Write(message, 0, message.Length);
|
||||
}
|
||||
}
|
||||
catch (SocketException socketException)
|
||||
|
|
@ -621,12 +721,33 @@ namespace VelNet
|
|||
}
|
||||
}
|
||||
|
||||
public static byte[] get_be_bytes(int n)
|
||||
{
|
||||
return BitConverter.GetBytes(n).Reverse().ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the server with a username
|
||||
/// </summary>
|
||||
public static void Login(string username, string password)
|
||||
{
|
||||
SendNetworkMessage("0:" + username + ":" + password);
|
||||
MemoryStream stream = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
|
||||
byte[] uB = Encoding.UTF8.GetBytes(username);
|
||||
byte[] pB = Encoding.UTF8.GetBytes(password);
|
||||
writer.Write((byte)MessageSendType.MESSAGE_LOGIN);
|
||||
writer.Write((byte)uB.Length);
|
||||
writer.Write(uB);
|
||||
writer.Write((byte)pB.Length);
|
||||
writer.Write(pB);
|
||||
|
||||
SendTcpMessage(stream.ToArray());
|
||||
}
|
||||
|
||||
public static void GetRooms()
|
||||
{
|
||||
SendTcpMessage(new byte[] { 1 }); //very simple message
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -635,52 +756,125 @@ namespace VelNet
|
|||
/// <param name="roomname">The name of the room to join</param>
|
||||
public static void Join(string roomname)
|
||||
{
|
||||
SendNetworkMessage("2:" + roomname);
|
||||
MemoryStream stream = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
|
||||
byte[] R = Encoding.UTF8.GetBytes(roomname);
|
||||
writer.Write((byte)MessageSendType.MESSAGE_JOINROOM);
|
||||
writer.Write((byte)R.Length);
|
||||
writer.Write(R);
|
||||
SendTcpMessage(stream.ToArray());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Leaves a room if we're in one
|
||||
/// </summary>
|
||||
public static void Leave()
|
||||
{
|
||||
if (InRoom) SendNetworkMessage("2:-1");
|
||||
}
|
||||
|
||||
public static void SendTo(MessageType type, string message, bool reliable = true)
|
||||
if (InRoom)
|
||||
{
|
||||
if (reliable)
|
||||
{
|
||||
SendNetworkMessage("3:" + (int)type + ":" + message);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendUdpMessage(instance.userid + ":3:" + (int)type + ":" + message);
|
||||
Join(""); //super secret way to leave
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendToGroup(string group, string message, bool reliable = true)
|
||||
public static void SendCustomMessage(byte[] message, bool include_self = false, bool reliable = true, bool ordered = false)
|
||||
{
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)MessageType.Custom);
|
||||
writer.Write(message.Length);
|
||||
writer.Write(message);
|
||||
SendToRoom(mem.ToArray(), include_self, reliable, ordered);
|
||||
}
|
||||
|
||||
public static void SendCustomMessageToGroup(string group, byte[] message,bool reliable = true)
|
||||
{
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)MessageType.Custom);
|
||||
writer.Write(message.Length);
|
||||
writer.Write(message);
|
||||
SendToGroup(group, mem.ToArray(), reliable);
|
||||
}
|
||||
|
||||
internal static void SendToRoom(byte[] message, bool include_self = false, bool reliable = true, bool ordered = false)
|
||||
{
|
||||
byte sendType = (byte)MessageSendType.MESSAGE_OTHERS;
|
||||
if (include_self && ordered) sendType = (byte)MessageSendType.MESSAGE_ALL_ORDERED;
|
||||
if (include_self && !ordered) sendType = (byte)MessageSendType.MESSAGE_ALL;
|
||||
if (!include_self && ordered) sendType = (byte)MessageSendType.MESSAGE_OTHERS_ORDERED;
|
||||
|
||||
|
||||
if (reliable)
|
||||
{
|
||||
SendNetworkMessage("4:" + group + ":" + message);
|
||||
MemoryStream mem = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write(sendType);
|
||||
writer.Write(get_be_bytes(message.Length));
|
||||
writer.Write(message);
|
||||
SendTcpMessage(mem.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
SendUdpMessage(instance.userid + ":4:" + group + ":" + message);
|
||||
//udp message needs the type
|
||||
toSend[0] = sendType; //we don't
|
||||
Array.Copy(get_be_bytes(instance.userid), 0, toSend, 1, 4);
|
||||
Array.Copy(message, 0, toSend, 5, message.Length);
|
||||
SendUdpMessage(toSend, message.Length + 5); //shouldn't be over 1024...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static void SendToGroup(string group, byte[] message, bool reliable = true)
|
||||
{
|
||||
byte[] utf8bytes = Encoding.UTF8.GetBytes(group);
|
||||
if (reliable)
|
||||
{
|
||||
MemoryStream stream = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
writer.Write((byte)MessageSendType.MESSAGE_GROUP);
|
||||
writer.Write(get_be_bytes(message.Length));
|
||||
writer.Write(message);
|
||||
writer.Write((byte)utf8bytes.Length);
|
||||
writer.Write(utf8bytes);
|
||||
SendTcpMessage(stream.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
toSend[0] = (byte)MessageSendType.MESSAGE_GROUP;
|
||||
Array.Copy(get_be_bytes(instance.userid), 0, toSend, 1, 4);
|
||||
//also need to send the group
|
||||
toSend[5] = (byte)utf8bytes.Length;
|
||||
Array.Copy(utf8bytes, 0, toSend, 6, utf8bytes.Length);
|
||||
Array.Copy(message, 0, toSend, 6 + utf8bytes.Length, message.Length);
|
||||
SendUdpMessage(toSend, 6 + utf8bytes.Length + message.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// changes the designated group that sendto(4) will go to
|
||||
/// </summary>
|
||||
public static void SetupMessageGroup(string groupName, List<int> userIds)
|
||||
public static void SetupMessageGroup(string groupname, List<int> client_ids)
|
||||
{
|
||||
if (userIds.Count > 0)
|
||||
if (client_ids.Count > 0)
|
||||
{
|
||||
instance.groups[groupName] = userIds.ToList();
|
||||
instance.groups[groupname] = client_ids.ToList();
|
||||
}
|
||||
|
||||
SendNetworkMessage($"5:{groupName}:{string.Join(":", userIds)}");
|
||||
MemoryStream stream = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
byte[] R = Encoding.UTF8.GetBytes(groupname);
|
||||
writer.Write((byte)6);
|
||||
writer.Write((byte)R.Length);
|
||||
writer.Write(R);
|
||||
writer.Write(get_be_bytes(client_ids.Count * 4));
|
||||
for (int i = 0; i < client_ids.Count; i++)
|
||||
{
|
||||
writer.Write(get_be_bytes(client_ids[i]));
|
||||
}
|
||||
|
||||
SendTcpMessage(stream.ToArray());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -700,14 +894,21 @@ namespace VelNet
|
|||
Debug.LogError("Can't instantiate object. Obj with that network ID was already instantiated.", instance.objects[networkId]);
|
||||
return null;
|
||||
}
|
||||
|
||||
NetworkObject newObject = Instantiate(prefab);
|
||||
newObject.networkId = networkId;
|
||||
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.
|
||||
SendTo(MessageType.OTHERS, "7," + newObject.networkId + "," + prefabName);
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)MessageType.Instantiate);
|
||||
writer.Write(newObject.networkId);
|
||||
writer.Write(prefabName);
|
||||
SendToRoom(mem.ToArray(), include_self:false, reliable:true);
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
|
@ -737,6 +938,7 @@ namespace VelNet
|
|||
instance.objects.Remove(networkId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj.isSceneObject)
|
||||
{
|
||||
instance.deletedSceneObjects.Add(networkId);
|
||||
|
|
@ -777,8 +979,13 @@ namespace VelNet
|
|||
// immediately successful
|
||||
instance.objects[networkId].owner = LocalPlayer;
|
||||
|
||||
// must be ordered, so that ownership transfers are not confused. Also sent to all players, so that multiple simultaneous requests will result in the same outcome.
|
||||
SendTo(MessageType.ALL_ORDERED, "6," + networkId);
|
||||
// must be ordered, so that ownership transfers are not confused.
|
||||
// Also sent to all players, so that multiple simultaneous requests will result in the same outcome.
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)MessageType.TakeOwnership);
|
||||
writer.Write(networkId);
|
||||
SendToRoom(mem.ToArray(), false, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 03a4d4e1a7fd74c7ab2eccca4ce168db
|
||||
guid: 233344de094f11341bdb834d564708dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VelNet
|
||||
{
|
||||
|
|
@ -39,7 +42,12 @@ namespace VelNet
|
|||
{
|
||||
if (kvp.Value.owner == this && kvp.Value.prefabName != "")
|
||||
{
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.OTHERS, "7," + kvp.Value.networkId + "," + kvp.Value.prefabName);
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.Instantiate);
|
||||
writer.Write(kvp.Value.networkId);
|
||||
writer.Write(kvp.Value.prefabName);
|
||||
VelNetManager.SendToRoom(mem.ToArray(), false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,39 +61,42 @@ namespace VelNet
|
|||
|
||||
/// <summary>
|
||||
/// These are generally things that come from the "owner" and should be enacted locally, where appropriate
|
||||
///
|
||||
/// Message encoding:
|
||||
/// byte: message type
|
||||
/// byte[]: message
|
||||
///
|
||||
/// The length of the byte[] for message is fixed according to the message type
|
||||
/// </summary>
|
||||
public void HandleMessage(VelNetManager.Message m)
|
||||
public void HandleMessage(VelNetManager.DataMessage m)
|
||||
{
|
||||
//we need to parse the message
|
||||
using MemoryStream mem = new MemoryStream(m.data);
|
||||
using BinaryReader reader = new BinaryReader(mem);
|
||||
|
||||
//types of messages
|
||||
string[] messages = m.text.Split(';'); //messages are split by ;
|
||||
foreach (string s in messages)
|
||||
{
|
||||
//individual message parameters separated by comma
|
||||
string[] sections = s.Split(',');
|
||||
VelNetManager.MessageType messageType = (VelNetManager.MessageType)reader.ReadByte();
|
||||
|
||||
switch (sections[0])
|
||||
switch (messageType)
|
||||
{
|
||||
case "5": // sync update for an object I may own
|
||||
case VelNetManager.MessageType.ObjectSync: // sync update for an object I may own
|
||||
{
|
||||
string objectKey = sections[1];
|
||||
string identifier = sections[2];
|
||||
string syncMessage = sections[3];
|
||||
byte[] messageBytes = Convert.FromBase64String(syncMessage);
|
||||
string objectKey = reader.ReadString();
|
||||
byte componentIdx = reader.ReadByte();
|
||||
int messageLength = reader.ReadInt32();
|
||||
byte[] syncMessage = reader.ReadBytes(messageLength);
|
||||
if (manager.objects.ContainsKey(objectKey))
|
||||
{
|
||||
if (manager.objects[objectKey].owner == this)
|
||||
{
|
||||
manager.objects[objectKey].ReceiveBytes(identifier, messageBytes);
|
||||
manager.objects[objectKey].ReceiveBytes(componentIdx, syncMessage);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "6": // I'm trying to take ownership of an object
|
||||
case VelNetManager.MessageType.TakeOwnership: // I'm trying to take ownership of an object
|
||||
{
|
||||
string networkId = sections[1];
|
||||
string networkId = reader.ReadString();
|
||||
|
||||
if (manager.objects.ContainsKey(networkId))
|
||||
{
|
||||
|
|
@ -94,10 +105,10 @@ namespace VelNet
|
|||
|
||||
break;
|
||||
}
|
||||
case "7": // I'm trying to instantiate an object
|
||||
case VelNetManager.MessageType.Instantiate: // I'm trying to instantiate an object
|
||||
{
|
||||
string networkId = sections[1];
|
||||
string prefabName = sections[2];
|
||||
string networkId = reader.ReadString();
|
||||
string prefabName = reader.ReadString();
|
||||
if (manager.objects.ContainsKey(networkId))
|
||||
{
|
||||
break; //we already have this one, ignore
|
||||
|
|
@ -107,23 +118,30 @@ namespace VelNet
|
|||
|
||||
break;
|
||||
}
|
||||
case "8": // I'm trying to destroy a gameobject I own
|
||||
case VelNetManager.MessageType.Destroy: // I'm trying to destroy a gameobject I own
|
||||
{
|
||||
string networkId = sections[1];
|
||||
string networkId = reader.ReadString();
|
||||
|
||||
VelNetManager.NetworkDestroy(networkId);
|
||||
break;
|
||||
}
|
||||
case "9": //deleted scene objects
|
||||
case VelNetManager.MessageType.DeleteSceneObjects: //deleted scene objects
|
||||
{
|
||||
for (int k = 1; k < sections.Length; k++)
|
||||
int len = reader.ReadInt32();
|
||||
for (int k = 1; k < len; k++)
|
||||
{
|
||||
VelNetManager.NetworkDestroy(sections[k]);
|
||||
VelNetManager.NetworkDestroy(reader.ReadString());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case VelNetManager.MessageType.Custom: // custom packets
|
||||
{
|
||||
int len = reader.ReadInt32();
|
||||
VelNetManager.CustomMessageReceived?.Invoke(reader.ReadBytes(len));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,19 +152,42 @@ namespace VelNet
|
|||
//FindObjectsOfType<NetworkObject>();
|
||||
}
|
||||
|
||||
public void SendGroupMessage(NetworkObject obj, string group, string identifier, byte[] data, bool reliable = true)
|
||||
public static void SendGroupMessage(NetworkObject obj, string group, byte componentIdx, byte[] data, bool reliable = true)
|
||||
{
|
||||
VelNetManager.SendToGroup(group, "5," + obj.networkId + "," + identifier + "," + Convert.ToBase64String(data), reliable);
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.ObjectSync);
|
||||
writer.Write(obj.networkId);
|
||||
writer.Write(componentIdx);
|
||||
writer.Write(data.Length);
|
||||
writer.Write(data);
|
||||
VelNetManager.SendToGroup(group, mem.ToArray(), reliable);
|
||||
}
|
||||
|
||||
public void SendMessage(NetworkObject obj, string identifier, byte[] data, bool reliable = true)
|
||||
public static void SendMessage(NetworkObject obj, byte componentIdx, byte[] data, bool reliable = true)
|
||||
{
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.OTHERS, "5," + obj.networkId + "," + identifier + "," + Convert.ToBase64String(data), reliable);
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.ObjectSync);
|
||||
writer.Write(obj.networkId);
|
||||
writer.Write(componentIdx);
|
||||
writer.Write(data.Length);
|
||||
writer.Write(data);
|
||||
VelNetManager.SendToRoom(mem.ToArray(), false, reliable);
|
||||
}
|
||||
|
||||
public void SendSceneUpdate()
|
||||
{
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.OTHERS, "9," + string.Join(",", manager.deletedSceneObjects));
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.DeleteSceneObjects);
|
||||
writer.Write(manager.deletedSceneObjects.Count);
|
||||
foreach (string o in manager.deletedSceneObjects)
|
||||
{
|
||||
writer.Write(o);
|
||||
}
|
||||
|
||||
VelNetManager.SendToRoom(mem.ToArray());
|
||||
}
|
||||
|
||||
[Obsolete("Use VelNetManager.NetworkDestroy() instead.")]
|
||||
|
|
@ -156,7 +197,12 @@ namespace VelNet
|
|||
if (!manager.objects.ContainsKey(networkId) || manager.objects[networkId].owner != this || !isLocal) return;
|
||||
|
||||
// send to all, which will make me delete as well
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.ALL_ORDERED, "8," + networkId);
|
||||
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.Destroy);
|
||||
writer.Write(networkId);
|
||||
VelNetManager.SendToRoom(mem.ToArray(), true, true);
|
||||
}
|
||||
|
||||
/// <returns>True if successful, False if failed to transfer ownership</returns>
|
||||
|
|
@ -172,8 +218,13 @@ namespace VelNet
|
|||
// immediately successful
|
||||
manager.objects[networkId].owner = this;
|
||||
|
||||
// must be ordered, so that ownership transfers are not confused. Also sent to all players, so that multiple simultaneous requests will result in the same outcome.
|
||||
VelNetManager.SendTo(VelNetManager.MessageType.ALL_ORDERED, "6," + networkId);
|
||||
// must be ordered, so that ownership transfers are not confused.
|
||||
// Also sent to all players, so that multiple simultaneous requests will result in the same outcome.
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
using BinaryWriter writer = new BinaryWriter(mem);
|
||||
writer.Write((byte)VelNetManager.MessageType.TakeOwnership);
|
||||
writer.Write(networkId);
|
||||
VelNetManager.SendToRoom(mem.ToArray(), true, true, ordered: true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "edu.uga.engr.vel.velnet",
|
||||
"displayName": "VelNet",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"unity": "2019.1",
|
||||
"description": "A custom networking library for Unity.",
|
||||
"keywords": [
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
"dependencies": {
|
||||
"com.unity.collab-proxy": "1.15.7",
|
||||
"com.unity.ide.rider": "2.0.7",
|
||||
"com.unity.ide.visualstudio": "2.0.12",
|
||||
"com.unity.ide.visualstudio": "2.0.14",
|
||||
"com.unity.ide.vscode": "1.2.4",
|
||||
"com.unity.test-framework": "1.1.30",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
"com.unity.timeline": "1.4.8",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"edu.uga.engr.vel.velnet.dissonance": "file:S:/git_repo/VelNetDissonanceIntegration",
|
||||
"edu.uga.engr.vel.velnet.dissonance": "https://github.com/velaboratory/VelNetDissonanceIntegration.git",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.12",
|
||||
"version": "2.0.14",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
|
@ -106,12 +106,13 @@
|
|||
"dependencies": {}
|
||||
},
|
||||
"edu.uga.engr.vel.velnet.dissonance": {
|
||||
"version": "file:S:/git_repo/VelNetDissonanceIntegration",
|
||||
"version": "https://github.com/velaboratory/VelNetDissonanceIntegration.git",
|
||||
"depth": 0,
|
||||
"source": "local",
|
||||
"source": "git",
|
||||
"dependencies": {
|
||||
"edu.uga.engr.vel.velnet": "1.0.4"
|
||||
}
|
||||
},
|
||||
"hash": "2767cf12e6f1b5c568c44cd6f1753866ae2e6fca"
|
||||
},
|
||||
"com.unity.modules.ai": {
|
||||
"version": "1.0.0",
|
||||
|
|
|
|||
Loading…
Reference in New Issue