private void Start()
    {
        playableGraph = PlayableGraph.Create();

        // Create the outputs.

        var animationOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

        var audioOutput = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());

        // Create the playables.

        var animationClipPlayable = AnimationClipPlayable.Create(playableGraph, animationClip);

        var audioClipPlayable = AudioClipPlayable.Create(playableGraph, audioClip, true);

        // Connect the playables to an output

        animationOutput.SetSourcePlayable(animationClipPlayable);

        audioOutput.SetSourcePlayable(audioClipPlayable);

        // Plays the Graph.

        playableGraph.Play();
    }
Exemple #2
0
    private void PlayGraph()
    {
        playableGraph = PlayableGraph.Create();
        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        AudioPlayableOutput audioOutput = AudioPlayableOutput.Create(playableGraph, "AudioOut", audioManager.musicSource);

        AudioClipPlayable clipPlayable = AudioClipPlayable.Create(playableGraph, audioManager.songs[audioManager.selectedSongIndex], false);

        audioOutput.SetSourcePlayable(clipPlayable);

        AudioMixerPlayable mixer = AudioMixerPlayable.Create(playableGraph);


        //playableDirector.SetGenericBinding();



        //audiTrack = playableGraph.Co
        //audiTrack.CreateClip(audioManager.songs[audioManager.selectedSongIndex]);
        //audiTrack.CreatePlayable(playableGraph, this.gameObject);
        playableGraph.Play();
        playableGraphIsSet = true;
        // BindTimelineTracks();
        //playableDirector.Play();
    }
Exemple #3
0
        public static SoundManager Create(GameObject go)
        {
            var audioSource = go.GetComponent <AudioSource>() ?? go.AddComponent <AudioSource>();
            var graph       = PlayableGraph.Create("AudioPlayable");
            var audioOut    = AudioPlayableOutput.Create(graph, "Audio", audioSource);

            var playable = ScriptPlayable <SoundManager> .Create(graph);

            audioOut.SetSourcePlayable(playable, 0);

            var trackCount = (int)EAudioChannel.Count;
            var mixer      = AudioMixerPlayable.Create(graph, trackCount);

            playable.AddInput(mixer, 0, 1);
            for (var i = 0; i < trackCount; ++i)
            {
                mixer.AddInput(AudioMixerPlayable.Create(graph), i, 1);
            }

            var behaviour = playable.GetBehaviour();

            behaviour.mGraph = graph;
            behaviour.mMixer = mixer;
            Instance         = behaviour;
            return(behaviour);
        }
        /// <summary>
        /// Use this for initialization
        /// </summary>
        private void Awake()
        {
            // Create playable graph.
            playableGraph = PlayableGraph.Create();

            // Create playable output node.
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            // Create animation mixer playerable node.
            int animationClipsLength = animationClips == null ? 0 : animationClips.Length;

            animationMixer = AnimationMixerPlayable.Create(playableGraph, animationClipsLength);

            // Connect the mixer to an output.
            playableOutput.SetSourcePlayable(animationMixer);

            // Create clip playable node for all animations.
            for (int i = 0; i < animationClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[i]);

                playableGraph.Connect(clipPlayable, 0, animationMixer, i);
                animationMixer.SetInputWeight(i, 0.0f);
            }

            // Create audio output node.
            var audioOutput = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());

            // Create audio mixer playerable node.
            int audioClipsLength = audioClips == null ? 0 : audioClips.Length;

            audioMixer = AudioMixerPlayable.Create(playableGraph, audioClipsLength);

            // Connect the mixer to an output.
            audioOutput.SetSourcePlayable(audioMixer);

            // Create clip playable node for all audios.
            for (int i = 0; i < audioClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AudioClipPlayable.Create(playableGraph, audioClips[i], false);

                playableGraph.Connect(clipPlayable, 0, audioMixer, i);
                audioMixer.SetInputWeight(i, 0.0f);
            }

            // Init the animation component list.
            currentAnimationList = new List <AnimationComponent>();

            // Plays the playable graph.
            playableGraph.Play();

            // Register graph visual client to show debug messages.
            GraphVisualizerClient.Show(playableGraph, "Animation Engine Graph");
        }
Exemple #5
0
        private void Start()
        {
            playableGraph = PlayableGraph.Create();
            var animationOutPut       = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());
            var audioOutput           = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());
            var animationClipPlayable = AnimationClipPlayable.Create(playableGraph, animationClip);
            var audioClipPlayable     = AudioClipPlayable.Create(playableGraph, audioClip, true);

            animationOutPut.SetSourcePlayable(animationClipPlayable);
            audioOutput.SetSourcePlayable(audioClipPlayable);
            playableGraph.Play();
        }
Exemple #6
0
    void Start()
    {
        mPlayableGraph = PlayableGraph.Create("AudioManager");
        mAudioOutput   = AudioPlayableOutput.Create(mPlayableGraph, "Audio", GetComponent <AudioSource>());

        mAudioClipPlayable01 = AudioClipPlayable.Create(mPlayableGraph, AudioClips[0], true);
        mAudioClipPlayable02 = AudioClipPlayable.Create(mPlayableGraph, AudioClips[1], true);

        mAudioMixerPlayable = AudioMixerPlayable.Create(mPlayableGraph, 2);

        mPlayableGraph.Connect(mAudioClipPlayable01, 0, mAudioMixerPlayable, 0);
        mPlayableGraph.Connect(mAudioClipPlayable02, 0, mAudioMixerPlayable, 1);

        mAudioOutput.SetSourcePlayable(mAudioMixerPlayable);

        mPlayableGraph.Play();

        mInited = true;
    }
