using System;
namespace Unity.Netcode
{
///
/// This is a wrapper that adds `INetworkSerializeByMemcpy` support to existing structs that the developer
/// doesn't have the ability to modify (for example, external structs like `Guid`).
///
///
public struct ForceNetworkSerializeByMemcpy : INetworkSerializeByMemcpy, IEquatable> where T : unmanaged, IEquatable
{
///
/// The wrapped value
///
public T Value;
///
/// The default constructor for
///
/// sets the initial value of type `T`
public ForceNetworkSerializeByMemcpy(T value)
{
Value = value;
}
///
/// Convert implicitly from the ForceNetworkSerializeByMemcpy wrapper to the underlying value
///
/// The wrapper
/// The underlying value
public static implicit operator T(ForceNetworkSerializeByMemcpy container) => container.Value;
///
/// Convert implicitly from a T value to a ForceNetworkSerializeByMemcpy wrapper
///
/// the value
/// a new wrapper
public static implicit operator ForceNetworkSerializeByMemcpy(T underlyingValue) => new ForceNetworkSerializeByMemcpy { Value = underlyingValue };
///
/// Check if wrapped values are equal
///
/// Other wrapper
/// true if equal
public bool Equals(ForceNetworkSerializeByMemcpy other)
{
return Value.Equals(other.Value);
}
///
/// Check if this value is equal to a boxed object value
///
/// The boxed value to check against
/// true if equal
public override bool Equals(object obj)
{
return obj is ForceNetworkSerializeByMemcpy other && Equals(other);
}
///
/// Obtains the wrapped value's hash code
///
/// Wrapped value's hash code
public override int GetHashCode()
{
return Value.GetHashCode();
}
}
}