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

namespace Framework.DataHandling
{
    /// <summary>
    /// The RigidbodyData class is used to serialize the Rigidbody class as 
    /// Unity classes cannot be serialized.
    /// </summary>
    [Serializable]
    public class RigidbodyData
    {
        public Vector3Data velocity;
        public Vector3Data angularVelocity;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="RigidbodyData"/> class.
        /// </summary>
        /// <param name="transform">The rigidbody.</param>
        public RigidbodyData(Rigidbody rigidbody)
        {
            this.velocity = new Vector3Data(rigidbody.velocity);
            this.angularVelocity = new Vector3Data(rigidbody.angularVelocity);
        }

        /// <summary>
        /// Applies the stored values of this RigidbodyData object to a given
        /// rigidbody.
        /// </summary>
        /// <param name="rigidbody">The rigidbody.</param>
        public void ToRigidbody(Rigidbody rigidbody)
        {
            rigidbody.velocity = this.velocity.ToVector3();
            rigidbody.angularVelocity = this.angularVelocity.ToVector3();
        }
    }
}
