关于如何为时间轴创建自己的混音器,我已经弄清楚了。使用类似的文本甚至对我来说都可以使用,但是使用AudioSource调音台则无法使用。为什么会发生这种情况? 这是调音台代码:
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using System.Collections.Generic;
public class LocalizedSoundMixerBehaviour : PlayableBehaviour
{
AudioSource m_TrackBinding;
bool m_FirstFrameHappened;
int inputCount;
LocalizedSoundBehaviour Behaviour;
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
m_TrackBinding = playerData as AudioSource;
if (m_TrackBinding == null)
return;
if (!m_FirstFrameHappened)
{
m_FirstFrameHappened = true;
}
float totalWeight = 0f;
float greatestWeight = 0f;
int currentInputs = 0;
inputCount = playable.GetInputCount();
for (int i = 0; i < inputCount; i++)
{
float inputWeight = playable.GetInputWeight(i);
ScriptPlayable<LocalizedSoundBehaviour> inputPlayable = (ScriptPlayable<LocalizedSoundBehaviour>)playable.GetInput(i);
Behaviour = inputPlayable.GetBehaviour();
totalWeight += inputWeight;
if (inputWeight > greatestWeight)
{
greatestWeight = inputWeight;
}
if (!Mathf.Approximately(inputWeight, 0f))
currentInputs++;
}
m_TrackBinding.clip = Behaviour.Sounds[0]; //arrey != 0
m_TrackBinding.Play();
}
public override void OnPlayableDestroy (Playable playable)
{
m_FirstFrameHappened = false;
if (m_TrackBinding == null)
return;
m_TrackBinding.Stop();
m_TrackBinding.clip = null;
}
}
创建了所有文件(行为,剪辑,音轨),所以我不明白为什么音乐不播放...