public D GetValueForAnim(int time, AnimConverter conv = null) { if (SelectedAnim >= TimeFrameLines.Count) { if (SelectedAnim == 0) { return(default(D)); } throw new InvalidOperationException("anim >= TimeFrameLines.Count"); } if (TimeFrameLines[SelectedAnim].Count == 0) { return(default(D)); } int tval = time; if (time != 0) { if (Sequence > 0) { tval = (int)(time % Sequence); } else { tval = (int)(time % (TimeFrameLines[SelectedAnim].Last() == 0 ? time : (int)TimeFrameLines[SelectedAnim].Last())); } } int pos = 0; bool found = false; bool useOne = false; if (TimeFrameLines[SelectedAnim].Count == 1) { useOne = true; found = true; pos = 0; } else { for (; pos < TimeFrameLines[SelectedAnim].Count - 1; ++pos) { uint t1 = TimeFrameLines[SelectedAnim][pos]; uint t2 = TimeFrameLines[SelectedAnim][pos + 1]; if (t1 <= tval && t2 >= tval) { found = true; break; } } } if (found == false) { useOne = true; } T val1 = KeyFrameLines[SelectedAnim][pos]; T val2; if (useOne) { val2 = val1; } else { val2 = KeyFrameLines[SelectedAnim][pos + 1]; } uint ti1 = TimeFrameLines[SelectedAnim][pos]; uint ti2 = 0; if (useOne) { ti2 = ti1; } else { ti2 = TimeFrameLines[SelectedAnim][pos + 1]; } float am = 1.0f; if (!useOne) { am = (tval - ti1) / ((float)ti2 - ti1); } D cval1 = default(D); D cval2 = default(D); if (conv != null) { cval1 = (D)conv.Convert(val1); cval2 = (D)conv.Convert(val2); } else { cval1 = (D)AnimConverter.Default.Convert(val1); cval2 = (D)AnimConverter.Default.Convert(val2); } return(AnimInterpolator.Current.Interpolate(cval1, cval2, am)); }
static AnimConverter() { Default = new AnimConverter(); }