Exemple #1
0
    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
        if (Application.isPlaying)
        {
            PlayableOutput playableOutput = graph.GetOutput(0);

            if (playableOutput.IsOutputValid())
            {
                ScriptPlayable <TimeNotificationBehaviour> scriptPlayable =
                    (ScriptPlayable <TimeNotificationBehaviour>)playableOutput.GetSourcePlayable().GetInput(0);



                TimeNotificationBehaviour timeNotificationBehaviour = scriptPlayable.GetBehaviour();

                var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>();

                m_Receiver = new ReceiverExample();

                playableOutput.AddNotificationReceiver(m_Receiver);

                foreach (var marker in simpleMarkers)
                {
                    scriptPlayable.GetBehaviour().AddNotification(marker.time, marker);
                }
            }
            else
            {
                playableOutput = ScriptPlayableOutput.Create(graph, "NotificationOutput");

                m_Receiver = new ReceiverExample();

                //why also here and in "outputs"
                playableOutput.AddNotificationReceiver(m_Receiver);

                //Create a TimeNotificationBehaviour
                var timeNotificationPlayable = ScriptPlayable <TimeNotificationBehaviour> .Create(graph);

                playableOutput.SetSourcePlayable(graph.GetRootPlayable(0));
                timeNotificationPlayable.GetBehaviour().timeSource = playableOutput.GetSourcePlayable();
                playableOutput.GetSourcePlayable().SetInputCount(playableOutput.GetSourcePlayable().GetInputCount() + 1);
                graph.Connect(timeNotificationPlayable, 0, playableOutput.GetSourcePlayable(), playableOutput.GetSourcePlayable().GetInputCount() - 1);

                var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>();


                foreach (var marker in simpleMarkers)
                {
                    timeNotificationPlayable.GetBehaviour().AddNotification(marker.time, marker);
                }
            }
        }

        return(base.CreateTrackMixer(graph, go, inputCount));
    }
    void Start()
    {
        m_Graph = PlayableGraph.Create("NotificationGraph");
        var output = ScriptPlayableOutput.Create(m_Graph, "NotificationOutput");

        //Create and register a receiver
        m_Receiver = new ReceiverExample();
        output.AddNotificationReceiver(m_Receiver);

        //Push a notification on the output
        output.PushNotification(Playable.Null, new MyNotification());

        m_Graph.Play();
    }
    void Start()
    {
        m_Graph = PlayableGraph.Create("NotificationGraph");
        var output = ScriptPlayableOutput.Create(m_Graph, "NotificationOutput");

        //Create and register a receiver
        m_Receiver = new ReceiverExample();
        output.AddNotificationReceiver(m_Receiver);

        //Create a TimeNotificationBehaviour
        var timeNotificationPlayable = ScriptPlayable <TimeNotificationBehaviour> .Create(m_Graph);

        output.SetSourcePlayable(timeNotificationPlayable);

        //Add a notification on the time notification behaviour
        var notificationBehaviour = timeNotificationPlayable.GetBehaviour();

        notificationBehaviour.AddNotification(2.0, new MyNotification());

        m_Graph.Play();
    }