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(); 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().Repaint(); //SceneView.RepaintAll(); //UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); //SceneView.lastActiveSceneView.Repaint(); } } }