using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Framework.DataStructures
{
    /// <summary>
    /// The TransformData class is used to serialize the Transform class as 
    /// Unity classes cannot be serialized.
    /// </summary>
    [Serializable]
    public class TransformData
    {
        public Vector3Data position;
        public QuaternionData rotation;
        public Vector3Data scale;

        /// <summary>
        /// Initializes a new instance of the <see cref="TransformData"/> class.
        /// </summary>
        /// <param name="transform">The transform.</param>
        public TransformData(Transform transform)
        {
            this.position = new Vector3Data(transform.position);
            this.rotation = new QuaternionData(transform.rotation);
            this.scale = new Vector3Data(transform.localScale);
        }

        /// <summary>
        /// Applies the stored values of this TransformData object to a given
        /// transform.
        /// </summary>
        /// <param name="transform">The transform.</param>
        public void ToTransform(Transform transform)
        {
            transform.position = this.position.ToVector3();
            transform.rotation = this.rotation.ToQuaternion();
            transform.localScale = this.scale.ToVector3();
        }
    }
}
