I'm making an app that's similar to an alarm, the user enters time and days, for days I'm using toggles,and storing the values of toggles states in a list which is stored in a list that contain all the inputs of the type days, then the user could edit any of his inputs, his old input are supposed to be shown there , but the problem is even when I'm storing them, old values are changing when I add new elements,(that's when currentToggle is changing) so when he press edit values aren't the same as he entered them
I think it has something to do with nested lists but I can't figure out how, ( assigning hours and minutes is perfectly working and both are normal lists)
the confirm method is for when the user confirm his choice, and there's edit button that open a panel ,its values are the same as the user entered them before
the index gives the number of the selected group of input, dayholder is the gameobject that contains all the toggles , and that's the part of the code that's related to what I've said
Toggle[] toggles;
List<bool> currentToggle = new List<bool>();
List <List<bool>> daysAll = new List<List<bool>>();
void Start () {
toggles = dayHolder.GetComponentsInChildren<Toggle>();
}
public void confirm()
{
checkON();
daysAll.Add(currentToggle);
}
public void editBut()
{
GameObject panelC = EventSystem.current.currentSelectedGameObject.gameObject.transform.parent.gameObject;
int index = panelC.transform.parent.gameObject.transform.GetSiblingIndex();
assignDays(index);
}
void assignDays(int index)
{
for (int i = 0; i < daysAll[index].Count; i++)
{
if (daysAll[index][i] == true)
toggles[i].isOn = true;
}
}
public void checkON()
{
currentToggle.RemoveAll(item => item != null);
for (int i = 0; i < toggles.Length; i++)
{
if (toggles[i].isOn)
currentToggle.Add(true);
else
currentToggle.Add(false);
}
}
currentToggle
changes , mostly because of what @DMGregory said that Lists in C# are reference types \$\endgroup\$for (int i = 0; i < daysAll[index].Count; i++) { if (daysAll[index][i] == true) toggles[i].isOn = true; else toggles[i].isOn = false; }
Thanks for your help \$\endgroup\$