using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
///
/// Representation of four-dimensional vectors.
///
namespace UnityLibrary
{
[Serializable]
public struct Vector4Serializable : ISerializable
{
#region Parametres
///
/// X component of the vector.
///
public float x;
///
/// Y component of the vector.
///
public float y;
///
/// Z component of the vector.
///
public float z;
///
/// W component of the vector.
///
public float w;
#endregion
#region Constructors
///
/// Initializes a new instance of the struct.
///
/// Vector.
public Vector4Serializable(Vector2 vector) : this(vector.x, vector.y)
{
}
///
/// Initializes a new instance of the struct.
///
/// Vector.
public Vector4Serializable(Vector3 vector) : this(vector.x, vector.y, vector.z)
{
}
///
/// Initializes a new instance of the struct.
///
/// Vector.
public Vector4Serializable(Vector4 vector) : this(vector.x, vector.y, vector.z, vector.w)
{
}
///
/// Initializes a new instance of the struct.
///
/// The x coordinate.
/// The y coordinate.
public Vector4Serializable(float x, float y) : this(x, y, 0f)
{
}
///
/// Initializes a new instance of the struct.
///
/// The x coordinate.
/// The y coordinate.
/// The z coordinate.
public Vector4Serializable(float x, float y, float z) : this(x, y, z, 0f)
{
}
///
/// Initializes a new instance of the struct.
///
/// The x coordinate.
/// The y coordinate.
/// The z coordinate.
/// The width.
public Vector4Serializable(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
#endregion
#region Methods
public override bool Equals(object obj)
{
if (obj is Vector4Serializable || obj is Vector4)
{
Vector4Serializable vector = (Vector4Serializable)obj;
return this.x == vector.x && this.y == vector.y && this.z == vector.z && this.w == vector.w;
}
return false;
}
public override int GetHashCode()
{
return this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2 ^ this.w.GetHashCode() >> 1;
}
public override string ToString()
{
return string.Format("({0}, {1}, {2}, {3})", this.x, this.y, this.z, this.w);
}
#endregion
#region Operators Overload
public static implicit operator Vector4Serializable(Vector2 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector2(Vector4Serializable vector)
{
return new Vector2(vector.x, vector.y);
}
public static implicit operator Vector4Serializable(Vector3 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector3(Vector4Serializable vector)
{
return new Vector3(vector.x, vector.y, vector.z);
}
public static implicit operator Vector4Serializable(Vector4 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector4(Vector4Serializable vector)
{
return new Vector4(vector.x, vector.y, vector.z, vector.w);
}
public static implicit operator Vector4Serializable(Vector2Serializable vector)
{
return new Vector4Serializable((Vector4)vector);
}
public static implicit operator Vector2Serializable(Vector4Serializable vector)
{
return new Vector2Serializable((Vector4)vector);
}
public static implicit operator Vector4Serializable(Vector3Serializable vector)
{
return new Vector4Serializable((Vector4)vector);
}
public static implicit operator Vector3Serializable(Vector4Serializable vector)
{
return new Vector3Serializable((Vector4)vector);
}
#endregion
#region ISerializable implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("x", this.x, typeof(float));
info.AddValue("y", this.y, typeof(float));
info.AddValue("z", this.w, typeof(float));
info.AddValue("w", this.w, typeof(float));
}
#endregion
}
}