u3d DoTween子物体回到原位

2023-08-24 13:42:37 浏览数 (1)

代码语言:javascript复制
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
public class Test : MonoBehaviour {

    public GameObject m_tar;
    Vector3 m_tarPos = Vector3.zero;
    Quaternion m_tarQua = Quaternion.identity;
    Dictionary<Transform, Vector3> m_mapPosReset = new Dictionary<Transform, Vector3>();
    Dictionary<Transform, Quaternion> m_mapQuaReset = new Dictionary<Transform, Quaternion>();
    // Use this for initialization
    void Start () {
        DOTween.Init();
        ChildPosInit();

    }
	
	// Update is called once per frame
	void Update () {
	
	}

    void ChildPosInit()
    {
        m_tarPos = m_tar.transform.position;
        m_tarQua = m_tar.transform.rotation;
        foreach (var render in m_tar.GetComponentsInChildren<Transform>())
        {
            m_mapPosReset[render.transform] = render.transform.position;
            m_mapQuaReset[render.transform] = render.transform.rotation;
        }
    }

    public void ChildPosReset()
    {
        m_tar.transform.DOMove(m_tarPos, 0.5f);
        m_tar.transform.DORotate(m_tarQua.eulerAngles, 0.5f);  
        foreach (var it in m_mapPosReset)
        {
            it.Key.DOMove(it.Value, 0.5f);
        }
        foreach (var it in m_mapQuaReset)
        {
            it.Key.DORotate(it.Value.eulerAngles, 0.5f);
        }

    }
}

0 人点赞