public void addElement(string name, string inputString) { HintElement newHintElem = new HintElement(); newHintElem.stringa = inputString; newHintElem.name = name; hintElements.Add(newHintElem); }
public void saveInfos() { //creo l'opportuna directory se non esiste già if (!Directory.Exists(directory)) { Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, directory)); } //cerca l'elemento con indice maggiore int actualIndex = 0; string finalPath01 = Path.Combine(Application.persistentDataPath, directory + "/" + Application.loadedLevelName + "_" + pathFileName + "_"); string finalPath02; while (true) { finalPath02 = finalPath01 + actualIndex.ToString() + ".xml"; if (File.Exists(finalPath02)) { actualIndex++; } else { break; } } //salva tutti gli elementi su file hintContainer = new HintAnalyzerContainer(); hintContainer.hintElements = hintElements.ToArray(); //ORDINO L'Array per nome string[] names = new string[hintContainer.hintElements.Length]; for (int i = 0; i < hintContainer.hintElements.Length; i++) { names[i] = hintContainer.hintElements[i].name; } Array.Sort(names); HintElement[] orderedElements = new HintElement[hintContainer.hintElements.Length]; for (int i = 0; i < names.Length; i++) { for (int j = 0; j < hintContainer.hintElements.Length; j++) { if (names[i] == hintContainer.hintElements[j].name) { orderedElements[i] = hintContainer.hintElements[j]; } } } hintContainer.hintElements = orderedElements; hintContainer.Save(finalPath02); }