A game about forced loneliness, made by TACStudios
1using System.Collections.Generic;
2using System.Linq;
3using System.Text;
4using UnityEditorInternal;
5using UnityEngine;
6
7namespace UnityEditor.Timeline
8{
9 interface IPropertyKeyDataSource
10 {
11 float[] GetKeys(); // Get the keys
12 Dictionary<float, string> GetDescriptions(); // Caches for descriptions
13 }
14
15 abstract class BasePropertyKeyDataSource : IPropertyKeyDataSource
16 {
17 static readonly StringBuilder k_StringBuilder = new StringBuilder();
18
19 protected abstract AnimationClip animationClip { get; }
20
21 public virtual float[] GetKeys()
22 {
23 if (animationClip == null)
24 return null;
25
26 var info = AnimationClipCurveCache.Instance.GetCurveInfo(animationClip);
27 return info.keyTimes.Select(TransformKeyTime).ToArray();
28 }
29
30 public virtual Dictionary<float, string> GetDescriptions()
31 {
32 var map = new Dictionary<float, string>();
33 var info = AnimationClipCurveCache.Instance.GetCurveInfo(animationClip);
34 var processed = new HashSet<string>();
35
36 foreach (var b in info.bindings)
37 {
38 var groupID = b.GetGroupID();
39 if (processed.Contains(groupID))
40 continue;
41
42 var group = info.GetGroupBinding(groupID);
43 var prefix = AnimationWindowUtility.GetNicePropertyGroupDisplayName(b.type, b.propertyName);
44
45 foreach (var t in info.keyTimes)
46 {
47 k_StringBuilder.Length = 0;
48
49 var key = TransformKeyTime(t);
50 if (map.ContainsKey(key))
51 k_StringBuilder.Append(map[key])
52 .Append('\n');
53
54 k_StringBuilder.Append(prefix)
55 .Append(" : ")
56 .Append(group.GetDescription(key));
57
58 map[key] = k_StringBuilder.ToString();
59 }
60 processed.Add(groupID);
61 }
62
63 return map;
64 }
65
66 protected virtual float TransformKeyTime(float keyTime)
67 {
68 return keyTime;
69 }
70 }
71}