using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; namespace UnityEngine.Timeline { /// /// A Track whose clips control time-related elements on a GameObject. /// [TrackClipType(typeof(ControlPlayableAsset), false)] [ExcludeFromPreset] [TimelineHelpURL(typeof(ControlTrack))] public class ControlTrack : TrackAsset { #if UNITY_EDITOR private static readonly HashSet s_ProcessedDirectors = new HashSet(); /// 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(); var activationToPreview = new HashSet(); var timeControlToPreview = new HashSet(); var subDirectorsToPreview = new HashSet(); 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(true)); if (controlPlayableAsset.active) activationToPreview.Add(gameObject); if (controlPlayableAsset.updateITimeControl) timeControlToPreview.UnionWith(ControlPlayableAsset.GetControlableScripts(gameObject)); if (controlPlayableAsset.updateDirector) subDirectorsToPreview.UnionWith(controlPlayableAsset.GetComponent(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 } }