Unity Editor下运行DoTween动画

DOTweenEditorPreview.PrepareTweenForPreview(tar.GetTween());
DOTweenEditorPreview.Start();

以Test脚本为例:

public class UTest : MonoBehaviour
{
    public Tween GetTween()
    {
        var tw= transform.DOMove(Vector3.left, 2);
        tw.onUpdate = () =>
        {
            Debug.Log("afdsaf");
        };
        return tw;
    }
}
[CustomEditor(typeof(UTest))]
public class UTestEditor : Editor
{
    UTest tar;
    void OnEnable()
    {
        tar = target as UTest;
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("NN"))
        {
            DOTweenEditorPreview.PrepareTweenForPreview(tar.GetTween(),false);
            DOTweenEditorPreview.Start();
        }
    }
}

posted on 2024-05-10 11:36  yungs  阅读(120)  评论(0编辑  收藏  举报