Ejemplo n.º 1
0
    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();
    }
Ejemplo n.º 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();
    }
Ejemplo n.º 3
0
    AudioStateInfo DoAddState(string name, AudioClip clip, bool isLoop)
    {
        AudioStateInfo newState = mAudioStateInfoManager.InsertState();

        newState.Init(name, clip, isLoop);

        int index = newState.Index;

        if (index == mMixerPlayable.GetInputCount())
        {
            mMixerPlayable.SetInputCount(index + 1);
        }

        var clipPlayable = AudioClipPlayable.Create(mGraph, clip, isLoop);

        if (!isLoop)
        {
            clipPlayable.SetDuration(clip.length);
        }

        newState.SetPlayable(clipPlayable);
        newState.Pause();

        if (mIsKeepStoppedPlayablesConnected)
        {
            ConnectInput(newState.Index);
        }

        return(newState);
    }
Ejemplo n.º 4
0
        private void Play(EAudioChannel channel, AudioClip audioClip)
        {
            if (channel == EAudioChannel.BGM)
            {
                PlayBGM(audioClip);
                return;
            }
            //if (IsMute(channel)) {
            //    return;
            //}
            var playable = mMixer.GetInput((int)channel);
            var count    = playable.GetInputCount();

            for (var i = 0; i < count; ++i)
            {
                var t = (AudioClipPlayable)playable.GetInput(i);
                if (t.IsDone())
                {
                    t.SetClip(audioClip);
                    t.SetTime(0);
                    t.SetDuration(audioClip.length);
                    t.SetDone(false);
                    return;
                }
            }
            var p = AudioClipPlayable.Create(mGraph, audioClip, false);

            p.SetDuration(audioClip.length);
            playable.AddInput(p, 0, 1);
        }
        /// <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");
        }
 private void Create(TimelineClip clip, Playable clipPlayable, Playable parentMixer, double startDelay, double finishTail)
 {
     this.m_Clip              = clip;
     this.m_Playable          = clipPlayable;
     this.m_AudioClipPlayable = (AudioClipPlayable)clipPlayable;
     this.m_ParentMixer       = parentMixer;
     this.m_StartDelay        = startDelay;
     this.m_FinishTail        = finishTail;
     PlayableExtensions.SetPlayState <Playable>(clipPlayable, 0);
 }
Ejemplo n.º 7
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();
        }
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            Playable result;

            if (this.m_Clip == null)
            {
                result = Playable.Null;
            }
            else
            {
                result = AudioClipPlayable.Create(graph, this.m_Clip, this.m_Loop);
            }
            return(result);
        }
Ejemplo n.º 9
0
 public void Load(MusicClip musicClip, Playable owner, PlayableGraph graph)
 {
     Clip = musicClip;
     owner.SetInputCount(1);
     mixer = AudioMixerPlayable.Create(graph, musicClip.ClipLayers.Length);
     graph.Connect(mixer, 0, owner, 0);
     owner.SetInputWeight(0, 1);
     inputPlayables = new AudioClipPlayable[musicClip.ClipLayers.Length];
     for (int i = 0; i < musicClip.ClipLayers.Length; i++)
     {
         inputPlayables[i] = AudioClipPlayable.Create(graph, musicClip.ClipLayers[i].Clip, false);
         graph.Connect(inputPlayables[i], 0, mixer, i);
         mixer.SetInputWeight(i, i == 0 ? 1f : 0f);
     }
 }
Ejemplo n.º 10
0
        private void PlayBGM(AudioClip audioClip)
        {
            mBgmAudioClip = audioClip;
            var bgm = mMixer.GetInput((int)EAudioChannel.BGM);

            //if (IsMute(EAudioChannel.BGM)) {
            //    return;
            //}
            if (bgm.GetInputCount() == 0)
            {
                bgm.AddInput(AudioClipPlayable.Create(mGraph, audioClip, true), 0, 0);
                mSingleTransitionIn = mSingleTransitionTime;
                return;
            }
            mSingleTransitionOut = mSingleTransitionIn = mSingleTransitionTime;
        }
        /// <summary>
        /// Creates the root of a Playable subgraph to play the audio clip.
        /// </summary>
        /// <param name="graph">PlayableGraph that will own the playable</param>
        /// <param name="go">The GameObject that triggered the graph build</param>
        /// <returns>The root playable of the subgraph</returns>
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            if (m_Clip == null)
            {
                return(Playable.Null);
            }

            var audioClipPlayable = AudioClipPlayable.Create(graph, m_Clip, m_Loop);

            audioClipPlayable.GetHandle().SetScriptInstance(m_ClipProperties.Clone());

#if UNITY_EDITOR
            m_LiveClipPlayable = audioClipPlayable;
#endif

            return(audioClipPlayable);
        }
Ejemplo n.º 12
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;
    }
 public static ReductionSyntax <PlayableSyntax> Add(
     this PlayableGraph graph, ref AudioClipPlayable playable, AudioClip clip, bool looping)
 {
     playable = AudioClipPlayable.Create(graph, clip, looping);
     return(PlayableSyntax.Create(graph, playable));
 }