Unity控制把執行

外掛之家發表於2020-12-23

視訊:https://www.bilibili.com/video/BV1oa4y1L7Qe
連結:https://pan.baidu.com/s/1ahrxle5I72FvywC1iv2_MQ
提取碼:ekbn
複製這段內容後開啟百度網盤手機App,操作更方便哦–來自百度網盤超級會員V3的分享
在這裡插入圖片描述

using UnityEngine;

namespace RTEditor
{
    /// <summary>
    /// This class can be used to store a snapshot of an object's transform data.
    /// </summary>
    public class ObjectTransformSnapshot
    {
        #region Private Variables
        /// <summary>
        /// This is the game object to which the snapshot data applies.
        /// </summary>
        private GameObject _gameObject;

        /// <summary>
        /// This is the snapshot of the object's absolute position.
        /// </summary>
        private Vector3 _absolutePosition;

        /// <summary>
        /// This is the snapshot of the object's absolute rotation.
        /// </summary>
        private Quaternion _absoluteRotation;

        /// <summary>
        /// This is the snapshot of the object's absolute scale.
        /// </summary>
        private Vector3 _absoluteScale;
        #endregion

        #region Public Methods
        /// <summary>
        /// Takes a snapshot of the specified object's transform data.
        /// </summary>
        public void TakeSnapshot(GameObject gameObject)
        {
            // Store the game object reference
            _gameObject = gameObject;

            // Take the snapshot
            Transform objectTransform = gameObject.transform;
            _absolutePosition = objectTransform.position;
            _absoluteRotation = objectTransform.rotation;
            _absoluteScale = objectTransform.lossyScale;
        }

        /// <summary>
        /// Applies the snapshot data to the last game object whose snapshot was taken. This
        /// method has no effect if no snapshot was taken before calling this method.
        /// </summary>
        public void ApplySnapshot()
        {
            // Is there any snapshot data available?
            if(_gameObject != null)
            {
                // Apply the snapshot to the game object's transform
                Transform objectTransform = _gameObject.transform;
                objectTransform.position = _absolutePosition;
                objectTransform.rotation = _absoluteRotation;
                _gameObject.SetAbsoluteScale(_absoluteScale);
            }
        }
        #endregion
    }
}

相關文章