Changed AssetContainer type to Object, add ContainerMode

This commit is contained in:
Haï~
2023-10-04 10:59:52 +02:00
parent a43516f45e
commit 21adaa86a6
3 changed files with 28 additions and 25 deletions
@@ -25,8 +25,8 @@ namespace AnimatorAsCode.V1
// public VRCAvatarDescriptor AvatarDescriptor; // public VRCAvatarDescriptor AvatarDescriptor;
public Transform AnimatorRoot; public Transform AnimatorRoot;
public Transform DefaultValueRoot; public Transform DefaultValueRoot;
public AnimatorController AssetContainer; public Object AssetContainer;
public Object GenericAssetContainer; public Container ContainerMode;
public string AssetKey; public string AssetKey;
public IAacDefaultsProvider DefaultsProvider; public IAacDefaultsProvider DefaultsProvider;
@@ -52,18 +52,21 @@ namespace AnimatorAsCode.V1
return false; return false;
} }
internal Object GetPersistentAssetContainer() internal Object AsPersistentContainerRequired()
{ {
var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; return ContainerMode != Container.Never ? AssetContainer : null;
if (container != null && EditorUtility.IsPersistent(container)) return container;
return null;
} }
internal Object GetAssetContainer() internal Object AsRegularContainer()
{ {
var container = AssetContainer != null ? AssetContainer : GenericAssetContainer; return ContainerMode == Container.Everything ? AssetContainer : null;
if (container != null) return container; }
return 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. /// Removes all assets from the asset container matching the specified asset key.
public void ClearPreviousAssets() public void ClearPreviousAssets()
{ {
var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.GetPersistentAssetContainer())); var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(_configuration.AsPersistentContainerRequired()));
foreach (var subAsset in allSubAssets) foreach (var subAsset in allSubAssets)
{ {
if (subAsset.name.StartsWith($"zAutogenerated__{_configuration.AssetKey}__") if (subAsset.name.StartsWith($"zAutogenerated__{_configuration.AssetKey}__")
@@ -56,6 +56,15 @@ namespace AnimatorAsCode.V1
return this; 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) public AacFlClip BlendShape(SkinnedMeshRenderer renderer, string blendShapeName, float value)
{ {
var binding = AacInternals.Binding(_component, typeof(SkinnedMeshRenderer), renderer.transform, $"blendShape.{blendShapeName}"); var binding = AacInternals.Binding(_component, typeof(SkinnedMeshRenderer), renderer.transform, $"blendShape.{blendShapeName}");
@@ -157,15 +166,6 @@ namespace AnimatorAsCode.V1
return this; 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) 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 var defensiveComponents = componentsWithNulls.Where(o => o != null); // Allow users to remove an item in the middle of the array
@@ -16,7 +16,7 @@ namespace AnimatorAsCode.V1
var animatorController = new AnimatorController(); var animatorController = new AnimatorController();
animatorController.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict animatorController.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict
animatorController.hideFlags = HideFlags.None; animatorController.hideFlags = HideFlags.None;
if (component.GetPersistentAssetContainer() != null) AssetDatabase.AddObjectToAsset(animatorController, component.GetPersistentAssetContainer()); if (component.AsPersistentContainerRequired() != null) AssetDatabase.AddObjectToAsset(animatorController, component.AsPersistentContainerRequired());
return animatorController; 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.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict
clip.hideFlags = HideFlags.None; clip.hideFlags = HideFlags.None;
if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetAssetContainer()); if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer());
return clip; return clip;
} }
@@ -38,7 +38,7 @@ namespace AnimatorAsCode.V1
var clip = new BlendTree(); var clip = new BlendTree();
clip.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict clip.name = "zAutogenerated__" + component.AssetKey + "__" + suffix + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict
clip.hideFlags = HideFlags.None; clip.hideFlags = HideFlags.None;
if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.GetAssetContainer()); if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(clip, component.AsRegularContainer());
return clip; return clip;
} }
@@ -47,7 +47,7 @@ namespace AnimatorAsCode.V1
var duplicated = (T)Object.Instantiate(assetToDuplicate); var duplicated = (T)Object.Instantiate(assetToDuplicate);
duplicated.name = "zAutogenerated__" + component.AssetKey + "__" + assetToDuplicate.name + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict duplicated.name = "zAutogenerated__" + component.AssetKey + "__" + assetToDuplicate.name + "_" + Random.Range(0, Int32.MaxValue); // FIXME animation name conflict
duplicated.hideFlags = HideFlags.None; duplicated.hideFlags = HideFlags.None;
if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.GetAssetContainer()); if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(duplicated, component.AsRegularContainer());
return duplicated; return duplicated;
} }
@@ -56,7 +56,7 @@ namespace AnimatorAsCode.V1
var avatarMask = new AvatarMask(); var avatarMask = new AvatarMask();
avatarMask.name = "zAutogenerated__" + component.AssetKey + "_" + fullLayerName + "__AvatarMask"; avatarMask.name = "zAutogenerated__" + component.AssetKey + "_" + fullLayerName + "__AvatarMask";
avatarMask.hideFlags = HideFlags.None; avatarMask.hideFlags = HideFlags.None;
if (component.GetAssetContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.GetAssetContainer()); if (component.AsRegularContainer() != null) AssetDatabase.AddObjectToAsset(avatarMask, component.AsRegularContainer());
return avatarMask; return avatarMask;
} }