From 21adaa86a67e62209c1f2985a898597af474d295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Wed, 4 Oct 2023 10:59:52 +0200 Subject: [PATCH] Changed AssetContainer type to Object, add ContainerMode --- .../V1/Editor/Aac.cs | 25 +++++++++++-------- .../V1/Editor/AacFlAnimations.cs | 18 ++++++------- .../V1/Editor/AacInternals.cs | 10 ++++---- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs index 08ec533..47f982e 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs @@ -25,8 +25,8 @@ namespace AnimatorAsCode.V1 // public VRCAvatarDescriptor AvatarDescriptor; public Transform AnimatorRoot; public Transform DefaultValueRoot; - public AnimatorController AssetContainer; - public Object GenericAssetContainer; + public Object AssetContainer; + public Container ContainerMode; public string AssetKey; public IAacDefaultsProvider DefaultsProvider; @@ -52,18 +52,21 @@ namespace AnimatorAsCode.V1 return false; } - internal Object GetPersistentAssetContainer() + internal Object AsPersistentContainerRequired() { - var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; - if (container != null && EditorUtility.IsPersistent(container)) return container; - return null; + return ContainerMode != Container.Never ? AssetContainer : null; } - internal Object GetAssetContainer() + internal Object AsRegularContainer() { - var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; - if (container != null) return container; - return null; + return ContainerMode == Container.Everything ? AssetContainer : null; + } + + public enum Container + { + Everything, + OnlyWhenPersistenceRequired, + Never } } @@ -429,7 +432,7 @@ namespace AnimatorAsCode.V1 /// Removes all assets from the asset container matching the specified asset key. public void ClearPreviousAssets() { - var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.GetPersistentAssetContainer())); + var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.AsPersistentContainerRequired())); foreach (var subAsset in allSubAssets) { if (subAsset.name.StartsWith($"zAutogenerated__{_configuration.AssetKey}__") diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs index a195262..b38746e 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacFlAnimations.cs @@ -56,6 +56,15 @@ namespace AnimatorAsCode.V1 return this; } + public AacFlClip Toggling(GameObject gameObject, bool value) + { + var binding = AacInternals.Binding(_component, typeof(GameObject), gameObject.transform, "m_IsActive"); + + AacInternals.SetCurve(Clip, binding, AacInternals.OneFrame(value ? 1f : 0f)); + + return this; + } + public AacFlClip BlendShape(SkinnedMeshRenderer renderer, string blendShapeName, float value) { var binding = AacInternals.Binding(_component, typeof(SkinnedMeshRenderer), renderer.transform, $"blendShape.{blendShapeName}"); @@ -157,15 +166,6 @@ namespace AnimatorAsCode.V1 return this; } - public AacFlClip Toggling(GameObject gameObject, bool value) - { - var binding = AacInternals.Binding(_component, typeof(GameObject), gameObject.transform, "m_IsActive"); - - AacInternals.SetCurve(Clip, binding, AacInternals.OneFrame(value ? 1f : 0f)); - - return this; - } - public AacFlClip TogglingComponent(Component[] componentsWithNulls, bool value) { var defensiveComponents = componentsWithNulls.Where(o => o != null); // Allow users to remove an item in the middle of the array diff --git a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs index 28ebc1d..c4be818 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs +++ b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs @@ -16,7 +16,7 @@ namespace AnimatorAsCode.V1 var animatorController = new AnimatorController(); animatorController.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict animatorController.hideFlags = HideFlags.None; - if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(animatorController, component.GetPersistentAssetContainer()); + if (component.AsPersistentContainerRequired() != null) AssetDatabase.AddObjectToAsset(animatorController, component.AsPersistentContainerRequired()); return animatorController; } @@ -29,7 +29,7 @@ namespace AnimatorAsCode.V1 { clip.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict clip.hideFlags = HideFlags.None; - if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetAssetContainer()); + if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); return clip; } @@ -38,7 +38,7 @@ namespace AnimatorAsCode.V1 var clip = new BlendTree(); clip.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict clip.hideFlags = HideFlags.None; - if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetAssetContainer()); + if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); return clip; } @@ -47,7 +47,7 @@ namespace AnimatorAsCode.V1 var duplicated = (T)Object.Instantiate(assetToDuplicate); duplicated.name = "zAutogenerated__" + component.AssetKey + "__" + assetToDuplicate.name + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict duplicated.hideFlags = HideFlags.None; - if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.GetAssetContainer()); + if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.AsRegularContainer()); return duplicated; } @@ -56,7 +56,7 @@ namespace AnimatorAsCode.V1 var avatarMask = new AvatarMask(); avatarMask.name = "zAutogenerated__" + component.AssetKey + "_" + fullLayerName + "__AvatarMask"; avatarMask.hideFlags = HideFlags.None; - if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.GetAssetContainer()); + if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.AsRegularContainer()); return avatarMask; }