internal override Playable OnCreatePlayableGraph(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree) { AudioMixerPlayable audioMixerPlayable = AudioMixerPlayable.Create(graph, base.clips.Length, false); for (int i = 0; i < base.clips.Length; i++) { TimelineClip timelineClip = base.clips[i]; PlayableAsset playableAsset = timelineClip.asset as PlayableAsset; if (!(playableAsset == null)) { float num = 0.1f; AudioPlayableAsset audioPlayableAsset = timelineClip.asset as AudioPlayableAsset; if (audioPlayableAsset != null) { num = audioPlayableAsset.bufferingTime; } Playable playable = playableAsset.CreatePlayable(graph, go); if (playable.IsValid <Playable>()) { tree.Add(new ScheduleRuntimeClip(timelineClip, playable, audioMixerPlayable, (double)num, 0.1)); graph.Connect <Playable, AudioMixerPlayable>(playable, 0, audioMixerPlayable, i); playable.SetSpeed(timelineClip.timeScale); playable.SetDuration(timelineClip.extrapolatedDuration); audioMixerPlayable.SetInputWeight(playable, 1f); } } } return(audioMixerPlayable); }
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(); }
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); }
internal override Playable CompileClips(PlayableGraph graph, GameObject go, IList <TimelineClip> timelineClips, IntervalTree <RuntimeElement> tree) { var clipBlender = AudioMixerPlayable.Create(graph, timelineClips.Count); #if UNITY_EDITOR clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone()); m_LiveMixerPlayable = clipBlender; #else if (hasCurves) { clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone()); } #endif for (int i = 0; i < timelineClips.Count; i++) { var c = timelineClips[i]; var asset = c.asset as PlayableAsset; if (asset == null) { continue; } var buffer = 0.1f; var audioAsset = c.asset as AudioPlayableAsset; if (audioAsset != null) { buffer = audioAsset.bufferingTime; } var source = asset.CreatePlayable(graph, go); if (!source.IsValid()) { continue; } if (source.IsPlayableOfType <AudioClipPlayable>()) { // Enforce initial values on all clips var audioClipPlayable = (AudioClipPlayable)source; var audioClipProperties = audioClipPlayable.GetHandle().GetObject <AudioClipProperties>(); audioClipPlayable.SetVolume(Mathf.Clamp01(m_TrackProperties.volume * audioClipProperties.volume)); audioClipPlayable.SetStereoPan(Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f)); audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(m_TrackProperties.spatialBlend)); } tree.Add(new ScheduleRuntimeClip(c, source, clipBlender, buffer)); graph.Connect(source, 0, clipBlender, i); source.SetSpeed(c.timeScale); source.SetDuration(c.extrapolatedDuration); clipBlender.SetInputWeight(source, 1.0f); } ConfigureTrackAnimation(tree, go, clipBlender); return(clipBlender); }
/// <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"); }
static AudioMixerPlayable CreateAudioBinding(PlayableGraph graph, AudioSource audioSource) { var mixerPlayable = AudioMixerPlayable.Create(graph, 1); var output = (AudioPlayableOutput)graph.GetOutputByType <AudioPlayableOutput>(0); if (!output.IsOutputNull()) { output.SetTarget(audioSource); output.SetSourcePlayable(mixerPlayable); Assert.IsTrue(output.IsOutputValid()); } return(mixerPlayable); }
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); } }
public AnimationComponent(AnimationMixerPlayable animationMixer, AudioMixerPlayable audioMixer, int animation, int audio = -1) { this.animationMixer = animationMixer; this.audioMixer = audioMixer; this.animationIndex = animation; this.audioIndex = audio; var clip = (AnimationClipPlayable)animationMixer.GetInput(animationIndex); // Calculate time for processing current clip. totalTime = clip.GetAnimationClip().length; // Reset the time so that the clip starts at the correct position. clip.SetTime(0); // Reverse the animation if necessary. clip.SetSpeed(speed); }
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; }
internal override Playable OnCreateClipPlayableGraph(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree) { var clipBlender = AudioMixerPlayable.Create(graph, clips.Length); // In the player, we do not add the AudioMixerProperties behaviour to the track if it contains no animation // however in the editor we want to always have it present to be able to preview changes live. #if UNITY_EDITOR clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone()); m_LiveMixerPlayable = clipBlender; #else if (hasCurves) { clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone()); } #endif InitializeClips(graph, go, tree, clipBlender); return(clipBlender); }
public void LoadAndPlay(MusicClip musicClip, Playable owner, PlayableGraph graph) { owner.SetInputCount(1); mixer = AudioMixerPlayable.Create(graph, musicClip.ClipLayers.Length); mixer.SetInputCount(musicChannels.Count + 1); var nextMusicChannelPlayable = ScriptPlayable <MusicChannel> .Create(graph); var nextMusicChannel = nextMusicChannelPlayable.GetBehaviour(); currentTime = 0; var leadTime = musicClip.Beginning.InSeconds(musicClip.BeatsPerBar, musicClip.BPM); channelCutOverTime = musicChannels.Count == 0 ? double.MinValue : musicChannels.First.Value.NextEnding(leadTime); channelPlayTime = musicChannels.Count == 0 ? double.MinValue : channelCutOverTime - leadTime; musicChannels.AddLast(nextMusicChannel); for (int i = 0; i < musicChannels.Count + 1; i++) { graph.Connect(mixer, 0, owner, 0); graph.Connect(nextMusicChannelPlayable, 0, mixer, i); mixer.SetInputWeight(i, 1); } }
public static ReductionSyntax <PlayableSyntax> Add( this PlayableGraph graph, ref AudioMixerPlayable playable, int count, bool normalize = false) { playable = AudioMixerPlayable.Create(graph, count, normalize); return(PlayableSyntax.Create(graph, playable)); }
void InitializeClips(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree, AudioMixerPlayable clipBlender) { for (int i = 0; i < clips.Length; i++) { var c = clips[i]; var asset = c.asset as PlayableAsset; if (asset == null) { continue; } var buffer = 0.1f; var audioAsset = c.asset as AudioPlayableAsset; if (audioAsset != null) { buffer = audioAsset.bufferingTime; } var source = asset.CreatePlayable(graph, go); if (!source.IsValid()) { continue; } if (source.IsPlayableOfType <AudioClipPlayable>()) { // Enforce initial values on all clips var audioClipPlayable = (AudioClipPlayable)source; var audioClipProperties = audioClipPlayable.GetHandle().GetObject <AudioClipProperties>(); audioClipPlayable.SetVolume(Mathf.Clamp01(m_TrackProperties.volume * audioClipProperties.volume)); audioClipPlayable.SetStereoPan(Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f)); audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(m_TrackProperties.spatialBlend)); } tree.Add(new ScheduleRuntimeClip(c, source, clipBlender, buffer)); graph.Connect(source, 0, clipBlender, i); source.SetSpeed(c.timeScale); source.SetDuration(c.extrapolatedDuration); clipBlender.SetInputWeight(source, 1.0f); } }
protected override void CreateMixerPlayable() { mMixerPlayable = AudioMixerPlayable.Create(mGraph, 1, true); }