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