ControlTrack.cs
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
namespace UnityEngine.Timeline
{
/// <summary>
/// A Track whose clips control time-related elements on a GameObject.
/// </summary>
[TrackClipType(typeof(ControlPlayableAsset), false)]
[ExcludeFromPreset]
public class ControlTrack : TrackAsset
{
#if UNITY_EDITOR
private static readonly HashSet<PlayableDirector> s_ProcessedDirectors = new HashSet<PlayableDirector>();
/// <inheritdoc/>
public override void GatherProperties(PlayableDirector director, IPropertyCollector driver)
{
if (director == null)
return;
// avoid recursion
if (s_ProcessedDirectors.Contains(director))
return;
s_ProcessedDirectors.Add(director);
var particlesToPreview = new HashSet<ParticleSystem>();
var activationToPreview = new HashSet<GameObject>();
var timeControlToPreview = new HashSet<MonoBehaviour>();
var subDirectorsToPreview = new HashSet<PlayableDirector>();
foreach (var clip in GetClips())
{
var controlPlayableAsset = clip.asset as ControlPlayableAsset;
if (controlPlayableAsset == null)
continue;
var gameObject = controlPlayableAsset.sourceGameObject.Resolve(director);
if (gameObject == null)
continue;
if (controlPlayableAsset.updateParticle)
particlesToPreview.UnionWith(gameObject.GetComponentsInChildren<ParticleSystem>(true));
if (controlPlayableAsset.active)
activationToPreview.Add(gameObject);
if (controlPlayableAsset.updateITimeControl)
timeControlToPreview.UnionWith(ControlPlayableAsset.GetControlableScripts(gameObject));
if (controlPlayableAsset.updateDirector)
subDirectorsToPreview.UnionWith(controlPlayableAsset.GetComponent<PlayableDirector>(gameObject));
}
ControlPlayableAsset.PreviewParticles(driver, particlesToPreview);
ControlPlayableAsset.PreviewActivation(driver, activationToPreview);
ControlPlayableAsset.PreviewTimeControl(driver, director, timeControlToPreview);
ControlPlayableAsset.PreviewDirectors(driver, subDirectorsToPreview);
s_ProcessedDirectors.Remove(director);
particlesToPreview.Clear();
activationToPreview.Clear();
timeControlToPreview.Clear();
subDirectorsToPreview.Clear();
}
#endif
}
}