void CacheFrame() { cacheFrame = frames[frameIndex]; float min = cacheFrame.frameStart; float max = min + cacheFrame.duration; cacheFrameRange = new Vector2(min, max); }
public void UpdateFrame(float frame) { //Debug.Log("UpdateFrame1"); if (frames == null) { return; } //Debug.Log("UpdateFrame2"); if (frame < cacheFrameRange.x) { frameIndex = -1; } while (frame >= cacheFrameRange.y || frame < cacheFrameRange.x) { frameIndex++; if (frameIndex >= frames.Length) { frameIndex = 0; CacheFrame(); break; } CacheFrame(); } if (frameIndex + 1 < frames.Length) { UgData.BoneFrameData next = frames[frameIndex + 1]; float g = frame - cacheFrameRange.x; float t = cacheFrameRange.y - cacheFrameRange.x; float d = g / t; if (next.transPos) { pos = Vector2.Lerp(startPos, startPos + next.pos, d); } if (next.transScale) { scale = Vector2.Lerp(startScale, next.scale, d); } if (next.transRotate) { rotation = Mathf.Lerp(startRotation, startRotation + next.rotation, d); } } testObj.transform.localScale = new Vector3(scale.x, scale.y, 1); testObj.transform.localPosition = pos; testObj.transform.localEulerAngles = new Vector3(0, 0, rotation); }