Exemple #7
0
        private void CreateTrackOutput(PlayableGraph graph, TrackAsset track, Playable playable, int port)
        {
            if (!track.isSubTrack)
            {
                IEnumerable <PlayableBinding> outputs = track.outputs;
                foreach (PlayableBinding binding in outputs)
                {
                    switch (binding.streamType)
                    {
                    case DataStreamType.Animation:
                    {
                        AnimationPlayableOutput animationPlayableOutput = AnimationPlayableOutput.Create(graph, binding.streamName, null);
                        TimelinePlayable.SetPlayableOutputParameters <AnimationPlayableOutput>(animationPlayableOutput, playable, port, binding);
                        this.EvaluateWeightsForAnimationPlayableOutput(track, animationPlayableOutput);
                        break;
                    }

                    case DataStreamType.Audio:
                    {
                        AudioPlayableOutput output = AudioPlayableOutput.Create(graph, binding.streamName, null);
                        TimelinePlayable.SetPlayableOutputParameters <AudioPlayableOutput>(output, playable, port, binding);
                        break;
                    }

                    case DataStreamType.Texture:
                        goto IL_B8;

                    case DataStreamType.None:
                    {
                        ScriptPlayableOutput output2 = ScriptPlayableOutput.Create(graph, binding.streamName);
                        TimelinePlayable.SetPlayableOutputParameters <ScriptPlayableOutput>(output2, playable, port, binding);
                        break;
                    }

                    default:
                        goto IL_B8;
                    }
                    continue;
IL_B8:
                    throw new NotImplementedException("Unsupported stream type");
                }
            }
        }
Exemple #8
0
 private void CreateTrackOutput(PlayableGraph graph, TrackAsset track, Playable playable, int port)
 {
     if (!track.isSubTrack)
     {
         IEnumerable <PlayableBinding> outputs = track.get_outputs();
         foreach (PlayableBinding current in outputs)
         {
             if (current.get_streamType() == null)
             {
                 AnimationPlayableOutput animationPlayableOutput = AnimationPlayableOutput.Create(graph, current.get_streamName(), null);
                 PlayableOutputExtensions.SetReferenceObject <AnimationPlayableOutput>(animationPlayableOutput, current.get_sourceObject());
                 PlayableOutputExtensions.SetSourcePlayable <AnimationPlayableOutput, Playable>(animationPlayableOutput, playable);
                 PlayableOutputExtensions.SetSourceInputPort <AnimationPlayableOutput>(animationPlayableOutput, port);
                 this.m_EvaluateCallbacks.Add(new AnimationOutputWeightProcessor(animationPlayableOutput));
             }
             else if (current.get_streamType() == 1)
             {
                 AudioPlayableOutput audioPlayableOutput = AudioPlayableOutput.Create(graph, current.get_streamName(), null);
                 PlayableOutputExtensions.SetReferenceObject <AudioPlayableOutput>(audioPlayableOutput, current.get_sourceObject());
                 PlayableOutputExtensions.SetSourcePlayable <AudioPlayableOutput, Playable>(audioPlayableOutput, playable);
                 PlayableOutputExtensions.SetSourceInputPort <AudioPlayableOutput>(audioPlayableOutput, port);
             }
             else
             {
                 if (current.get_streamType() != 3)
                 {
                     throw new NotImplementedException("Unsupported stream type");
                 }
                 ScriptPlayableOutput scriptPlayableOutput = ScriptPlayableOutput.Create(graph, current.get_streamName());
                 PlayableOutputExtensions.SetReferenceObject <ScriptPlayableOutput>(scriptPlayableOutput, current.get_sourceObject());
                 PlayableOutputExtensions.SetSourcePlayable <ScriptPlayableOutput, Playable>(scriptPlayableOutput, playable);
                 PlayableOutputExtensions.SetSourceInputPort <ScriptPlayableOutput>(scriptPlayableOutput, port);
             }
         }
     }
 }
        private void InitialiseBindings(AnimancerPlayable root)
        {
            if (_HasInitialisedBindings || _Bindings == null || root == null)
            {
                return;
            }

            _HasInitialisedBindings = true;

            var bindingCount = _Bindings.Count;

            if (bindingCount == 0)
            {
                return;
            }

            var output = _Asset.outputs.GetEnumerator();
            var graph  = root._Graph;

            for (int i = 0; i < bindingCount; i++)
            {
                if (!output.MoveNext())
                {
                    return;
                }

                var binding = _Bindings[i];
                if (binding == null)
                {
                    continue;
                }

                var name = output.Current.streamName;

#if UNITY_2018_2_OR_NEWER
                var type = output.Current.outputTargetType;
#else
                var type = output.Current.sourceBindingType;
                if (output.Current.streamType == DataStreamType.Animation)
                {
                    type = typeof(Animator);
                }
#endif

#if UNITY_ASSERTIONS
                if (type != null && !type.IsAssignableFrom(binding.GetType()))
                {
                    Debug.LogError(string.Concat(
                                       "Binding Type Mismatch: bindings[", i.ToString(), "] is '",
                                       binding.ToString(), "' but should be a ", type.FullName,
                                       " for ", name));
                    continue;
                }
#endif

                var playable = _Playable.GetInput(i);

                if (type == typeof(Animator))
                {
                    var playableOutput = AnimationPlayableOutput.Create(graph, name, (Animator)binding);
                    playableOutput.SetSourcePlayable(playable);
                }
                else if (type == typeof(AudioSource))
                {
                    var playableOutput = AudioPlayableOutput.Create(graph, name, (AudioSource)binding);
                    playableOutput.SetSourcePlayable(playable);
                }
                else// ActivationTrack, SignalTrack, ControlTrack, PlayableTrack.
                {
                    var playableOutput = ScriptPlayableOutput.Create(graph, name);
                    playableOutput.SetUserData(binding);
                    playableOutput.SetSourcePlayable(playable);
                }
            }
        }