using System; using UnityEngine; namespace Framework.Support { /// Helper methods for interpolating public static class InterpolationHelper { /// Interpolates a typical camera fade /// Running interpolation time /// Total time of the faqde /// Duration of the fade in /// Duration of the fade out /// The interpolated fade level public static float InterpolateFade( float t, float totalTime, float fadeInTime, float fadeOutTime ) { if(fadeInTime <= 0.0f) { // Neither fade-in or fade-out are present. Always return 1.0 if(fadeOutTime <= 0.0f) { return 1.0f; } // Only fade-out is present. Everything before fade-out is 1.0, // everything after it is 0.0 float remainingTime = totalTime - t; if(remainingTime < fadeOutTime) { return Math.Max(0.0f, remainingTime / fadeOutTime); } else { return 1.0f; } } else if(fadeOutTime <= 0.0f) { // Only fade-in is present. Everything before fade-in is 0.0, // everything after it is 1.0 if(t < fadeInTime) { return Math.Max(0.0f, t / fadeInTime); } else { return 1.0f; } } else { // TODO: Do both fade-in and fade-out and calculate where max levels meet // So there's no skip when the length is shorter than the fade time return 0.5f; } } } } // namespace Framework.Support