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 19c9c54..80549ab 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 @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; @@ -46,6 +46,9 @@ namespace AnimatorAsCode.V1 public string AssetKey; /// An object that will provide default values. When in doubt, use `new AacDefaultsProvider(...)` public IAacDefaultsProvider DefaultsProvider; + /// An object that will provide abstraction for asset container object. + /// AssetContainer field value will be used if left null. + public IAacAssetContainerProvider AssetContainerProvider; private Dictionary _additionalData; // Nullable @@ -74,14 +77,13 @@ namespace AnimatorAsCode.V1 return false; } - internal Object AsPersistentContainerRequired() + internal IAacAssetContainerProvider ContainerProvider { - return ContainerMode != Container.Never ? AssetContainer : null; - } - - internal Object AsRegularContainer() - { - return ContainerMode == Container.Everything ? AssetContainer : null; + get + { + AssetContainerProvider ??= new AacSimpleAssetContainerProvider(this); + return AssetContainerProvider; + } } /// Values that define how created assets should be added to the AssetContainer. @@ -618,20 +620,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.AsPersistentContainerRequired())); - foreach (var subAsset in allSubAssets) - { - if ( - ( - subAsset.name.StartsWith($"{AacInternals.AutoGeneratedPrefix}{_configuration.AssetKey}__") - || subAsset.name.StartsWith($"{AacInternals.AutoGeneratedLegacyPrefix}{_configuration.AssetKey}__") - ) - - && (subAsset is AnimationClip || subAsset is BlendTree || subAsset is AvatarMask)) - { - AssetDatabase.RemoveObjectFromAsset(subAsset); - } - } + _configuration.ContainerProvider.ClearPreviousAssets(); } /// If you are not creating an animator, this returns an object from which you can obtain animator parameter objects. You should use this class if you are creating BlendTree assets without any animator controllers to back it. Otherwise, it is strongly recommended to obtain animator parameter objects directly from the layer objects instead of using NoAnimator(), as the use of NoAnimator() will not result in the registration of any parameters inside the animator controller. 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 45b7b12..6e5a01d 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 @@ -21,7 +21,7 @@ namespace AnimatorAsCode.V1 var animatorController = new AnimatorController(); animatorController.name = Internal_GenerateAnimationName(component, suffix); // FIXME animation name conflict animatorController.hideFlags = HideFlags.None; - if (component.AsPersistentContainerRequired() != null) AssetDatabase.AddObjectToAsset(animatorController, component.AsPersistentContainerRequired()); + component.ContainerProvider.SaveAsPersistenceRequired(animatorController); return animatorController; } @@ -34,7 +34,7 @@ namespace AnimatorAsCode.V1 { clip.name = Internal_GenerateAnimationName(component, suffix); clip.hideFlags = HideFlags.None; - if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); + component.ContainerProvider.SaveAsRegular(clip); return clip; } @@ -43,7 +43,7 @@ namespace AnimatorAsCode.V1 var clip = new BlendTree(); clip.name = Internal_GenerateAnimationName(component, suffix); clip.hideFlags = HideFlags.None; - if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer()); + component.ContainerProvider.SaveAsRegular(clip); return clip; } @@ -52,7 +52,7 @@ namespace AnimatorAsCode.V1 var duplicated = (T)Object.Instantiate(assetToDuplicate); duplicated.name = Internal_GenerateAnimationName(component, assetToDuplicate.name); duplicated.hideFlags = HideFlags.None; - if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.AsRegularContainer()); + component.ContainerProvider.SaveAsRegular(duplicated); return duplicated; } @@ -66,7 +66,7 @@ namespace AnimatorAsCode.V1 var avatarMask = new AvatarMask(); avatarMask.name = AutoGeneratedPrefix + component.AssetKey + "_" + fullLayerName + "__AvatarMask"; avatarMask.hideFlags = HideFlags.None; - if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.AsRegularContainer()); + component.ContainerProvider.SaveAsRegular(avatarMask); return avatarMask; }