summaryrefslogtreecommitdiff
path: root/Assets/UI_Extension/Scripts/Animation/Tween/Editor/TweenAnimationInspector_Play.cs
blob: e74aa74aafb941d6e464a9d6fbad1749ce247297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEditor;

namespace TweenAnimation
{
    public partial class TweenAnimationInspector : Editor
    {
        PlaybackTimer m_PlaybackTimer;

        float playbackTime
        {
            get
            {
                return m_PlaybackTimer.time;
            }
        }

        // 编辑器下播放动画
        void EditorPlay()
        {
            animation.BeforePlay();
            EditorApplication.update -= Update;
            EditorApplication.update += Update;
        }

        void EditorStop()
        {
            EditorApplication.update -= Update;
        }

        //https://answers.unity.com/questions/1187622/how-to-manually-refresh-inspector-from-editor-code.html
        void RepaintInspector(System.Type t)
        {
            Editor[] ed = (Editor[])Resources.FindObjectsOfTypeAll<Editor>();
            for (int i = 0; i < ed.Length; i++)
            {
                if (ed[i].GetType() == t)
                {
                    ed[i].Repaint();
                    return;
                }
            }
        }

        //https://gamedev.stackexchange.com/questions/125698/how-to-edit-and-persist-serializable-assets-in-the-editor-window
        //https://support.unity.com/hc/en-us/articles/115002294603-How-do-I-make-a-scene-dirty-when-modifying-a-property-via-script-
        //https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html
        //void MarkTargetsDirty()
        //{
        //    if (animation == null)
        //        return;
        //    for (int i = 0; i < animation.modules.Count; ++i)
        //    {
        //        var module = animation.modules[i];
        //        if (module.target)
        //            EditorUtility.SetDirty(module.target);
        //        if (module.targets != null)
        //        {
        //            for (int j = 0; j < module.targets.Length; ++j)
        //            {
        //                EditorUtility.SetDirty(module.targets[j]);
        //            }
        //        }
        //    }
        //}

        //https://forum.unity.com/threads/editor-script-mark-scene-dirty-changed.100340/
        void MarkSceneDirty()
        {
            if(animation)
                EditorUtility.SetDirty(animation);
        }

        void Update()
        {
            animation.UpdateEditor(playbackTime);

            // repaint
            MarkSceneDirty();
            RepaintInspector(typeof(TweenAnimationInspector));

            //MarkSceneDirty();
            //MarkTargetsDirty();
            //UnityEngine.SceneManagement.Scene scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
            //UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
            //UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
            //EditorWindow.GetWindow<SceneView>().Repaint();
            //SceneView.RepaintAll();
            //UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
            //SceneView.lastActiveSceneView.Repaint();
        }

    }
}