Add IAacAssetContainerProvider and AacSimpleAssetContainerProvider
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Animations;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
|
namespace AnimatorAsCode.V1
|
||||||
|
{
|
||||||
|
public interface IAacAssetContainerProvider
|
||||||
|
{
|
||||||
|
void SaveAsPersistenceRequired(Object objectToAdd);
|
||||||
|
void SaveAsRegular(Object objectToAdd);
|
||||||
|
void ClearPreviousAssets();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class AacSimpleAssetContainerProvider : IAacAssetContainerProvider
|
||||||
|
{
|
||||||
|
private readonly AacConfiguration _configuration;
|
||||||
|
|
||||||
|
internal AacSimpleAssetContainerProvider(AacConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveAsPersistenceRequired(Object objectToAdd)
|
||||||
|
{
|
||||||
|
if (_configuration.ContainerMode != AacConfiguration.Container.Never) AssetDatabase.AddObjectToAsset(objectToAdd, _configuration.AssetContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveAsRegular(Object objectToAdd)
|
||||||
|
{
|
||||||
|
if (_configuration.ContainerMode == AacConfiguration.Container.Everything) AssetDatabase.AddObjectToAsset(objectToAdd, _configuration.AssetContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearPreviousAssets()
|
||||||
|
{
|
||||||
|
var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.AssetContainer));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 548220720b88e034288c669042c5d30a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user