diff --git a/Framework/Editor/V1/AacFlAnimations.cs b/Framework/Editor/V1/AacFlAnimations.cs index a17a17b..4f22138 100644 --- a/Framework/Editor/V1/AacFlAnimations.cs +++ b/Framework/Editor/V1/AacFlAnimations.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; +using Object = UnityEngine.Object; // ReSharper disable once CheckNamespace namespace AnimatorAsCode.V1 @@ -232,6 +233,12 @@ namespace AnimatorAsCode.V1 return new AacFlSettingCurveColor(Clip, new[] {binding}, true); } + public AacFlSettingCurveObjectReference AnimatesObjectReference(Component anyComponent, string property) + { + var binding = Internal_BindingFromComponent(anyComponent, property); + return new AacFlSettingCurveObjectReference(Clip, new[] {binding}); + } + public EditorCurveBinding BindingFromComponent(Component anyComponent, string propertyName) { return Internal_BindingFromComponent(anyComponent, propertyName); @@ -306,6 +313,30 @@ namespace AnimatorAsCode.V1 } } + public class AacFlSettingCurveObjectReference + { + private readonly AnimationClip _clip; + private readonly EditorCurveBinding[] _bindings; + + public AacFlSettingCurveObjectReference(AnimationClip clip, EditorCurveBinding[] bindings) + { + _clip = clip; + _bindings = bindings; + } + + public void WithOneFrame(Object objectReference) + { + foreach (var binding in _bindings) + { + AnimationUtility.SetObjectReferenceCurve(_clip, binding, new[] + { + new ObjectReferenceKeyframe { time = 0f, value = objectReference }, + new ObjectReferenceKeyframe { time = 1/60f, value = objectReference } + }); + } + } + } + public class AacFlSettingCurveColor { private readonly AnimationClip _clip; diff --git a/Framework/Editor/V1/AacInternals.cs b/Framework/Editor/V1/AacInternals.cs index ed47fde..dfd1f2e 100644 --- a/Framework/Editor/V1/AacInternals.cs +++ b/Framework/Editor/V1/AacInternals.cs @@ -73,6 +73,12 @@ namespace AnimatorAsCode.V1 internal static string ResolveRelativePath(Transform avatar, Transform item) { + if (avatar == item) + { + // TODO: Is this correct?? + return ""; + } + if (item.parent != avatar && item.parent != null) { return ResolveRelativePath(avatar, item.parent) + "/" + item.name;