protected virtual SpriterVarValue GetVariableValue(SpriterAnimation animation, SpriterVarDef varDef, SpriterVarline varline, float targetTime)
        {
            SpriterVarlineKey[] keys = varline.Keys;
            if (keys == null)
            {
                return(varDef.VariableValue);
            }

            SpriterVarlineKey keyA = keys.GetLastKey(targetTime) ?? keys[keys.Length - 1];

            if (keyA == null)
            {
                return(varDef.VariableValue);
            }

            SpriterVarlineKey keyB = varline.Keys.GetNextKey(keyA, animation.Looping);

            if (keyB == null)
            {
                return(keyA.VariableValue);
            }

            float adjustedTime = keyA.Time == keyB.Time ? targetTime : SpriterHelper.AdjustTime(targetTime, keyA, keyB, animation.Length);
            float factor       = SpriterHelper.GetFactor(keyA, keyB, animation.Length, adjustedTime);

            SpriterVarValue varVal = Pool.GetObject <SpriterVarValue>();

            varVal.Interpolate(keyA.VariableValue, keyB.VariableValue, factor);
            return(varVal);
        }
        private static SpriterVarValue GetVariableValue(SpriterAnimation animation, SpriterVarDef varDef, SpriterVarline varline, float targetTime)
        {
            SpriterVarlineKey[] keys = varline.Keys;
            if (keys == null)
            {
                return(varDef.VariableValue);
            }

            SpriterVarlineKey keyA = LastKeyForTime(keys, targetTime) ?? keys[keys.Length - 1];

            if (keyA == null)
            {
                return(varDef.VariableValue);
            }

            SpriterVarlineKey keyB = GetNextXLineKey(varline.Keys, keyA, animation.Looping);

            if (keyB == null)
            {
                return(keyA.VariableValue);
            }

            float adjustedTime = keyA.Time == keyB.Time ? targetTime : AdjustTime(keyA, keyB, animation.Length, targetTime);
            float factor       = GetFactor(keyA, keyB, animation.Length, targetTime);

            return(Interpolate(keyA.VariableValue, keyB.VariableValue, factor));
        }