A game about forced loneliness, made by TACStudios
1using JetBrains.Annotations;
2using UnityEngine;
3using UnityEngine.Playables;
4using UnityEngine.Timeline;
5
6namespace UnityEditor.Timeline
7{
8 [CustomTimelineEditor(typeof(AnimationPlayableAsset)), UsedImplicitly]
9 class AnimationPlayableAssetEditor : ClipEditor
10 {
11 public static readonly string k_NoClipAssignedError = L10n.Tr("No animation clip assigned");
12 public static readonly string k_LegacyClipError = L10n.Tr("Legacy animation clips are not supported");
13 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");
14 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");
15
16 /// <inheritdoc/>
17 public override ClipDrawOptions GetClipOptions(TimelineClip clip)
18 {
19 var clipOptions = base.GetClipOptions(clip);
20 var asset = clip.asset as AnimationPlayableAsset;
21
22 if (asset != null)
23 clipOptions.errorText = GetErrorText(asset, clip.GetParentTrack() as AnimationTrack, clipOptions.errorText);
24
25 if (clip.recordable)
26 clipOptions.highlightColor = DirectorStyles.Instance.customSkin.colorAnimationRecorded;
27
28 return clipOptions;
29 }
30
31 /// <inheritdoc />
32 public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
33 {
34 var asset = clip.asset as AnimationPlayableAsset;
35 if (asset != null && asset.clip != null && asset.clip.legacy)
36 {
37 asset.clip = null;
38 Debug.LogError("Legacy Animation Clips are not supported");
39 }
40 }
41
42 string GetErrorText(AnimationPlayableAsset animationAsset, AnimationTrack track, string defaultError)
43 {
44 if (animationAsset.clip == null)
45 return k_NoClipAssignedError;
46 if (animationAsset.clip.legacy)
47 return k_LegacyClipError;
48 if (animationAsset.clip.hasMotionCurves || animationAsset.clip.hasRootCurves)
49 {
50 if (track != null && track.trackOffset == TrackOffset.Auto)
51 {
52 var animator = track.GetBinding(TimelineEditor.inspectedDirector);
53 if (animator != null && !animator.applyRootMotion && !animationAsset.clip.hasGenericRootTransform)
54 {
55 if (animationAsset.clip.hasMotionCurves)
56 return k_MotionCurveError;
57 return k_RootCurveError;
58 }
59 }
60 }
61
62 return defaultError;
63 }
64 }
65}