Hi
I want to change the playback speed of target animator in runtime because timescale changes the speed of everything. (So I cannot use the time dilation track in the default playable package).
I used timeline playable wizard to create a custom track of my own to alter the target animator speed. However although the script worked, the playback speed did not change. Is there anything wrong with my script? Or is there any work around on this issue?
I also tried using Chronos’s lock clock function but Chronos doesn’t seem to work in timeline either.
here is my code:
public class AnimatorPlaySpeedMixerBehaviour : PlayableBehaviour
{
float m_DefaultSpeed;
Animator m_TrackBinding;
bool m_FirstFrameHappend;
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
m_TrackBinding = playerData as Animator;
if (!m_TrackBinding)
return;
if (!m_FirstFrameHappend)
{
m_DefaultSpeed = m_TrackBinding.speed;
m_FirstFrameHappend = true;
}
int inputCount = playable.GetInputCount ();
float blendedSpeed = 0f;
float totalWeight = 0f;
float greatestWeight = 0f;
int currentInputs = 0;
for (int i = 0; i < inputCount; i++)
{
float inputWeight = playable.GetInputWeight(i);
ScriptPlayable<AnimatorPlaySpeedBehaviour> inputPlayable = (ScriptPlayable<AnimatorPlaySpeedBehaviour>)playable.GetInput(i);
AnimatorPlaySpeedBehaviour input = inputPlayable.GetBehaviour ();
blendedSpeed += input.Speed * inputWeight;
totalWeight += inputWeight;
if (inputWeight > greatestWeight)
{
greatestWeight = inputWeight;
}
if (!Mathf.Approximately (inputWeight, 0f))
currentInputs++;
}
m_TrackBinding.speed = blendedSpeed + m_DefaultSpeed * (1f - totalWeight);
if (currentInputs != 1 && 1f - totalWeight > greatestWeight)
{
}
}
public override void OnGraphStop(Playable playable)
{
m_TrackBinding.speed = m_DefaultSpeed;
m_FirstFrameHappend = false;
}
}