Add Animator As Code
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using AnimatorAsCode.V0;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using AnimatorController = UnityEditor.Animations.AnimatorController;
|
||||
|
||||
namespace AnimatorAsCodeFramework.Examples
|
||||
{
|
||||
public static class AacExample
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6c6740568e64846b6b18720f7315ca4
|
||||
timeCreated: 1645751901
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbcd8ae9108f27f44aacfe48a78785d4
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,92 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5874b9d3baa9584c88aae7527592af0
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 1
|
||||
seamlessCubemap: 1
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 2
|
||||
aniso: 0
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 2
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 100
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3aab8cb479c1da147b4fec0a8fe34236
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: AacExampleMaterial
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.698
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 0.48689637, g: 0.11609437, b: 0.037962936, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3542dfecd687604fb8d0b0e6a5a6318
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -340790334, guid: 67cc4cb7839cd3741b63733d5adf0442, type: 3}
|
||||
m_Name: AacExampleMenu
|
||||
m_EditorClassIdentifier:
|
||||
controls:
|
||||
- name: Item
|
||||
icon: {fileID: 0}
|
||||
type: 102
|
||||
parameter:
|
||||
name: EnableItem
|
||||
value: 1
|
||||
style: 0
|
||||
subMenu: {fileID: 0}
|
||||
subParameters: []
|
||||
labels: []
|
||||
- name: Accesories
|
||||
icon: {fileID: 0}
|
||||
type: 102
|
||||
parameter:
|
||||
name: EnableAccessories
|
||||
value: 1
|
||||
style: 0
|
||||
subMenu: {fileID: 0}
|
||||
subParameters: []
|
||||
labels: []
|
||||
- name: Thing
|
||||
icon: {fileID: 0}
|
||||
type: 102
|
||||
parameter:
|
||||
name: AccessoryThing
|
||||
value: 1
|
||||
style: 0
|
||||
subMenu: {fileID: 0}
|
||||
subParameters: []
|
||||
labels: []
|
||||
- name: Wedge Amount
|
||||
icon: {fileID: 0}
|
||||
type: 203
|
||||
parameter:
|
||||
name:
|
||||
value: 1
|
||||
style: 0
|
||||
subMenu: {fileID: 0}
|
||||
subParameters:
|
||||
- name: WedgeAmount
|
||||
labels: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cde459092e0783540b3837521d750413
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -1506855854, guid: 67cc4cb7839cd3741b63733d5adf0442, type: 3}
|
||||
m_Name: AacExampleParams
|
||||
m_EditorClassIdentifier:
|
||||
parameters:
|
||||
- name: EnableItem
|
||||
valueType: 2
|
||||
saved: 1
|
||||
defaultValue: 0
|
||||
- name: EnableAccessories
|
||||
valueType: 2
|
||||
saved: 1
|
||||
defaultValue: 0
|
||||
- name: AccessoryThing
|
||||
valueType: 2
|
||||
saved: 1
|
||||
defaultValue: 0
|
||||
- name: WedgeAmount
|
||||
valueType: 1
|
||||
saved: 1
|
||||
defaultValue: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 599b4ef18dd7b2b41ae63050dc68cf49
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,102 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63527d990aefbfd4889bdd854f8389e2
|
||||
ModelImporter:
|
||||
serializedVersion: 19301
|
||||
internalIDToNameTable: []
|
||||
externalObjects:
|
||||
- first:
|
||||
type: UnityEngine:Material
|
||||
assembly: UnityEngine.CoreModule
|
||||
name: Material.001
|
||||
second: {fileID: 2100000, guid: c3542dfecd687604fb8d0b0e6a5a6318, type: 2}
|
||||
materials:
|
||||
materialImportMode: 1
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
materialLocation: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleCurves: 1
|
||||
optimizeGameObjects: 0
|
||||
motionNodeName:
|
||||
rigImportErrors:
|
||||
rigImportWarnings:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
importAnimatedCustomProperties: 0
|
||||
importConstraints: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
extraUserProperties: []
|
||||
clipAnimations: []
|
||||
isReadable: 0
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 1
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
useSRGBMaterialColor: 1
|
||||
sortHierarchyByName: 1
|
||||
importVisibility: 1
|
||||
importBlendShapes: 1
|
||||
importCameras: 1
|
||||
importLights: 1
|
||||
fileIdsGeneration: 2
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
preserveHierarchy: 0
|
||||
skinWeightsMode: 0
|
||||
maxBonesPerVertex: 4
|
||||
minBoneWeight: 0.001
|
||||
meshOptimizationFlags: -1
|
||||
indexFormat: 0
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 3
|
||||
normalCalculationMode: 4
|
||||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||
blendShapeNormalImportMode: 1
|
||||
normalSmoothingSource: 0
|
||||
referencedClips: []
|
||||
importAnimation: 1
|
||||
humanDescription:
|
||||
serializedVersion: 3
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
globalScale: 1
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
hasExtraRoot: 0
|
||||
skeletonHasParents: 1
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
autoGenerateAvatarMappingIfUnspecified: 1
|
||||
animationType: 2
|
||||
humanoidOversampling: 1
|
||||
avatarSetup: 0
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 152a25406238928428795a65c5473ecb
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
|
||||
namespace AnimatorAsCodeFramework.Examples
|
||||
{
|
||||
public class GenExample0_ToggleGo : MonoBehaviour
|
||||
{
|
||||
public VRCAvatarDescriptor avatar;
|
||||
public AnimatorController assetContainer;
|
||||
public string assetKey;
|
||||
public GameObject item;
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(GenExample0_ToggleGo), true)]
|
||||
public class GenExample0_ToggleGoEditor : Editor
|
||||
{
|
||||
private const string SystemName = "Example 0";
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
AacExample.InspectorTemplate(this, serializedObject, "assetKey", Create, Remove);
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
var my = (GenExample0_ToggleGo) target;
|
||||
// The avatar is used here:
|
||||
// - to find the FX playable layer animator, where a new layer will be created.
|
||||
// - to resolve the relative animation path to the item.
|
||||
// The generated animation files are stored in the asset container.
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey, AacExample.Options().WriteDefaultsOff());
|
||||
|
||||
// Create a layer in the FX animator.
|
||||
// Additional layers can be created in the FX animator (see later in the manual).
|
||||
var fx = aac.CreateMainFxLayer();
|
||||
|
||||
// The first created state is the default one connected to the "Entry" node.
|
||||
// States are automatically placed on the grid (see later in the manual).
|
||||
var hidden = fx.NewState("Hidden")
|
||||
// Animation assets are generated as sub-assets of the asset container.
|
||||
// The animation path to my.skinnedMesh is relative to my.avatar
|
||||
.WithAnimation(aac.NewClip().Toggling(my.item, false));
|
||||
var shown = fx.NewState("Shown")
|
||||
.WithAnimation(aac.NewClip().Toggling(my.item, true));
|
||||
|
||||
// Creates a Bool parameter in the FX layer.
|
||||
// Parameters are added to the Animator if a parameter with the same name
|
||||
// does not exist yet.
|
||||
var itemParam = fx.BoolParameter("EnableItem");
|
||||
|
||||
// Transitions are created with a set of default values
|
||||
// That can be changed in the Generator settings (see later in the manual).
|
||||
hidden.TransitionsTo(shown).When(itemParam.IsTrue());
|
||||
shown.TransitionsTo(hidden).When(itemParam.IsFalse());
|
||||
}
|
||||
|
||||
private void Remove()
|
||||
{
|
||||
var my = (GenExample0_ToggleGo) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
aac.RemoveAllMainLayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be5bb2bad8914be8a6a86373d48e4574
|
||||
timeCreated: 1645746140
|
||||
@@ -0,0 +1,76 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
|
||||
namespace AnimatorAsCodeFramework.Examples
|
||||
{
|
||||
public class GenExample1_ToggleSmr : MonoBehaviour
|
||||
{
|
||||
public VRCAvatarDescriptor avatar;
|
||||
public AnimatorController assetContainer;
|
||||
public string assetKey;
|
||||
public SkinnedMeshRenderer skinnedMesh;
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(GenExample1_ToggleSmr), true)]
|
||||
public class GenExample1_ToggleSmrEditor : Editor
|
||||
{
|
||||
private const string SystemName = "Example 1";
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
AacExample.InspectorTemplate(this, serializedObject, "assetKey", Create, Remove);
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
var my = (GenExample1_ToggleSmr) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
var fx = aac.CreateMainFxLayer();
|
||||
var hidden = fx.NewState("Hidden")
|
||||
// The runtime type of my.skinnedMesh is used within the animation.
|
||||
// In this case, the "SkinnedMeshRenderer" component is disabled.
|
||||
.WithAnimation(aac.NewClip().TogglingComponent(my.skinnedMesh, false));
|
||||
var shown = fx.NewState("Shown")
|
||||
.WithAnimation(aac.NewClip().TogglingComponent(my.skinnedMesh, true));
|
||||
|
||||
// This creates two Bool parameters in the animator.
|
||||
// The resulting value can be used in conditions.
|
||||
var accessoriesParams = fx.BoolParameters("EnableAccessories", "AccessoryThing");
|
||||
|
||||
// The following line creates one transition.
|
||||
// The conditions are "EnableAccessories is true" and "AccessoryThing is true"
|
||||
hidden.TransitionsTo(shown).When(accessoriesParams.AreTrue());
|
||||
|
||||
// The following line creates two transitions:
|
||||
// - The first transition is "EnableAccessories is false"
|
||||
// - The second transition is "AccessoryThing is false"
|
||||
shown.TransitionsTo(hidden).When(accessoriesParams.IsAnyFalse());
|
||||
|
||||
if (false)
|
||||
{
|
||||
// Alternatively, you can use the long way:
|
||||
var enableAccessoriesParam = fx.BoolParameter("EnableAccessories");
|
||||
var thingParam = fx.BoolParameter("ThingParam");
|
||||
|
||||
hidden.TransitionsTo(shown).When(enableAccessoriesParam.IsTrue()).And(thingParam.IsTrue());
|
||||
|
||||
// - The first transition:
|
||||
shown.TransitionsTo(hidden).When(enableAccessoriesParam.IsFalse())
|
||||
// - The second transition:
|
||||
.Or().When(thingParam.IsFalse());
|
||||
}
|
||||
}
|
||||
|
||||
private void Remove()
|
||||
{
|
||||
var my = (GenExample1_ToggleSmr) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
aac.RemoveAllMainLayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea8b0c32e2e54e4883f5b113609cb670
|
||||
timeCreated: 1645744548
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
|
||||
namespace AnimatorAsCodeFramework.Examples
|
||||
{
|
||||
public class GenExample2_Animate : MonoBehaviour
|
||||
{
|
||||
public VRCAvatarDescriptor avatar;
|
||||
public AnimatorController assetContainer;
|
||||
public string assetKey;
|
||||
public SkinnedMeshRenderer wedgeMesh;
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(GenExample2_Animate), true)]
|
||||
public class GenExample1_BlushEditor : Editor
|
||||
{
|
||||
private const string SystemName = "Example 2";
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
AacExample.InspectorTemplate(this, serializedObject, "assetKey", Create, Remove);
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
var my = (GenExample2_Animate) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
var fx = aac.CreateMainFxLayer();
|
||||
|
||||
fx.NewState("Motion")
|
||||
.WithAnimation(aac.NewClip().Animating(clip =>
|
||||
{
|
||||
clip.Animates(my.wedgeMesh, "blendShape.Wedge").WithFrameCountUnit(keyframes =>
|
||||
keyframes.Easing(0, 100f).Easing(28, 0).Easing(29, 0).Easing(30, 0).Easing(31, 0).Easing(32, 0).Easing(60, 100f)
|
||||
);
|
||||
clip.Animates(my.wedgeMesh, "material._Metallic").WithFrameCountUnit(keyframes =>
|
||||
keyframes.Constant(0, 1f).Constant(28, 0).Constant(60, 0)
|
||||
);
|
||||
}))
|
||||
.MotionTime(fx.FloatParameter("WedgeAmount"));
|
||||
}
|
||||
|
||||
private void Remove()
|
||||
{
|
||||
var my = (GenExample2_Animate) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
aac.RemoveAllMainLayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b09d955c545f45428d3c5cfb9b214117
|
||||
timeCreated: 1645746969
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.Linq;
|
||||
using AnimatorAsCode.V0;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
|
||||
namespace AnimatorAsCodeFramework.Examples
|
||||
{
|
||||
public class GenExample3_Gesturing : MonoBehaviour
|
||||
{
|
||||
public VRCAvatarDescriptor avatar;
|
||||
public AnimatorController assetContainer;
|
||||
public string assetKey;
|
||||
public SkinnedMeshRenderer iconMesh;
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(GenExample3_Gesturing), true)]
|
||||
public class GenExample3_GesturingEditor : Editor
|
||||
{
|
||||
private const string SystemName = "Example 3";
|
||||
|
||||
private GenExample3_Gesturing my;
|
||||
private AacFlBase aac;
|
||||
|
||||
private const string MaxBlendshape = "blendShape.KPIN_A_Major_Max";
|
||||
private const string MinBlendshape = "blendShape.KPIN_A_Major_Min";
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
AacExample.InspectorTemplate(this, serializedObject, "assetKey", Create, Remove);
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
my = (GenExample3_Gesturing) target;
|
||||
aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
CreateMainLayer();
|
||||
CreateSupportingLayer();
|
||||
}
|
||||
|
||||
private void Remove()
|
||||
{
|
||||
var my = (GenExample3_Gesturing) target;
|
||||
var aac = AacExample.AnimatorAsCode(SystemName, my.avatar, my.assetContainer, my.assetKey);
|
||||
|
||||
aac.RemoveAllMainLayers();
|
||||
aac.RemoveAllSupportingLayers("Detection");
|
||||
}
|
||||
|
||||
private void CreateMainLayer()
|
||||
{
|
||||
var layer = aac.CreateMainFxLayer();
|
||||
|
||||
var dirtyCheckParameter = layer.BoolParameter("AAC_INTERNAL_GesturingIcon_DirtyCheck");
|
||||
|
||||
// ### Create states
|
||||
var lackOfChangeDetected = layer.NewState("Animate To NoChange")
|
||||
.WithAnimation(IconAppears());
|
||||
|
||||
// By default, states have an animation that animates a dummy object for 1 frame.
|
||||
var noChange = layer.NewState("NoChange", 1, 0).RightOf();
|
||||
|
||||
var changeDetected = layer.NewState("Animate To Changing").Under()
|
||||
.WithAnimation(IconDisappears());
|
||||
|
||||
// This creates a clip that animates a dummy object for 1.5f seconds.
|
||||
var changing = layer.NewState("Changing", 0, 1).LeftOf()
|
||||
.WithAnimation(aac.DummyClipLasting(1.5f, AacFlUnit.Seconds));
|
||||
|
||||
// When this state is entered, the parameter is driven to the value of false.
|
||||
var stillChanging = layer.NewState("Still Changing", 0, 2).Under()
|
||||
.Drives(dirtyCheckParameter, false);
|
||||
|
||||
// ------
|
||||
|
||||
// ### Create transitions
|
||||
lackOfChangeDetected.TransitionsTo(changeDetected).AfterAnimationIsAtLeastAtPercent(0.7f).When(dirtyCheckParameter.IsTrue());
|
||||
|
||||
// The transition duration is 30% of the animation duration.
|
||||
lackOfChangeDetected.TransitionsTo(noChange).AfterAnimationFinishes().WithTransitionDurationPercent(0.3f);
|
||||
|
||||
noChange.TransitionsTo(changeDetected).When(dirtyCheckParameter.IsTrue());
|
||||
|
||||
// By using AfterAnimationFinishes, the transition will trigger after the animation
|
||||
// for the icon appearing finishes.
|
||||
changeDetected.TransitionsTo(changing).AfterAnimationFinishes();
|
||||
|
||||
changing.TransitionsTo(stillChanging).When(dirtyCheckParameter.IsTrue());
|
||||
// By using AfterAnimationFinishes, the transition will trigger after 1.5 seconds,
|
||||
// which is the length of the animation in Changing.
|
||||
changing.TransitionsTo(lackOfChangeDetected).AfterAnimationFinishes();
|
||||
|
||||
// The transition will immediately happen upon entering, by using Exit time set to 0.
|
||||
stillChanging.AutomaticallyMovesTo(changing);
|
||||
}
|
||||
|
||||
private void CreateSupportingLayer()
|
||||
{
|
||||
// Create an additional FX layer.
|
||||
var layer = aac.CreateSupportingFxLayer("Detection");
|
||||
var reevaluating = layer.NewState("Reevaluating", -1, 0);
|
||||
|
||||
foreach (var left in Enumerable.Range(0, 8))
|
||||
{
|
||||
foreach (var right in Enumerable.Range(0, 8))
|
||||
{
|
||||
var state = layer.NewState($"Gesture {left} {right}", left, right)
|
||||
// When this state is entered, the parameter is driven to the value of true.
|
||||
.Drives(layer.BoolParameter("AAC_INTERNAL_GesturingIcon_DirtyCheck"), true);
|
||||
|
||||
reevaluating.TransitionsTo(state)
|
||||
// Use ".Av3" to access VRChat standard parameters.
|
||||
// Accessing these parameters will create the corresponding parameter in the animator.
|
||||
.When(layer.Av3().GestureLeft.IsEqualTo(left))
|
||||
.And(layer.Av3().GestureRight.IsEqualTo(right));
|
||||
state.TransitionsTo(reevaluating)
|
||||
.When(layer.Av3().GestureLeft.IsNotEqualTo(left))
|
||||
.Or()
|
||||
.When(layer.Av3().GestureRight.IsNotEqualTo(right));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AacFlClip IconAppears()
|
||||
{
|
||||
return aac.NewClip().Animating(clip =>
|
||||
{
|
||||
clip.Animates(my.iconMesh, MaxBlendshape)
|
||||
.WithFrameCountUnit(keyframes => keyframes.Easing(0, 1.001f).Easing(10, 0f));
|
||||
clip.Animates(my.iconMesh, MinBlendshape)
|
||||
.WithOneFrame(0f);
|
||||
});
|
||||
}
|
||||
|
||||
private AacFlClip IconDisappears()
|
||||
{
|
||||
return aac.NewClip().Animating(clip =>
|
||||
{
|
||||
clip.Animates(my.iconMesh, MaxBlendshape)
|
||||
.WithFrameCountUnit(keyframes => keyframes.Easing(0, 0f).Easing(30, 0f));
|
||||
clip.Animates(my.iconMesh, MinBlendshape)
|
||||
.WithFrameCountUnit(keyframes => keyframes.Easing(0, 0f).Easing(10, 100f));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bd105e311c440ca03e6f6c46f830fc
|
||||
timeCreated: 1645755767
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4c992e0dc0e4f74a36f386346991dbc
|
||||
timeCreated: 1645800049
|
||||
Reference in New Issue
Block a user