N0xus
N0xus

Reputation: 2724

Making an X length List fit in between a 0 - 1 scale

I'm having an issue making my list (that could have any number of elements) correspond to another object that takes in a range of 0-1.

What are the steps involved so I can covert my lists data so that when my slider is at 0, it's at the start of my list and when its at 1, it's at the end of my list?

All the code that corresponds to my list and how I'm filling it out is as follows:

private List<DateTime> days = new List<DateTime>();
private string debugAreaString = "";



// Use this for initialization
void Start () 
{
    Slider ();
    sliderElement = sliderObject.GetComponent<UISlider>();
}

// Update is called once per frame
void Update ()
{
    sliderElement.numberOfSteps = Convert.ToInt32(days.Count - 1);
    for( int p = 0; p < sliderElement.numberOfSteps - 1; p++)
    {
        debugAreaString = Convert.ToString(days[p]);
        //Debug.Log(days[p]);
    }


    Debug.Log(sliderElement.numberOfSteps);




}

void Slider()
{
    startTime = new DateTime(startYear, startMonth, startDay);
    endTime = new DateTime(endYear, endMonth, endDay);

    TimeSpan elapsed = endTime.Subtract(startTime);

    startString = startDay.ToString();
    elapsedString = elapsed.TotalDays.ToString();


    int totalDays = (int)endTime.Subtract(startTime).TotalDays;

    days.Add(startTime); 

    for (var i = 1; i < totalDays; i++)
    {
        days.Add(startTime.AddDays(i));
    }

    days.Add(endTime);  
}

The list gets filled with every single day between two points.

Upvotes: 0

Views: 48

Answers (1)

selkathguy
selkathguy

Reputation: 1171

"What are the steps involved so I can covert my lists data so that when my slider is at 0, it's at the start of my list and when its at 1, it's at the end of my list?"

myList[(int)Math.Round(sliderValue*myList.Count)]

No conversion necessary.

Upvotes: 3

Related Questions