-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVRCFTGenerator_Template.cs
114 lines (104 loc) · 5.01 KB
/
VRCFTGenerator_Template.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#if UNITY_EDITOR
using System;
using VRCFTGenerator.AnimatorAsCode.V0;
using UnityEditor;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using AnimatorController = UnityEditor.Animations.AnimatorController;
namespace Raz.VRCFTGenerator
{
public static class AACTemplate
{
public static TemplateGenOptions Options()
{
return TemplateGenOptions.Defaults();
}
public struct TemplateGenOptions
{
public static TemplateGenOptions Defaults()
{
return new TemplateGenOptions()
{
WriteDefaults = false
};
}
public TemplateGenOptions WriteDefaultsOff()
{
WriteDefaults = false;
return this;
}
public TemplateGenOptions WriteDefaultsOn()
{
WriteDefaults = true;
return this;
}
public bool WriteDefaults;
}
public static void InspectorTemplate(Editor editor, SerializedObject serializedObj, string propName, Action createFn, Action removeFnOptional = null)
{
var prop = serializedObj.FindProperty(propName);
if (prop.stringValue.Trim() == "")
{
prop.stringValue = GUID.Generate().ToString();
serializedObj.ApplyModifiedProperties();
}
editor.DrawDefaultInspector();
if (GUILayout.Button("Create"))
{
createFn.Invoke();
}
if (removeFnOptional != null && GUILayout.Button("Remove"))
{
removeFnOptional.Invoke();
}
}
/// <summary>
/// Creates an AAC base with default options (write defaults OFF). This function is provided as an example on how to invoke AAC internals.
/// </summary>
/// <param name="systemName">Prefix for layer names</param>
/// <param name="avatar">Playable layers of this avatar to modify</param>
/// <param name="assetContainer">Animation assets will be generated as sub-assets of that asset container</param>
/// <param name="assetKey">Animation assets will be generated with this name in order to clean up previously generated assets of the same system</param>
/// <param name="options">Some options, such as whether Write Defaults is ON or OFF</param>
/// <returns>The AAC base.</returns>
public static AacFlBase AnimatorAsCode(string systemName, VRCAvatarDescriptor avatar, AnimatorController assetContainer, string assetKey)
{
return AnimatorAsCode(systemName, avatar, assetContainer, assetKey, TemplateGenOptions.Defaults());
}
/// <summary>
/// Creates an AAC base. This function is provided as an example on how to invoke AAC internals.
/// </summary>
/// <param name="systemName">Prefix for layer names</param>
/// <param name="avatar">Playable layers of this avatar to modify</param>
/// <param name="assetContainer">Animation assets will be generated as sub-assets of that asset container</param>
/// <param name="assetKey">Animation assets will be generated with this name in order to clean up previously generated assets of the same system</param>
/// <param name="options">Some options, such as whether Write Defaults is ON or OFF</param>
/// <returns>The AAC base.</returns>
public static AacFlBase AnimatorAsCode(string systemName, VRCAvatarDescriptor avatar, AnimatorController assetContainer, string assetKey, TemplateGenOptions options)
{
var aac = AacV0.Create(new AacConfiguration
{
SystemName = systemName,
// In the examples, we consider the avatar to be also the animator root.
AvatarDescriptor = avatar,
// You can set the animator root to be different than the avatar descriptor,
// if you want to apply an animator to a different avatar without redefining
// all of the game object references which were relative to the original avatar.
AnimatorRoot = avatar.transform,
// DefaultValueRoot is currently unused in AAC. It is added here preemptively
// in order to define an avatar root to sample default values from.
// The intent is to allow animators to be created with Write Defaults OFF,
// but mimicking the behaviour of Write Defaults ON by automatically
// sampling the default value from the scene relative to the transform
// defined in DefaultValueRoot.
DefaultValueRoot = avatar.transform,
AssetContainer = assetContainer,
AssetKey = assetKey,
DefaultsProvider = new AacDefaultsProvider(writeDefaults: options.WriteDefaults)
});
aac.ClearPreviousAssets();
return aac;
}
}
}
#endif