Unity tool like Mixamo, preview the project animation library
I’m in the process of developing a handy tool for viewing the animation library in a project. The tool should work in the editor, it does not care whether the game is running or not. In general, some results achieved. Now I’m looking at why animations are not played. Probably someone who knows more optimal ways to create a similar tool will be glad to advice.
using UnityEditor;
using UnityEngine;
public class AnimationsLibraryShortTest : EditorWindow
{
[MenuItem("Examples/Animations library short test")]
public static void ShowWindow()
{
GetWindow<AnimationsLibraryShortTest>(false, "Animations library short test", true);
}
private AnimationClip Anim;
private GameObject Go;
private UnityEditor.Editor ModelEditor;
private float m_Time;
private void OnEnable()
{
Anim = AssetDatabase.LoadAssetAtPath<AnimationClip>(AssetDatabase.GUIDToAssetPath("860b3ec4a6e3b6c4ba8082b7ddb44a03"));
Go = AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath("dce51f72c11cfd94c992cb5f31920d6c"));
AnimationMode.StartAnimationMode();
}
private void OnDisable()
{
AnimationMode.StopAnimationMode();
}
private void OnGUI()
{
if (ModelEditor == null)
ModelEditor = UnityEditor.Editor.CreateEditor(Go);
float startTime = 0.0f;
float stopTime = Anim.length;
m_Time = EditorGUILayout.Slider("Выполнение", m_Time, 0, stopTime);
// AnimationMode.BeginSampling();
// obj.animation.SampleAnimation(obj.m_ModelEditor.target as GameObject, m_Time);
// AnimationMode.SampleAnimationClip(ModelEditor.target as GameObject, Anim, m_Time);
ModelEditor.OnPreviewGUI(GUILayoutUtility.GetRect(400, 400), EditorStyles.whiteLabel);
ModelEditor.Repaint();
// AnimationMode.EndSampling();
}
private void Update()
{
if (Anim == null)
return;
if (ModelEditor.target == null)
return;
if (!EditorApplication.isPlaying && AnimationMode.InAnimationMode())
{
// Animate the GameObject
AnimationMode.BeginSampling();
AnimationMode.SampleAnimationClip(ModelEditor.target as GameObject, Anim, m_Time);
AnimationMode.EndSampling();
// SceneView.RepaintAll();
}
}
}