Hey all.
I have a custom editor for creating movesets. I’m trying to play an animation clip on the target of a preview window, but it only every refreshes when I click on the preview. I’ve tried every method possible for rereshing the preview, but nothing so far has worked.
The basic of what I’ve got in my Editor Window.
private void OnGUI()
{
// Draw some things, omitted for shortness...
EditorGUILayout.BeginVertical("box");
DrawPreviewWindow();
EditorGUILayout.EndVertical();
}
private void DrawPreviewWindow()
{
gameObject = (GameObject)EditorGUILayout.ObjectField(gameObject, typeof(GameObject), true);
if (gameObject != null)
{
if (gameObjectEditor == null)
gameObjectEditor = Editor.CreateEditor(gameObject);
if (clip != null)
{
scrubTime = EditorGUILayout.Slider(scrubTime, 0f, clip.length);
}
GUIStyle bgColor = new GUIStyle();
gameObjectEditor.OnPreviewGUI(GUILayoutUtility.GetRect(256, 256), bgColor);
gameObjectEditor.ReloadPreviewInstances();
}
}
private void Update()
{
if (gameObject == null) { return; }
if (clip != null)
{
if (!AnimationMode.InAnimationMode())
{
AnimationMode.StartAnimationMode();
}
AnimationMode.BeginSampling();
AnimationMode.SampleAnimationClip(gameObjectEditor.target as GameObject, clip, scrubTime);
AnimationMode.EndSampling();
}
}
I’ve been scratching my head all day. Any help would be muchly appreciated!