Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

NotificationUtilities.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.Playables;
  4. namespace UnityEngine.Timeline
  5. {
  6. static class NotificationUtilities
  7. {
  8. public static ScriptPlayable<TimeNotificationBehaviour> CreateNotificationsPlayable(PlayableGraph graph, IEnumerable<IMarker> markers, PlayableDirector director)
  9. {
  10. return CreateNotificationsPlayable(graph, markers, null, director);
  11. }
  12. public static ScriptPlayable<TimeNotificationBehaviour> CreateNotificationsPlayable(PlayableGraph graph, IEnumerable<IMarker> markers, TimelineAsset timelineAsset)
  13. {
  14. return CreateNotificationsPlayable(graph, markers, timelineAsset, null);
  15. }
  16. static ScriptPlayable<TimeNotificationBehaviour> CreateNotificationsPlayable(PlayableGraph graph, IEnumerable<IMarker> markers, IPlayableAsset asset, PlayableDirector director)
  17. {
  18. ScriptPlayable<TimeNotificationBehaviour> notificationPlayable = ScriptPlayable<TimeNotificationBehaviour>.Null;
  19. DirectorWrapMode extrapolationMode = director != null ? director.extrapolationMode : DirectorWrapMode.None;
  20. bool didCalculateDuration = false;
  21. var duration = 0d;
  22. foreach (IMarker e in markers)
  23. {
  24. var notification = e as INotification;
  25. if (notification == null)
  26. continue;
  27. if (!didCalculateDuration)
  28. {
  29. duration = director != null ? director.playableAsset.duration : asset.duration;
  30. didCalculateDuration = true;
  31. }
  32. if (notificationPlayable.Equals(ScriptPlayable<TimeNotificationBehaviour>.Null))
  33. {
  34. notificationPlayable = TimeNotificationBehaviour.Create(graph,
  35. duration, extrapolationMode);
  36. }
  37. var time = (DiscreteTime)e.time;
  38. var tlDuration = (DiscreteTime)duration;
  39. if (time >= tlDuration && time <= tlDuration.OneTickAfter() && tlDuration != 0)
  40. time = tlDuration.OneTickBefore();
  41. if (e is INotificationOptionProvider notificationOptionProvider)
  42. notificationPlayable.GetBehaviour().AddNotification((double)time, notification, notificationOptionProvider.flags);
  43. else
  44. notificationPlayable.GetBehaviour().AddNotification((double)time, notification);
  45. }
  46. return notificationPlayable;
  47. }
  48. public static bool TrackTypeSupportsNotifications(Type type)
  49. {
  50. var binding = (TrackBindingTypeAttribute)Attribute.GetCustomAttribute(type, typeof(TrackBindingTypeAttribute));
  51. return binding != null &&
  52. (typeof(Component).IsAssignableFrom(binding.type) ||
  53. typeof(GameObject).IsAssignableFrom(binding.type));
  54. }
  55. }
  56. }