Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ControlTrack.cs 2.7KB

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