Skip to content

Commit

Permalink
Use AacSimpleAssetContainerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
kb10uy authored and hai-vr committed Nov 29, 2024
1 parent 061b539 commit e445ba8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
33 changes: 11 additions & 22 deletions Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/Aac.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
Expand Down Expand Up @@ -46,6 +46,9 @@ public struct AacConfiguration
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<Type, object> _additionalData; // Nullable

Expand Down Expand Up @@ -74,14 +77,13 @@ public bool TryGetAdditionalData<T>(out T value) where T : class
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.
Expand Down Expand Up @@ -618,20 +620,7 @@ private AacFlClip CreateEmptyClip()
/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static AnimatorController NewAnimatorController(AacConfiguration compon
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;
}

Expand All @@ -34,7 +34,7 @@ internal static AnimationClip RegisterClip(AacConfiguration component, string su
{
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;
}

Expand All @@ -43,7 +43,7 @@ internal static BlendTree NewBlendTreeAsRaw(AacConfiguration component, string s
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;
}

Expand All @@ -52,7 +52,7 @@ internal static T DuplicateAssetIntoContainer<T>(AacConfiguration component, T a
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;
}

Expand All @@ -66,7 +66,7 @@ internal static AvatarMask NewAvatarMask(AacConfiguration component, string full
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;
}

Expand Down

0 comments on commit e445ba8

Please sign in to comment.