Hey!
I am making an editor extension and I want to have a box that has a preview of an animated mesh in it.
I got it kind of working, but not completely so I feel really close but can’t quite get it!
This displays the GameObject and I can rotate around it by clicking and dragging. The game object does not animate:
GameObject previewGameObject;
AnimationClip animationClip;
Editor myEditor;
float sampleTime = 0.5f;
void OnInspectorGUI()
{
if(myEditor == null) myEditor = Editor.CreateEditor(previewGameObject);
if(myEditor.target != previewGameObject)
{
Editor.DestroyImmediate(myEditor);
myEditor = Editor.CreateEditor(previewGameObject);
}
AnimationMode.StartAnimationMode();
AnimationMode.BeginSampling();
AnimationMode.SampleAnimationClip(previewGameObject, animationClip, sampleTime);
myEditor.DrawPreview(new Rect(0, 0, 300, 300));
AnimationMode.EndSampling();
AnimationMode.StopAnimationMode();
}
To get the animation to work I have to assign the editor every frame, which is dumb and also stops me from being able to rotate around the object:
GameObject previewGameObject;
AnimationClip animationClip;
Editor myEditor;
float sampleTime = 0.5f;
void OnInspectorGUI()
{
Editor.DestroyImmediate(myEditor);
myEditor = Editor.CreateEditor(previewGameObject);
AnimationMode.StartAnimationMode();
AnimationMode.BeginSampling();
AnimationMode.SampleAnimationClip(previewGameObject, animationClip, sampleTime);
myEditor.DrawPreview(new Rect(0, 0, 300, 300));
AnimationMode.EndSampling();
AnimationMode.StopAnimationMode();
}
I have tried a bunch of things, but nothing works as I want to so far!
I hope someone out there has experience in this because this animation preview is quite important to my extension.
Thanks!