Add Animator As Code

This commit is contained in:
Haï~
2022-02-27 20:16:34 +01:00
parent 16199f7614
commit 58c51926a7
47 changed files with 18297 additions and 0 deletions
@@ -0,0 +1,52 @@
using System.Linq;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using UnityEditor;
using UnityEditor.Animations;
namespace AnimatorAsCodeFramework.Examples
{
public class GenExampleManual_PlacingStates : MonoBehaviour
{
public VRCAvatarDescriptor avatar;
public AnimatorController assetContainer;
public string assetKey;
}
[CustomEditor(typeof(GenExampleManual_PlacingStates), true)]
public class GenExampleManual_PlacingStatesEditor : Editor
{
private const string SystemName = "Example Manual - Placing States";
public override void OnInspectorGUI()
{
AacExample.InspectorTemplate(this, serializedObject, "assetKey", Create, Remove);
}
private void Create()
{
var my = (GenExampleManual_PlacingStates) target;
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
var fx = aac.CreateMainFxLayer();
var init = fx.NewState("Init"); // This is the first state. By default it is at (0, 0)
var a = fx.NewState("A"); // This will be placed under Init.
var b = fx.NewState("B"); // This will be placed under A.
var c = fx.NewState("C").RightOf(a); // This will be placed right of A.
var d = fx.NewState("D"); // This will be placed under C.
var alternate = fx.NewState("Alternate").Over(c); // This will be placed over C.
// This will be placed next to Alternate: 2 blocks over, and 1 to the right.
var reset = fx.NewState("Reset").Shift(alternate, 1, -2);
}
private void Remove()
{
var my = (GenExampleManual_PlacingStates) target;
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
aac.RemoveAllMainLayers();
}
}
}