Hi,
This is a follow on topic from my unity topic: Default Blend And Starting an animation Half way through .
I am unsure how to make a merge request on github so I will do it here (sorry).
I believe that you should be able to queue an animation on a track, and have it play from any given time (start by default).The clear use case, as in the topic above, is that if an animation gets interrupted and you wish to replay the animation after the interrupt, you may not want it to play for the start.
Imagine your character needs to takes a gun from a holster and cocks the trigger. The character proceeds to take the gun, and thus at this moment in time it is in his hand, but then something interrupts him - he takes a hit for example-. After the take hit has ended the gun is still in his hand, so you don't want him to take it out of his holster again (i.e. play animation from the start), he only needs to clock it (play from a given points).
At the moment we create these Milestones
events, and a callback keeps track of the most recent Milestone
, which gets cleared when the animation ends.
The code I suggest, is adding an additional (optional) parameter to public TrackEntry AddAnimation (...)
c#-unity code would look like this:
public TrackEntry AddAnimation (int trackIndex, Animation animation, bool loop, float delay, float startTime = 0) {
...
entry.time = startTime;
...
}
additionally code in public void Update (float delta)
would need to change:
public void Update (float delta) {
....
TrackEntry next = current.next;
if (next != null) {
float a = current.lastTime - next.delay;
bool b = false;
if (next.time > 0)//Check if we have added a new start time
{
b = true;
a = (next.time + current.lastTime) - next.delay;
}
float c;
c = current.lastTime - next.delay;
if (c >= 0) {
if (b)
{
next.time = a; next.lastTime = a;//Change the start time for this entry
}
else
next.time = a;//only set `time` when the track changes
SetCurrent(i, next);
};
} else {
// End non-looping animation when it reaches its end time and there is no next entry.
if (!current.loop && current.lastTime >= current.endTime) ClearTrack(i);
}
....
}
(this could improved maybe? I didn't want to add any other varibles to the trackentry)
if the startTime needed to change, you could pluginto the track which has it, and manually change it, as the time
var in the TrackEntry no longer changes every frame.
Playing our game showed no obvious errors or bugs.