namespace Zinnia.Data.Type
{
using System;
using UnityEngine;
using Zinnia.Extension;
///
/// Holds information with the ability to override properties without affecting the scene .
///
[Serializable]
public class TransformData
{
[Tooltip("A reference to the original UnityEngine.Transform.")]
[SerializeField]
private Transform transform;
///
/// A reference to the original .
///
public Transform Transform
{
get
{
return transform;
}
set
{
transform = value;
}
}
[Tooltip("Determines whether to operate on the local or global values.")]
[SerializeField]
private bool useLocalValues;
///
/// Determines whether to operate on the local or global values.
///
public bool UseLocalValues
{
get
{
return useLocalValues;
}
set
{
useLocalValues = value;
}
}
[Tooltip("Position override of the UnityEngine.Transform object.")]
[SerializeField]
private Vector3? positionOverride;
///
/// Position override of the object.
///
public Vector3? PositionOverride
{
get
{
return positionOverride;
}
set
{
positionOverride = value;
}
}
[Tooltip("Rotation override of the UnityEngine.Transform object.")]
[SerializeField]
private Quaternion? rotationOverride;
///
/// Rotation override of the object.
///
public Quaternion? RotationOverride
{
get
{
return rotationOverride;
}
set
{
rotationOverride = value;
}
}
[Tooltip("Scale override of the UnityEngine.Transform object.")]
[SerializeField]
private Vector3? scaleOverride;
///
/// Scale override of the object.
///
public Vector3? ScaleOverride
{
get
{
return scaleOverride;
}
set
{
scaleOverride = value;
}
}
///
/// The position of the or the if it is set.
///
public virtual Vector3 Position => PositionOverride ?? (UseLocalValues ? Transform.localPosition : Transform.position);
///
/// The rotation of the or the if it is set.
///
public virtual Quaternion Rotation => RotationOverride ?? (UseLocalValues ? Transform.localRotation : Transform.rotation);
///
/// The scale of the or the if it is set.
///
public virtual Vector3 Scale => ScaleOverride ?? (UseLocalValues ? Transform.localScale : Transform.lossyScale);
///
/// The state of whether the is valid.
///
public virtual bool IsValid => Transform != null;
///
/// Creates a new for an empty .
///
public TransformData() { }
///
/// Creates a new from an existing .
///
/// The to create the from.
public TransformData(Transform transform)
{
Transform = transform;
}
///
/// Creates a new from an existing .
///
/// The to create the from.
public TransformData(GameObject gameObject) : this(gameObject != null ? gameObject.transform : null) { }
///
public override bool Equals(object other)
{
if (other == null)
{
return false;
}
TransformData data = other as TransformData;
return Equals(data);
}
///
public override int GetHashCode()
{
return base.GetHashCode();
}
///
public override string ToString()
{
string[] titles = new string[]
{
"Transform",
"UseLocalValues",
"PositionOverride",
"RotationOverride",
"ScaleOverride"
};
object[] values = new object[]
{
Transform,
UseLocalValues,
PositionOverride,
RotationOverride,
ScaleOverride
};
return StringExtensions.FormatForToString(titles, values);
}
///
/// Checks to see if the given is equal to .
///
/// The instance to check equality with.
/// Whether the two instances are equal.
public virtual bool Equals(TransformData other)
{
if (other == null || !GetType().Equals(other.GetType()))
{
return false;
}
return Transform == other.Transform &&
UseLocalValues == other.UseLocalValues &&
PositionOverride == other.PositionOverride &&
RotationOverride == other.RotationOverride &&
ScaleOverride == other.ScaleOverride;
}
///
/// Clears the state back to .
///
public virtual void Clear()
{
Transform = null;
UseLocalValues = false;
PositionOverride = null;
RotationOverride = null;
ScaleOverride = null;
}
}
}