public void Update() { KeyFrameCustom fromFrame = new KeyFrameCustom(new Vector3(0.0f, 0.0f, 0.0f), 0); KeyFrameCustom toFrame = new KeyFrameCustom(new Vector3(0.0f, 0.0f, 0.0f), 0); bool addedToFrame = false; for (int i = 0; i < keyFrameSamples.Length; i++) { if (keyFrameSamples[i].timeFrame > currentFrame) { toFrame = keyFrameSamples[i]; addedToFrame = true; break; } else { fromFrame = keyFrameSamples[i]; } } if (!addedToFrame) { switch (animMode) { case AnimMode.Once: transform.position = fromFrame.pos; break; case AnimMode.Loop: currentFrame = 0; break; case AnimMode.PingPong: reverse = true; break; } } else { float unlerp = ((float)(currentFrame - fromFrame.timeFrame) / (float)(toFrame.timeFrame - fromFrame.timeFrame)); transform.position = fromFrame.pos * ((unlerp - 1.0f) / (-1.0f)) + toFrame.pos * unlerp; } if (!reverse) { currentFrame++; } else { currentFrame--; if (currentFrame < 0) { currentFrame = 0; reverse = false; } } }
public static bool CompareTimeFrame(KeyFrameCustom frameA, KeyFrameCustom frameB) { if (frameA.timeFrame > frameB.timeFrame) { return(true); } else { return(false); } }
public KeyFrameCustom(KeyFrameCustom frameCopy) { pos = frameCopy.pos; timeFrame = frameCopy.timeFrame; }