Add ultimate xr

This commit is contained in:
2024-08-06 21:58:35 +02:00
parent 864033bf10
commit 7165bacd9d
3952 changed files with 2162037 additions and 35 deletions

View File

@@ -0,0 +1,44 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IUxrSerializable.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Interface to add serialization capabilities to a class.
/// </summary>
public interface IUxrSerializable
{
#region Public Types & Data
/// <summary>
/// Gets the current serialization version of the class that implements the interface. It has the same goal as
/// <see cref="UxrConstants.Serialization.CurrentBinaryVersion" /> but this version property is specific to each class
/// that implements the <see cref="IUxrSerializable" /> interface, which may be used outside the UltimateXR scope,
/// in user specific classes that want to benefit from serialization.<br />
/// Each class that implement the <see cref="IUxrSerializable" /> interface may have its own version. It is a number
/// that gets incremented by one each time the serialization format of the class that implements this interface
/// changes, enabling backwards compatibility.
/// </summary>
int SerializationVersion { get; }
#endregion
#region Public Methods
/// <summary>
/// Serializes or deserializes the object. The serializer interface uses the same methods to serialize and to
/// deserialize, instead of requiring separate serialization and deserialization methods.
/// This simplifies implementations and helps eliminating bugs due to inconsistencies between reading and writing.
/// </summary>
/// <param name="serializer">Serializer to use</param>
/// <param name="serializationVersion">
/// When reading it tells the <see cref="SerializationVersion" /> the data was
/// serialized with. When writing it uses the latest <see cref="SerializationVersion" /> version.
/// </param>
void Serialize(IUxrSerializer serializer, int serializationVersion);
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2aa06f29947837479c280d8f6e6cc07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,293 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IUxrSerializer.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using UltimateXR.Core.Math;
using UltimateXR.Core.Unique;
using UnityEngine;
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Interface to serialize and deserialize data. It uses a single method that performs the correct operation (read or
/// write) transparently, avoiding inconsistencies that can happen when using separate serialize/deserialize methods
/// on complex data with versioning.
/// </summary>
public interface IUxrSerializer : IDisposable
{
#region Public Types & Data
/// <summary>
/// Gets the serialization version. When reading it tells the version the data was serialized with. When writing it
/// uses the latest version.
/// </summary>
int Version { get; }
/// <summary>
/// Gets whether the operation is writing data (serializing) or reading data (deserializing).
/// </summary>
bool IsReading { get; }
#endregion
#region Public Methods
/// <summary>
/// Serializes or deserializes a boolean value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref bool value);
/// <summary>
/// Serializes or deserializes an sbyte value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref sbyte value);
/// <summary>
/// Serializes or deserializes a byte value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref byte value);
/// <summary>
/// Serializes or deserializes a char value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref char value);
/// <summary>
/// Serializes or deserializes an int value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref int value);
/// <summary>
/// Serializes or deserializes a uint value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref uint value);
/// <summary>
/// Serializes or deserializes a long value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref long value);
/// <summary>
/// Serializes or deserializes a ulong value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref ulong value);
/// <summary>
/// Serializes or deserializes a float value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref float value);
/// <summary>
/// Serializes or deserializes double value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref double value);
/// <summary>
/// Serializes or deserializes decimal value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref decimal value);
/// <summary>
/// Serializes or deserializes string value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
/// <remarks>Implementations must support serializing null strings</remarks>
void Serialize(ref string value);
/// <summary>
/// Serializes or deserializes an Enum value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeEnum<T>(ref T value) where T : Enum;
/// <summary>
/// Serializes or deserializes a type value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Type value);
/// <summary>
/// Serializes or deserializes a <see cref="Guid" /> value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Guid value);
/// <summary>
/// Serializes or deserializes a tuple.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize<T1, T2>(ref (T1, T2) value);
/// <summary>
/// Serializes or deserializes an array.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <typeparam name="T">The type of the elements</typeparam>
/// <remarks>Implementations must support null</remarks>
void Serialize<T>(ref T[] values);
/// <summary>
/// Serializes or deserializes an array, where each element might be of a different type. The type of each element will
/// be stored next to the object.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void Serialize(ref object[] values);
/// <summary>
/// Serializes or deserializes a list.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <typeparam name="T">The type of the elements</typeparam>
/// <remarks>Implementations must support null</remarks>
void Serialize<T>(ref List<T> values);
/// <summary>
/// Serializes or deserializes a list of objects, where each element might be of a different type. The type of each
/// element will be stored next to the object.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void Serialize(ref List<object> values);
/// <summary>
/// Serializes or deserializes a hash set.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <typeparam name="T">The type of the elements</typeparam>
/// <remarks>Implementations must support null</remarks>
void Serialize<T>(ref HashSet<T> values);
/// <summary>
/// Serializes or deserializes a hash set of objects, where each element might be of a different type. The type of each
/// element will be stored next to the object.
/// </summary>
/// <param name="values">The elements to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void Serialize(ref HashSet<object> values);
/// <summary>
/// Serializes or deserializes a dictionary.
/// </summary>
/// <param name="values">The values</param>
/// <typeparam name="TKey">The key type</typeparam>
/// <typeparam name="TValue">The value type</typeparam>
/// <remarks>Implementations must support null</remarks>
void Serialize<TKey, TValue>(ref Dictionary<TKey, TValue> values);
/// <summary>
/// Serializes or deserializes a <see cref="DateTime" /> value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref DateTime dateTime);
/// <summary>
/// Serializes or deserializes a <see cref="TimeSpan" /> value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref TimeSpan timeSpan);
/// <summary>
/// Serializes or deserializes a Vector2 value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Vector2 value);
/// <summary>
/// Serializes or deserializes a Vector3 value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Vector3 value);
/// <summary>
/// Serializes or deserializes a Vector4 value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Vector4 value);
/// <summary>
/// Serializes or deserializes Color value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Color value);
/// <summary>
/// Serializes or deserializes Color32 value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Color32 value);
/// <summary>
/// Serializes or deserializes Quaternion value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Quaternion value);
/// <summary>
/// Serializes or deserializes Matrix4x4 value.
/// </summary>
/// <param name="value">The element to serialize or deserialize</param>
void Serialize(ref Matrix4x4 value);
/// <summary>
/// Serializes or deserializes a component with the <see cref="IUxrUniqueId" /> interface, storing only the
/// <see cref="IUxrUniqueId.UniqueId" />.
/// </summary>
/// <param name="unique">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeUniqueComponent(ref IUxrUniqueId unique);
/// <summary>
/// Serializes or deserializes a component with the <see cref="IUxrUniqueId" /> interface, storing only the
/// <see cref="IUxrUniqueId.UniqueId" />.
/// </summary>
/// <param name="component">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeUniqueComponent<T>(ref T component) where T : Component, IUxrUniqueId;
/// <summary>
/// Serializes or deserializes an object that implements the <see cref="IUxrSerializable" /> interface.
/// </summary>
/// <param name="serializable">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeUxrSerializable(ref IUxrSerializable serializable);
/// <summary>
/// Serializes or deserializes an object that implements the <see cref="IUxrSerializable" /> interface.
/// </summary>
/// <param name="obj">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeUxrSerializable<T>(ref T obj) where T : IUxrSerializable;
/// <summary>
/// Serializes or deserializes an <see cref="UxrAxis" /> value.
/// </summary>
/// <param name="axis">The axis to serialize or deserialize</param>
void SerializeAxis(ref UxrAxis axis);
/// <summary>
/// Serializes a variable of a type that is known only at runtime. When writing it will serialize the type
/// together with the value so that it can be deserialized back when reading.
/// </summary>
/// <param name="obj">The element to serialize or deserialize</param>
/// <remarks>Implementations must support null</remarks>
void SerializeAnyVar<T>(ref T obj);
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee82d6ded7c93524daf62a5181c40d91
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,587 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrBinarySerializer.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using UltimateXR.Core.Math;
using UltimateXR.Core.Unique;
using UltimateXR.Extensions.System.IO;
using UnityEngine;
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Class that helps serializing/deserializing data using a single method instead of two separate Serialize
/// and Deserialize methods. It also stores the serialization version when reading or writing data.
/// </summary>
public class UxrBinarySerializer : IUxrSerializer
{
#region Constructors & Finalizer
/// <summary>
/// Constructor for deserialization.
/// </summary>
/// <param name="reader">Binary reader with the data</param>
/// <param name="version">Version that the data was serialized with</param>
public UxrBinarySerializer(BinaryReader reader, int version)
{
Version = version;
IsReading = true;
Reader = reader;
}
/// <summary>
/// Constructor for serialization.
/// </summary>
/// <param name="writer">Binary writer to output the data</param>
public UxrBinarySerializer(BinaryWriter writer)
{
Version = UxrConstants.Serialization.CurrentBinaryVersion;
IsReading = false;
Writer = writer;
}
#endregion
#region Implicit IDisposable
/// <inheritdoc />
public void Dispose()
{
}
#endregion
#region Implicit IUxrSerializer
/// <summary>
/// Gets, when reading, the version that the data was serialized with. When writing, it gets the latest version that it
/// is being serialized with, which is equal to <see cref="UxrConstants.Serialization.CurrentBinaryVersion" />.
/// </summary>
public int Version { get; }
/// <summary>
/// Gets whether the serializer is reading (using <see cref="Reader" />) or writing (using <see cref="Writer" />).
/// </summary>
public bool IsReading { get; }
/// <inheritdoc />
public void Serialize(ref bool value)
{
if (IsReading)
{
value = Reader.ReadBoolean();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref sbyte value)
{
if (IsReading)
{
value = Reader.ReadSByte();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref byte value)
{
if (IsReading)
{
value = Reader.ReadByte();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref char value)
{
if (IsReading)
{
value = Reader.ReadChar();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref int value)
{
if (IsReading)
{
value = Reader.ReadCompressedInt32(Version);
}
else
{
Writer.WriteCompressedInt32(value);
}
}
/// <inheritdoc />
public void Serialize(ref uint value)
{
if (IsReading)
{
value = Reader.ReadCompressedUInt32(Version);
}
else
{
Writer.WriteCompressedUInt32(value);
}
}
/// <inheritdoc />
public void Serialize(ref long value)
{
if (IsReading)
{
value = Reader.ReadCompressedInt64(Version);
}
else
{
Writer.WriteCompressedInt64(value);
}
}
/// <inheritdoc />
public void Serialize(ref ulong value)
{
if (IsReading)
{
value = Reader.ReadCompressedUInt64(Version);
}
else
{
Writer.WriteCompressedUInt64(value);
}
}
/// <inheritdoc />
public void Serialize(ref float value)
{
if (IsReading)
{
value = Reader.ReadSingle();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref double value)
{
if (IsReading)
{
value = Reader.ReadDouble();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref decimal value)
{
if (IsReading)
{
value = Reader.ReadDecimal();
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref string value)
{
if (IsReading)
{
bool nullCheck = Reader.ReadBoolean();
value = nullCheck ? Reader.ReadString() : null;
}
else
{
Writer.Write(value != null);
if (value != null)
{
Writer.Write(value);
}
}
}
/// <inheritdoc />
public void SerializeEnum<T>(ref T value) where T : Enum
{
if (IsReading)
{
value = Reader.ReadEnum<T>(Version);
}
else
{
Writer.WriteEnum(value);
}
}
/// <inheritdoc />
public void Serialize(ref Type value)
{
if (IsReading)
{
value = Reader.ReadType(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Guid value)
{
if (IsReading)
{
value = Reader.ReadGuid(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize<T1, T2>(ref (T1, T2) value)
{
if (IsReading)
{
value = Reader.ReadTuple<T1, T2>(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize<T>(ref T[] values)
{
if (IsReading)
{
values = Reader.ReadArray<T>(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize(ref object[] values)
{
if (IsReading)
{
values = Reader.ReadObjectArray(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize<T>(ref List<T> values)
{
if (IsReading)
{
values = Reader.ReadList<T>(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize(ref List<object> values)
{
if (IsReading)
{
values = Reader.ReadObjectList(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize<TKey, TValue>(ref Dictionary<TKey, TValue> values)
{
if (IsReading)
{
values = Reader.ReadDictionary<TKey, TValue>(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize<T>(ref HashSet<T> values)
{
if (IsReading)
{
values = Reader.ReadHashSet<T>(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize(ref HashSet<object> values)
{
if (IsReading)
{
values = Reader.ReadObjectHashSet(Version);
}
else
{
Writer.Write(values);
}
}
/// <inheritdoc />
public void Serialize(ref DateTime value)
{
if (IsReading)
{
value = Reader.ReadDateTime(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref TimeSpan value)
{
if (IsReading)
{
value = Reader.ReadTimeSpan(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Vector2 value)
{
if (IsReading)
{
value = Reader.ReadVector2(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Vector3 value)
{
if (IsReading)
{
value = Reader.ReadVector3(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Vector4 value)
{
if (IsReading)
{
value = Reader.ReadVector4(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Color value)
{
if (IsReading)
{
value = Reader.ReadColor(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Color32 value)
{
if (IsReading)
{
value = Reader.ReadColor32(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Quaternion value)
{
if (IsReading)
{
value = Reader.ReadQuaternion(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void Serialize(ref Matrix4x4 value)
{
if (IsReading)
{
value = Reader.ReadMatrix(Version);
}
else
{
Writer.Write(value);
}
}
/// <inheritdoc />
public void SerializeUniqueComponent(ref IUxrUniqueId unique)
{
if (IsReading)
{
unique = Reader.ReadUniqueComponent(Version);
}
else
{
Writer.WriteUniqueComponent(unique);
}
}
/// <inheritdoc />
public void SerializeUniqueComponent<T>(ref T component) where T : Component, IUxrUniqueId
{
if (IsReading)
{
component = Reader.ReadUniqueComponent(Version) as T;
}
else
{
Writer.WriteUniqueComponent(component);
}
}
/// <inheritdoc />
public void SerializeUxrSerializable(ref IUxrSerializable serializable)
{
if (IsReading)
{
serializable = Reader.ReadUxrSerializable(Version);
}
else
{
Writer.WriteUxrSerializable(serializable);
}
}
/// <inheritdoc />
public void SerializeUxrSerializable<T>(ref T obj) where T : IUxrSerializable
{
if (IsReading)
{
obj = (T)Reader.ReadUxrSerializable(Version);
}
else
{
Writer.WriteUxrSerializable(obj);
}
}
/// <inheritdoc />
public void SerializeAxis(ref UxrAxis axis)
{
if (IsReading)
{
axis = Reader.ReadAxis(Version);
}
else
{
Writer.WriteAxis(axis);
}
}
/// <inheritdoc />
public void SerializeAnyVar<T>(ref T obj)
{
if (IsReading)
{
obj = (T)Reader.ReadAnyVar(Version);
}
else
{
Writer.WriteAnyVar(obj);
}
}
#endregion
#region Private Types & Data
/// <summary>
/// Gets the reader, if <see cref="IsReading" /> is true. Otherwise it is null.
/// </summary>
private BinaryReader Reader { get; }
/// <summary>
/// Gets the writer, if <see cref="IsReading" /> is false. Otherwise it is null.
/// </summary>
private BinaryWriter Writer { get; }
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b432ceb3955a0343838c776354833dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,259 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrDummySerializer.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using UltimateXR.Core.Math;
using UltimateXR.Core.StateSave;
using UltimateXR.Core.Unique;
using UnityEngine;
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Serializer that doesn't read or write data. It can be used by <see cref="IUxrStateSave" /> implementations to cache
/// initial object data without any read or write operations.
/// </summary>
public class UxrDummySerializer : IUxrSerializer
{
#region Constructors & Finalizer
/// <summary>
/// Constructor for deserialization.
/// </summary>
/// <param name="isReading">Whether to initialize in read mode or write mode</param>
/// <param name="version">Version that the data was serialized with</param>
public UxrDummySerializer(bool isReading, int version)
{
Version = version;
IsReading = isReading;
}
#endregion
#region Implicit IDisposable
/// <inheritdoc />
public void Dispose()
{
}
#endregion
#region Implicit IUxrSerializer
/// <inheritdoc />
public int Version { get; }
/// <inheritdoc />
public bool IsReading { get; }
/// <inheritdoc />
public void Serialize(ref bool value)
{
}
/// <inheritdoc />
public void Serialize(ref sbyte value)
{
}
/// <inheritdoc />
public void Serialize(ref byte value)
{
}
/// <inheritdoc />
public void Serialize(ref char value)
{
}
/// <inheritdoc />
public void Serialize(ref int value)
{
}
/// <inheritdoc />
public void Serialize(ref uint value)
{
}
/// <inheritdoc />
public void Serialize(ref long value)
{
}
/// <inheritdoc />
public void Serialize(ref ulong value)
{
}
/// <inheritdoc />
public void Serialize(ref float value)
{
}
/// <inheritdoc />
public void Serialize(ref double value)
{
}
/// <inheritdoc />
public void Serialize(ref decimal value)
{
}
/// <inheritdoc />
public void Serialize(ref string value)
{
}
/// <inheritdoc />
public void SerializeEnum<T>(ref T value) where T : Enum
{
}
/// <inheritdoc />
public void Serialize(ref Type value)
{
}
/// <inheritdoc />
public void Serialize(ref Guid value)
{
}
/// <inheritdoc />
public void Serialize<T1, T2>(ref (T1, T2) value)
{
}
/// <inheritdoc />
public void Serialize<T>(ref T[] values)
{
}
/// <inheritdoc />
public void Serialize(ref object[] values)
{
}
/// <inheritdoc />
public void Serialize<T>(ref List<T> values)
{
}
/// <inheritdoc />
public void Serialize(ref List<object> values)
{
}
/// <inheritdoc />
public void Serialize<TKey, TValue>(ref Dictionary<TKey, TValue> values)
{
}
/// <inheritdoc />
public void Serialize<T>(ref HashSet<T> values)
{
}
/// <inheritdoc />
public void Serialize(ref HashSet<object> values)
{
}
/// <inheritdoc />
public void Serialize(ref DateTime value)
{
}
/// <inheritdoc />
public void Serialize(ref TimeSpan value)
{
}
/// <inheritdoc />
public void Serialize(ref Vector2 value)
{
}
/// <inheritdoc />
public void Serialize(ref Vector3 value)
{
}
/// <inheritdoc />
public void Serialize(ref Vector4 value)
{
}
/// <inheritdoc />
public void Serialize(ref Color value)
{
}
/// <inheritdoc />
public void Serialize(ref Color32 value)
{
}
/// <inheritdoc />
public void Serialize(ref Quaternion value)
{
}
/// <inheritdoc />
public void Serialize(ref Matrix4x4 value)
{
}
/// <inheritdoc />
public void SerializeUniqueComponent(ref IUxrUniqueId unique)
{
}
/// <inheritdoc />
public void SerializeUniqueComponent<T>(ref T component) where T : Component, IUxrUniqueId
{
}
/// <inheritdoc />
public void SerializeUxrSerializable(ref IUxrSerializable serializable)
{
}
/// <inheritdoc />
public void SerializeUxrSerializable<T>(ref T obj) where T : IUxrSerializable
{
}
/// <inheritdoc />
public void SerializeAxis(ref UxrAxis axis)
{
}
/// <inheritdoc />
public void SerializeAnyVar<T>(ref T obj)
{
}
#endregion
#region Public Types & Data
/// <summary>
/// Gets a dummy serializer initialized in read mode.
/// </summary>
public static UxrDummySerializer ReadModeSerializer = new UxrDummySerializer(true, UxrConstants.Serialization.CurrentBinaryVersion);
/// <summary>
/// Gets a dummy serializer initialized in write mode.
/// </summary>
public static UxrDummySerializer WriteModeSerializer = new UxrDummySerializer(false, UxrConstants.Serialization.CurrentBinaryVersion);
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 483be337e05e7b64786f8dedfb2a7eb5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrSerializationFormat.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Enumerates the different serialization formats that are supported.
/// </summary>
public enum UxrSerializationFormat
{
/// <summary>
/// Binary uncompressed format.
/// </summary>
BinaryUncompressed,
/// <summary>
/// Binary compressed using Gzip.
/// </summary>
BinaryGzip
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9c879fce5d1bfb45b743e14774e4e79
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrVarType.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core.StateSync;
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Enumerates the variable types supported by serialization, for example
/// <see cref="UxrPropertyChangedSyncEventArgs" />.
/// </summary>
public enum UxrVarType
{
Unknown = 0,
// C#
Bool = 1,
SignedByte = 2,
Byte = 3,
Char = 4,
Int = 5,
UnsignedInt = 6,
Long = 7,
UnsignedLong = 8,
Float = 9,
Double = 10,
Decimal = 11,
String = 12,
Enum = 13,
Type = 20,
Guid = 21,
Tuple = 22,
// C# collections
Array = 30,
ObjectArray = 31,
List = 32,
ObjectList = 33,
Dictionary = 34,
HashSet = 35,
ObjectHashSet = 36,
// Other C# types
DateTime = 50,
TimeSpan = 51,
// Unity
Vector2 = 100,
Vector3 = 101,
Vector4 = 102,
Color = 103,
Color32 = 104,
Quaternion = 105,
Matrix4x4 = 106,
// UXR
IUxrUnique = 200,
IUxrSerializable = 201,
UxrAxis = 202
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dfeeeeda25242ae40886a7415517952b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,216 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UxrVarTypeExt.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using UltimateXR.Core.Math;
using UltimateXR.Core.Settings;
using UltimateXR.Core.Unique;
using UnityEngine;
namespace UltimateXR.Core.Serialization
{
/// <summary>
/// Extensions for <see cref="UxrVarType" />.
/// </summary>
public static class UxrVarTypeExt
{
#region Public Methods
/// <summary>
/// Tries to get the type of an object that support serialization/deserialization using UltimateXR.
/// </summary>
/// <param name="obj">Object to get the type of</param>
/// <returns>Type from <see cref="UxrVarType" /> or <see cref="UxrVarType.Unknown" /> if not supported</returns>
public static UxrVarType GetType<T>(T obj)
{
if (obj == null)
{
return UxrVarType.Unknown;
}
Type type = obj.GetType();
// C# types
if (obj is bool)
{
return UxrVarType.Bool;
}
if (obj is sbyte)
{
return UxrVarType.SignedByte;
}
if (obj is byte)
{
return UxrVarType.Byte;
}
if (obj is char)
{
return UxrVarType.Char;
}
if (obj is int)
{
return UxrVarType.Int;
}
if (obj is uint)
{
return UxrVarType.UnsignedInt;
}
if (obj is long)
{
return UxrVarType.Long;
}
if (obj is ulong)
{
return UxrVarType.UnsignedLong;
}
if (obj is float)
{
return UxrVarType.Float;
}
if (obj is double)
{
return UxrVarType.Double;
}
if (obj is decimal)
{
return UxrVarType.Decimal;
}
if (obj is string)
{
return UxrVarType.String;
}
if (obj is Enum)
{
return UxrVarType.Enum;
}
if (obj is Type)
{
return UxrVarType.Type;
}
if (obj is Guid)
{
return UxrVarType.Guid;
}
if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Tuple<,>) || type.GetGenericTypeDefinition() == typeof(ValueTuple<,>)))
{
return UxrVarType.Tuple;
}
// C# collections
if (type.IsArray)
{
return type.GetElementType() == typeof(object) ? UxrVarType.ObjectArray : UxrVarType.Array;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
{
return type.GetElementType() == typeof(object) ? UxrVarType.ObjectList : UxrVarType.List;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
return UxrVarType.Dictionary;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(HashSet<>))
{
return type.GetElementType() == typeof(object) ? UxrVarType.ObjectHashSet : UxrVarType.HashSet;
}
// Other C# types
if (obj is DateTime)
{
return UxrVarType.DateTime;
}
if (obj is TimeSpan)
{
return UxrVarType.TimeSpan;
}
// Unity types
if (obj is Vector2)
{
return UxrVarType.Vector2;
}
if (obj is Vector3)
{
return UxrVarType.Vector3;
}
if (obj is Vector4)
{
return UxrVarType.Vector4;
}
if (obj is Color)
{
return UxrVarType.Color;
}
if (obj is Color32)
{
return UxrVarType.Color32;
}
if (obj is Quaternion)
{
return UxrVarType.Quaternion;
}
if (obj is Matrix4x4)
{
return UxrVarType.Matrix4x4;
}
// UXR types
if (obj is IUxrUniqueId)
{
return UxrVarType.IUxrUnique;
}
if (obj is IUxrSerializable)
{
return UxrVarType.IUxrSerializable;
}
if (obj is UxrAxis)
{
return UxrVarType.UxrAxis;
}
if (UxrGlobalSettings.Instance.LogLevelCore >= UxrLogLevel.Errors)
{
Debug.LogError($"{UxrConstants.CoreModule} Unknown type in {nameof(GetType)} ({type.FullName})");
}
return UxrVarType.Unknown;
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a01bc1f70562035458a24f0420087494
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: