Initial commit of Unity files, Network Library, Project settings (Compiler flags for networking to work on Unity), Unity Version 2019.4 LTS
This commit is contained in:
parent
8ec6828fa0
commit
9b69003715
119 changed files with 15444 additions and 0 deletions
52
Assets/Runtime/Networking/Helpers/HashtableExtension.cs
Normal file
52
Assets/Runtime/Networking/Helpers/HashtableExtension.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using UnityEngine;
|
||||
using ExitGames.Client.Photon.LoadBalancing;
|
||||
|
||||
using Hashtable = ExitGames.Client.Photon.Hashtable;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions of Exitgames Hashtable to allow for concise conditional setting logic
|
||||
/// </summary>
|
||||
public static class HashtableExtension {
|
||||
/// <summary>
|
||||
/// Checks if the hashtable contains key, if so, it will update toSet. Struct version
|
||||
/// </summary>
|
||||
/// <param name="key">Key to check for</param>
|
||||
/// <param name="toSet">Reference to the variable to set</param>
|
||||
/// <typeparam name="T">Type to cast toSet to</typeparam>
|
||||
public static void SetOnKey<T>(this Hashtable h, object key, ref T toSet) where T : struct {
|
||||
if (h.ContainsKey(key))
|
||||
toSet = (T)h[key];
|
||||
}
|
||||
|
||||
public static void AddOrSet<T>(this Hashtable h, object key, T val) where T : struct {
|
||||
if (h.ContainsKey(key)) {
|
||||
h[key] = val;
|
||||
} else {
|
||||
h.Add(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a value to the hashtable if and only if it mismatches the previous provided
|
||||
/// Returns true if the replacement was made
|
||||
/// </summary>
|
||||
public static bool AddWithDirty<T>(this Hashtable h, char key, T tracked, ref T previous) {
|
||||
if (tracked.Equals(previous)) return false;
|
||||
|
||||
h.Add (key,tracked);
|
||||
previous = tracked;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds and updates the keys/value based on <paramref name="propertiesToSet"/>.
|
||||
/// Any other keys are uneffected.
|
||||
/// </summary>
|
||||
/// <param name="h"></param>
|
||||
/// <param name="propertiesToSet"></param>
|
||||
public static void SetHashtable(this Hashtable h, Hashtable propertiesToSet){
|
||||
var customProps = propertiesToSet.StripToStringKeys() as Hashtable;
|
||||
h.Merge(customProps);
|
||||
h.StripKeysWithNullValues();
|
||||
}
|
||||
}
|
11
Assets/Runtime/Networking/Helpers/HashtableExtension.cs.meta
Normal file
11
Assets/Runtime/Networking/Helpers/HashtableExtension.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91b1fc7f0e237bb4e8fc167e80d4b8e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Runtime/Networking/Helpers/PhotonConstants.cs
Normal file
34
Assets/Runtime/Networking/Helpers/PhotonConstants.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class PhotonConstants {
|
||||
public static readonly byte EntityUpdateCode = 110;
|
||||
public static readonly byte EntityEventCode = 105;
|
||||
public static readonly byte EntityInstantiateCode = 106;
|
||||
public static readonly char eidChar = (char)206; // 'Î'
|
||||
public static readonly char athChar = (char)238; // 'î'
|
||||
public static readonly char insChar = (char)207; // 'Ï'
|
||||
public static readonly char tpeChar = (char)208;
|
||||
|
||||
public static readonly string propScene = "sc";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Region names strings
|
||||
/// </summary>
|
||||
public static readonly Dictionary<string,string> RegionNames = new Dictionary<string,string>() {
|
||||
{"asia","Signapore"},
|
||||
{"au","Australia"},
|
||||
{"cae","Montreal"},
|
||||
{"cn","Shanghai"},
|
||||
{"eu","Europe"},
|
||||
{"in","India"},
|
||||
{"jp","Japan"},
|
||||
{"ru","Moscow"},
|
||||
{"rue","East Russia"},
|
||||
{"sa","Brazil"},
|
||||
{"kr","South Korea"},
|
||||
{"us","Eastern US"},
|
||||
{"usw","Western US"}
|
||||
};
|
||||
}
|
11
Assets/Runtime/Networking/Helpers/PhotonConstants.cs.meta
Normal file
11
Assets/Runtime/Networking/Helpers/PhotonConstants.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3090fc43b95be2244909c218fbf35512
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
139
Assets/Runtime/Networking/Helpers/StreamCustomTypes.cs
Normal file
139
Assets/Runtime/Networking/Helpers/StreamCustomTypes.cs
Normal file
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ExitGames.Client.Photon;
|
||||
using UnityEngine;
|
||||
|
||||
using Hashtable = ExitGames.Client.Photon.Hashtable;
|
||||
|
||||
public static class StreamCustomTypes {
|
||||
public static void Register() {
|
||||
PhotonPeer.RegisterType(typeof(Vector2), (byte)'V', SerializeVector2, DeserializeVector2);
|
||||
PhotonPeer.RegisterType(typeof(Vector3), (byte)'W', SerializeVector3, DeserializeVector3);
|
||||
PhotonPeer.RegisterType(typeof(Quaternion), (byte)'Q', SerializeQuaternion, DeserializeQuaternion);
|
||||
PhotonPeer.RegisterType(typeof(Color), (byte)'C', SerializeColor, DeserializeColor);
|
||||
PhotonPeer.RegisterType(typeof(char), (byte)'c', SerializeChar, DeserializeChar);
|
||||
}
|
||||
|
||||
private static short SerializeVector2(StreamBuffer outStream, object customObj) {
|
||||
var vo = (Vector2)customObj;
|
||||
|
||||
var ms = new MemoryStream(2 * 4);
|
||||
|
||||
ms.Write(BitConverter.GetBytes(vo.x), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.y), 0, 4);
|
||||
|
||||
outStream.Write(ms.ToArray(), 0, 2 * 4);
|
||||
return 2 * 4;
|
||||
}
|
||||
|
||||
private static object DeserializeVector2(StreamBuffer inStream, short length) {
|
||||
var bytes = new Byte[2 * 4];
|
||||
inStream.Read(bytes, 0, 2 * 4);
|
||||
return new
|
||||
Vector2(
|
||||
BitConverter.ToSingle(bytes, 0),
|
||||
BitConverter.ToSingle(bytes, 4));
|
||||
|
||||
// As best as I can tell, the new Protocol.Serialize/Deserialize are written around WP8 restrictions
|
||||
// It's not worth the pain.
|
||||
|
||||
//int index = 0;
|
||||
//float x, y;
|
||||
//Protocol.Deserialize(out x, bytes, ref index);
|
||||
//Protocol.Deserialize(out y, bytes, ref index);
|
||||
|
||||
//return new Vector2(x, y);
|
||||
}
|
||||
|
||||
private static short SerializeVector3(StreamBuffer outStream, object customObj) {
|
||||
Vector3 vo = (Vector3)customObj;
|
||||
|
||||
var ms = new MemoryStream(3 * 4);
|
||||
|
||||
ms.Write(BitConverter.GetBytes(vo.x), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.y), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.z), 0, 4);
|
||||
|
||||
outStream.Write(ms.ToArray(), 0, 3 * 4);
|
||||
return 3 * 4;
|
||||
}
|
||||
|
||||
private static object DeserializeVector3(StreamBuffer inStream, short length) {
|
||||
var bytes = new byte[3 * 4];
|
||||
|
||||
inStream.Read(bytes, 0, 3 * 4);
|
||||
|
||||
return new
|
||||
Vector3(
|
||||
BitConverter.ToSingle(bytes, 0),
|
||||
BitConverter.ToSingle(bytes, 4),
|
||||
BitConverter.ToSingle(bytes, 8));
|
||||
}
|
||||
|
||||
private static short SerializeQuaternion(StreamBuffer outStream, object customObj) {
|
||||
Quaternion vo = (Quaternion)customObj;
|
||||
|
||||
var ms = new MemoryStream(4 * 4);
|
||||
|
||||
ms.Write(BitConverter.GetBytes(vo.x), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.y), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.z), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.w), 0, 4);
|
||||
|
||||
outStream.Write(ms.ToArray(), 0, 4 * 4);
|
||||
return 4 * 4;
|
||||
}
|
||||
|
||||
private static object DeserializeQuaternion(StreamBuffer inStream, short length) {
|
||||
var bytes = new byte[4 * 4];
|
||||
|
||||
inStream.Read(bytes, 0, 4 * 4);
|
||||
|
||||
return new
|
||||
Quaternion(
|
||||
BitConverter.ToSingle(bytes, 0),
|
||||
BitConverter.ToSingle(bytes, 4),
|
||||
BitConverter.ToSingle(bytes, 8),
|
||||
BitConverter.ToSingle(bytes, 12));
|
||||
}
|
||||
|
||||
private static short SerializeColor(StreamBuffer outStream, object customObj) {
|
||||
Color vo = (Color)customObj;
|
||||
|
||||
var ms = new MemoryStream(4 * 4);
|
||||
|
||||
ms.Write(BitConverter.GetBytes(vo.r), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.g), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.b), 0, 4);
|
||||
ms.Write(BitConverter.GetBytes(vo.a), 0, 4);
|
||||
|
||||
outStream.Write(ms.ToArray(), 0, 4 * 4);
|
||||
return 4 * 4;
|
||||
}
|
||||
|
||||
private static object DeserializeColor(StreamBuffer inStream, short length) {
|
||||
var bytes = new byte[4 * 4];
|
||||
|
||||
inStream.Read(bytes, 0, 4 * 4);
|
||||
|
||||
return new
|
||||
Color(
|
||||
BitConverter.ToSingle(bytes, 0),
|
||||
BitConverter.ToSingle(bytes, 4),
|
||||
BitConverter.ToSingle(bytes, 8),
|
||||
BitConverter.ToSingle(bytes, 12));
|
||||
}
|
||||
|
||||
private static short SerializeChar(StreamBuffer outStream, object customObj) {
|
||||
outStream.Write(new[]{ (byte)((char)customObj) }, 0, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static object DeserializeChar(StreamBuffer inStream, short Length) {
|
||||
var bytes = new Byte[1];
|
||||
inStream.Read(bytes, 0, 1);
|
||||
|
||||
return (char)bytes[0];
|
||||
}
|
||||
}
|
11
Assets/Runtime/Networking/Helpers/StreamCustomTypes.cs.meta
Normal file
11
Assets/Runtime/Networking/Helpers/StreamCustomTypes.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4402087c29fe6f4888bd19ae6c229d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue