generated from raccoon/vrchat-project-template
Added scripts stub
This commit is contained in:
8
Assets/hwm.meta
Normal file
8
Assets/hwm.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e7e8d532e5be04d8e0b6c5b471c696
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/hwm/Editor.meta
Normal file
8
Assets/hwm/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05a6291265cab1c4bb434e058ec404fb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/hwm/Editor/HWMSetupEditor.cs
Normal file
21
Assets/hwm/Editor/HWMSetupEditor.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RiggingTools.FacialAnimation
|
||||
{
|
||||
[CustomEditor(typeof(HWMSetup))]
|
||||
public class HWMSetupEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
var script = (HWMSetup)target;
|
||||
|
||||
if (GUILayout.Button("Generate Anim Controller"))
|
||||
{
|
||||
script.GenerateAnimationController();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/hwm/Editor/HWMSetupEditor.cs.meta
Normal file
11
Assets/hwm/Editor/HWMSetupEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 909adcc30362c8d44a3fef10070fe4ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/hwm/Scripts.meta
Normal file
8
Assets/hwm/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f658d84ba6af6849bf405c7218a9214
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/hwm/Scripts/HWMSetup.cs
Normal file
58
Assets/hwm/Scripts/HWMSetup.cs
Normal 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
|
||||
}
|
||||
}
|
||||
11
Assets/hwm/Scripts/HWMSetup.cs.meta
Normal file
11
Assets/hwm/Scripts/HWMSetup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9baa4cf3adb15d041a7f046e68b4fe53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user