// Inside the Rigidbody2DExtension class /// <summary> /// Saving the state :Rigidbody2DState state rigidbody2D.GetState(); /// </summary> /// <param name="rigidbody2D"></param> /// <returns></returns> public static Rigidbody2DState GetState(this Rigidbody2D rigidbody2D) { Rigidbody2DState state = new Rigidbody2DState(); state.velocity = rigidbody2D.velocity; state.angularVelocity = rigidbody2D.angularVelocity; return(state); }
/// <summary> /// Save current rigidbody state for later reuse /// </summary> /// <param name="rigidbody2D"></param> /// <param name="state"></param> /// <returns></returns> public static Rigidbody2DState GetState(this Rigidbody2D rigidbody2D, Rigidbody2DState state = null) { if (state == null) { state = new Rigidbody2DState(); } state.velocity = rigidbody2D.velocity; state.angularVelocity = rigidbody2D.angularVelocity; return(state); }