From 1a559b6251b34ba633b5feaeee500dd64845627e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Mon, 2 Oct 2023 08:48:27 +0200 Subject: [PATCH] Allow any object to be an asset container: - Asset containers are no longer restricted to the AnimatorController class when using the new GenericAssetContainer configuration field - The asset container will not be used if it is not a persistent asset --- .../dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs | 10 +++++++++- .../V1/Editor/AacInternals.cs | 10 +++++----- Packages/dev.hai-vr.animator-as-code.v1/package.json | 2 +- README.md | 1 + 4 files changed, 16 insertions(+), 7 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 e39d0d1..3758058 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 @@ -26,10 +26,18 @@ namespace AnimatorAsCode.V1 public Transform AnimatorRoot; public Transform DefaultValueRoot; public AnimatorController AssetContainer; + public Object GenericAssetContainer; public string AssetKey; public IAacDefaultsProvider DefaultsProvider; public Dictionary AdditionalData; // Nullable + public Object GetPersistentAssetContainer() + { + var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; + if (container != null && EditorUtility.IsPersistent(container)) return container; + return null; + } + public AacConfiguration WithAdditonalData(Type key, object value) { var conf = this; @@ -413,7 +421,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.AssetContainer)); + var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.GetPersistentAssetContainer())); 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/AacInternals.cs b/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacInternals.cs index 7e0aad4..e461c92 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.AssetContainer != null) AssetDatabase.AddObjectToAsset(animatorController, component.AssetContainer); + if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(animatorController, component.GetPersistentAssetContainer()); 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.AssetContainer != null) AssetDatabase.AddObjectToAsset(clip, component.AssetContainer); + if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetPersistentAssetContainer()); 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.AssetContainer != null) AssetDatabase.AddObjectToAsset(clip, component.AssetContainer); + if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetPersistentAssetContainer()); 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.AssetContainer != null) AssetDatabase.AddObjectToAsset(duplicated, component.AssetContainer); + if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.GetPersistentAssetContainer()); 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.AssetContainer != null) AssetDatabase.AddObjectToAsset(avatarMask, component.AssetContainer); + if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.GetPersistentAssetContainer()); return avatarMask; } diff --git a/Packages/dev.hai-vr.animator-as-code.v1/package.json b/Packages/dev.hai-vr.animator-as-code.v1/package.json index 73608c3..efd40bf 100644 --- a/Packages/dev.hai-vr.animator-as-code.v1/package.json +++ b/Packages/dev.hai-vr.animator-as-code.v1/package.json @@ -1,7 +1,7 @@ { "name": "dev.hai-vr.animator-as-code.v1", "displayName": "Animator As Code", - "version": "1.0.9906", + "version": "1.0.9907", "unity": "2019.4", "description": "Animator As Code", "vrchatVersion" : "2022.1.1", diff --git a/README.md b/README.md index 88db465..84ec2b3 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Otherwise if you are **not** using VRChat, install it through the [Releases](htt - [V1 Functions reference](https://docs.hai-vr.dev/docs/products/animator-as-code/functions/base) - [VRChat reference](https://docs.hai-vr.dev/docs/products/animator-as-code/functions/vrchat) - [VRChat (Destructive Workflow) reference](https://docs.hai-vr.dev/docs/products/animator-as-code/functions/vrchat-destructive) +- [Non-Destructive Modular Framework Processor reference](https://docs.hai-vr.dev/docs/products/animator-as-code/functions/ndmf-processor) - [Modular Avatar As Code reference](https://docs.hai-vr.dev/docs/products/animator-as-code/functions/modular-avatar) ## Animator As Code V0