Added scripts stub

This commit is contained in:
raccoon
2025-08-25 14:56:30 +05:00
parent 7014f3cfb0
commit a04f2ef173
7 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Animations;
#endif
namespace RiggingTools.FacialAnimation
{
[RequireComponent(typeof(SkinnedMeshRenderer))]
public class HWMSetup : MonoBehaviour
{
[Header("Animation Settings")]
public float moveDistance = 1f;
public float duration = 2f;
#if UNITY_EDITOR
public void GenerateAnimationController()
{
var skinnedMesh = GetComponent<SkinnedMeshRenderer>();
if (skinnedMesh == null)
{
Debug.LogWarning($"Skinned Mesh Renderer not found on {gameObject.name}");
return;
}
string objName = gameObject.name;
var clip = new AnimationClip();
clip.name = objName + "_MoveUpDown";
Keyframe[] keys = {
new Keyframe(0, 0),
new Keyframe(duration / 2f, moveDistance),
new Keyframe(duration, 0)
};
var curve = new AnimationCurve(keys);
clip.SetCurve("", typeof(Transform), "localPosition.y", curve);
// Make loop
var clipSettings = AnimationUtility.GetAnimationClipSettings(clip);
clipSettings.loopTime = true;
AnimationUtility.SetAnimationClipSettings(clip, clipSettings);
AssetDatabase.CreateAsset(clip, $"Assets/{objName}_MoveUpDown.anim");
var controller = AnimatorController.CreateAnimatorControllerAtPath($"Assets/{objName}_Controller.controller");
var state = controller.layers[0].stateMachine.AddState("MoveUpDown");
state.motion = clip;
controller.layers[0].stateMachine.defaultState = state;
AssetDatabase.SaveAssets();
Debug.Log($"Generated animator setup for {objName}");
}
#endif
}
}