diff --git a/Framework/Editor/V1/Aac.cs b/Framework/Editor/V1/Aac.cs index aa3359a..e2a4f7b 100644 --- a/Framework/Editor/V1/Aac.cs +++ b/Framework/Editor/V1/Aac.cs @@ -4,6 +4,7 @@ using System.Linq; using UnityEditor; using UnityEditor.Animations; using UnityEngine; +using Object = UnityEngine.Object; // ReSharper disable once CheckNamespace namespace AnimatorAsCode.V1 @@ -339,6 +340,12 @@ namespace AnimatorAsCode.V1 .WithUnit(unit, keyframes => keyframes.Constant(0, 0f).Constant(numberOf, 0f))); } + /// Duplicate a new asset into the container and return it. For example, use this to create modified material variants. This asset will be removed the same way as other generated assets. + public T DuplicateAsset(T assetToDuplicate) where T : Object + { + return AacInternals.DuplicateAssetIntoContainer(_configuration, assetToDuplicate); + } + // For backwards compatibility, generates an animation with 2 keyframes that are at a distance of 1 / 60 of 1 frame, // that is 1 / 3600 seconds. // This was due to DummyClipLasting returning a clip with unit conversion applied twice, diff --git a/Framework/Editor/V1/AacInternals.cs b/Framework/Editor/V1/AacInternals.cs index 42b9073..f8ff642 100644 --- a/Framework/Editor/V1/AacInternals.cs +++ b/Framework/Editor/V1/AacInternals.cs @@ -3,6 +3,7 @@ using System.Reflection; using UnityEditor; using UnityEditor.Animations; using UnityEngine; +using Object = UnityEngine.Object; using Random = UnityEngine.Random; // ReSharper disable once CheckNamespace @@ -41,6 +42,15 @@ namespace AnimatorAsCode.V1 return clip; } + internal static T DuplicateAssetIntoContainer(AacConfiguration component, T assetToDuplicate) where T : Object + { + 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; + AssetDatabase.AddObjectToAsset(duplicated, component.AssetContainer); + return duplicated; + } + internal static EditorCurveBinding Binding(AacConfiguration component, Type type, Transform transform, string propertyName) { return new EditorCurveBinding