void updateAnimationVars() { float value = InterpolationUtil.moveInLinear(Time.timeSinceLevelLoad - animationStartTime, 0, duration, 1); if (value >= 1) { value = 100; fillAnimate = false; } getMaterial().SetFloat("_FillValue", value); }
void updateAnimationVars() { float value = 1 - InterpolationUtil.moveInLinear(Time.realtimeSinceStartup - animationStartTime, 0, duration, 1); if (value <= 0) { value = 0; fillAnimate = false; } material.SetFloat(FILL_VALUE_ID, value); }
void doScrollingToExactPosition(ref Vector2 scrollPosition) { float y; float time = Time.time - startTime; if (time < duration) { y = InterpolationUtil.moveInCirc(time, startY, duration, routeLength); } else { y = targetY; animate = false; } scrollPosition.y = y; }
/// <summary> /// step all interpolations using cached kinematic states /// </summary> private void updateInterpolations() { foreach (var cachedKinState in cachedKinStates) { var body = cachedKinState.Key; var cache = cachedKinState.Value; var interpLag = cache.stateBuf.capacity - 1; if (cache.stateBuf.Count < cache.stateBuf.capacity) { continue; } var update0 = cache.stateBuf.peekAt(0); // start var update1 = cache.stateBuf.peekAt(1); // end // calculate time discrepancy var timeNow = NetworkTime.time(); // time between stored frames var timeDiff = (update1.data.time - update0.data.time) / 1000f; // time since we received the last frame var refRecvAt = update1.receivedAt; // time the end update was received var frameTime = 1f / syncer.netUps; // expected timestep for each frame var rawTimeSince = (timeNow - refRecvAt) / 1000f; // time since receiving the end update var relTimeSince = rawTimeSince - frameTime * (interpLag - 1); // relative time (adjusting for interpolation lag) // if our interpolation window exceeds the time window we received, skip if (relTimeSince > timeDiff) { continue; } var interpT = (relTimeSince / timeDiff); // progress in interpolation if (timeDiff == 0) { interpT = 1; // protect from NaN } #if DEBUG if (syncer.debug) { Global.log.trace( $"interpolate T: {interpT} (rawsince={rawTimeSince}, relsince={relTimeSince}, diff={timeDiff}"); } #endif // // just apply directly // update1.applyTo(body); switch (body.interpolationType) { case SyncBody.InterpolationType.Linear: if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Pos)) { body.pos = InterpolationUtil.lerp(update0.data.pos.unpack(), update1.data.pos.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Vel)) { body.velocity = InterpolationUtil.lerp(update0.data.vel.unpack(), update1.data.vel.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Angle)) { body.angle = InterpolationUtil.lerp(update0.data.angle, update1.data.angle, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.AngularVel)) { body.angularVelocity = InterpolationUtil.lerp(update0.data.angularVelocity, update1.data.angularVelocity, interpT); } break; case SyncBody.InterpolationType.Hermite: if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Pos)) { body.pos = InterpolationUtil.hermite(update0.data.pos.unpack(), update1.data.pos.unpack(), update0.data.vel.unpack() * Time.DeltaTime, update1.data.vel.unpack() * Time.DeltaTime, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Vel)) { body.velocity = InterpolationUtil.lerp(update0.data.vel.unpack(), update1.data.vel.unpack(), interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.Angle)) { body.angle = InterpolationUtil.hermite(update0.data.angle, update1.data.angle, update0.data.angularVelocity * Time.DeltaTime, update1.data.angularVelocity * Time.DeltaTime, interpT); } if (body.syncedFields.HasFlag(SyncBody.InterpolatedFields.AngularVel)) { body.angularVelocity = InterpolationUtil.lerp(update0.data.angularVelocity, update1.data.angularVelocity, interpT); } break; } } }