using UnityEngine;

using System;
using System.Collections;

public class FilteredFloat
{
    #region Fields

    private float _RaiseStepFactor;
    private float _LowerStepFactor;

    private float _CurrentValue;

    #endregion

    #region Getters and Setters

    public float CurrentValue
    {
        get { return _CurrentValue; }
        set { _CurrentValue = value; }
    }

    #endregion

    #region Logic

    public void Reset()
    {
        _CurrentValue = 0.0f;
    }

    public float ToValue(float i_NewValue, float i_FrameTime)
    {
        float smoothStepFactor = (i_NewValue < _CurrentValue) ? _LowerStepFactor : _RaiseStepFactor;
        float smoothFactor = (smoothStepFactor > 0.0f) ? 1.0f - Mathf.Pow(0.5f, i_FrameTime / smoothStepFactor) : 1.0f;

        _CurrentValue += (i_NewValue - _CurrentValue) * smoothFactor;

        return _CurrentValue;
    }

    #endregion

    #region Constructors

    public FilteredFloat(float i_RaiseStepFactor = 0.5f, float i_LowerStepFactor = 0.5f)
    {
        _CurrentValue = 0.0f;

        _RaiseStepFactor = i_RaiseStepFactor;
        _LowerStepFactor = i_LowerStepFactor;
    }

    #endregion    
}
