Firstborn/Library/PackageCache/com.unity.timeline@1.7.1/Editor/Animation/AnimationPlayableAssetEdito...
Schaken-Mods b486678290 Library -Artifacts
Library -Artifacts
2023-03-28 12:24:16 -05:00

66 lines
2.8 KiB
C#

using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
[CustomTimelineEditor(typeof(AnimationPlayableAsset)), UsedImplicitly]
class AnimationPlayableAssetEditor : ClipEditor
{
public static readonly string k_NoClipAssignedError = L10n.Tr("No animation clip assigned");
public static readonly string k_LegacyClipError = L10n.Tr("Legacy animation clips are not supported");
static readonly string k_MotionCurveError = L10n.Tr("You are using motion curves without applyRootMotion enabled on the Animator. The root transform will not be animated");
static readonly string k_RootCurveError = L10n.Tr("You are using root curves without applyRootMotion enabled on the Animator. The root transform will not be animated");
/// <inheritdoc/>
public override ClipDrawOptions GetClipOptions(TimelineClip clip)
{
var clipOptions = base.GetClipOptions(clip);
var asset = clip.asset as AnimationPlayableAsset;
if (asset != null)
clipOptions.errorText = GetErrorText(asset, clip.GetParentTrack() as AnimationTrack, clipOptions.errorText);
if (clip.recordable)
clipOptions.highlightColor = DirectorStyles.Instance.customSkin.colorAnimationRecorded;
return clipOptions;
}
/// <inheritdoc />
public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
{
var asset = clip.asset as AnimationPlayableAsset;
if (asset != null && asset.clip != null && asset.clip.legacy)
{
asset.clip = null;
Debug.LogError("Legacy Animation Clips are not supported");
}
}
string GetErrorText(AnimationPlayableAsset animationAsset, AnimationTrack track, string defaultError)
{
if (animationAsset.clip == null)
return k_NoClipAssignedError;
if (animationAsset.clip.legacy)
return k_LegacyClipError;
if (animationAsset.clip.hasMotionCurves || animationAsset.clip.hasRootCurves)
{
if (track != null && track.trackOffset == TrackOffset.Auto)
{
var animator = track.GetBinding(TimelineEditor.inspectedDirector);
if (animator != null && !animator.applyRootMotion && !animationAsset.clip.hasGenericRootTransform)
{
if (animationAsset.clip.hasMotionCurves)
return k_MotionCurveError;
return k_RootCurveError;
}
}
}
return defaultError;
}
}
}