static List <Segment> GenerateSegments(Asset asset, TaggedAnimationClip animationClip) { var segments = new List <Segment>(); var tags = animationClip.Tags.ToList(); tags.Sort((x, y) => x.startTime.CompareTo(y.startTime)); foreach (TagAnnotation tag in tags) { float startTime = math.max(0.0f, tag.startTime); float endTime = math.min(animationClip.DurationInSeconds, tag.EndTime); float duration = endTime - startTime; if (duration <= 0.0f) { Debug.LogWarning($"One '{tag.Name}' tag is laying entirely outside of '{animationClip.ClipName}' clip range, it will therefore be ignored. (Tag starting at {tag.startTime:0.00} seconds, whose duration is {tag.duration:0.00} seconds)."); continue; } int firstFrame = animationClip.ClampedTimeInSecondsToIndex(startTime); int numFrames = animationClip.ClampedDurationInSecondsToFrames(duration); int onePastLastFrame = math.min(firstFrame + numFrames, animationClip.NumFrames); var interval = new Interval(firstFrame, onePastLastFrame); var segment = new Segment { clip = animationClip, source = interval, destination = Interval.Empty }; segment.tags.Add(tag); segments.Add(segment); } Coalesce(segments); return(segments); }
public int GetFrameIndexFromClipTime(float time) { return(clip.ClipFramesToAssetFrames(asset, clip.ClampedTimeInSecondsToIndex(time))); }