Hi,
I’m new to Timeline so this might be basic but I can’t find a way to get the notification timings to be relative to the Timeline when I fire them from a playableBehaviour
PlayableAsset
public class RhythmBeatAsset : PlayableAsset
{
protected RhythmBeatBehaviour m_RhythmBeatBehaviour;
public override Playable CreatePlayable (PlayableGraph graph, GameObject owner)
{
var playable = ScriptPlayable<RhythmBeatBehaviour>.Create(graph);
m_RhythmBeatBehaviour = playable.GetBehaviour();
return playable;
}
}
PlayableBehaviour
public class RhythmBeatBehaviour : TimeNotificationBehaviour
{
protected double m_PreviousTime;
protected float m_Bpm;
protected RhythmBeatReceiver m_RhythmBeatReceiver;
public override void OnGraphStart(Playable playable)
{
m_PreviousTime = 0;
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
m_RhythmBeatReceiver = playerData as RhythmBeatReceiver;
if (m_RhythmBeatReceiver != null) {
m_Bpm = m_RhythmBeatReceiver.Bpm;
}
if (m_PreviousTime < playable.GetTime())
{
info.output.PushNotification(playable, new MyNotification());
m_PreviousTime += 60f / m_Bpm;
}
}
}
Notification Receiver
public class RhythmBeatReceiver : MonoBehaviour, INotificationReceiver
{
[SerializeField] protected float m_Bpm = 120;
[SerializeField] protected bool m_DebugLogTimings;
public float Bpm => m_Bpm;
public void OnNotify(Playable origin, INotification notification, object context)
{
if (notification != null && m_DebugLogTimings)
{
double time = origin.IsValid() ? origin.GetTime() : 0.0;
Debug.LogFormat("Rhythm Beat Received notification of type {0} at time {1}", notification.GetType(), time);
}
}
}
When I place Notification markers on the track the receiver logs the timings in relation to the full timeline they. When I place a clip the timings of the notification are relative to that clip. That’s when I call “origin.GetTime()”. From what I understand the Playbale “origin” is a clip within the timeline, and markers have a clip of their own for all markers in a track.
So I’m wondering how I’m supposed to get the relative timings? Something like clipStartTime+origin.GetTime() would do the trick but I’m not sure where I can get the clipStartTime from the receiver.
The other thing I wanted to know is how do I push a notification on start and on stop of a clip?
I have a ton of other questions but I’ll ask them at another time