public bool Load(int indice) { if (PlayerPrefs.HasKey("Inventario" + indice)) { List <Item> _Itens = new List <Item>(); List <int> _Quantidades = new List <int>(); string _temp = PlayerPrefs.GetString("Inventario" + indice); print(_temp); string variavel = string.Empty; string valor = string.Empty; string array = string.Empty; bool bool_variavel = false; bool bool_valor = false; bool bool_array = false; bool bool_array_nome = false; int ListaIndice = -1; //------------------------ #region Load for (int i = 0; i < _temp.Length; i++) { if (_temp[i] == ']') { bool_variavel = false; } if (_temp[i] == '}') { bool_valor = false; #region Registrando print(array); if (array == "Itens") { _Itens.Add(ResourceFind.FindItem(valor)); print(valor); } if (array == "Quantidades") { _Quantidades.Add(System.Convert.ToInt32(valor)); print(valor); } #endregion variavel = string.Empty; valor = string.Empty; } //Escreve o nome da variavel if (bool_variavel) { variavel += _temp[i]; } //Detectou uma variavel no proximo elemento if (_temp[i] == '[') { bool_variavel = true; } //Escreve o valor da variavel if (bool_valor) { valor += _temp[i]; } //Detecta um valor no proximo elemento if (_temp[i] == '{') { bool_valor = true; } //Detecta o inicio de um array if (_temp[i] == '!') { bool_array = true; array = string.Empty; } if (_temp[i] == '>') { bool_array_nome = false; } //Escreve o nome do array if (bool_array_nome) { array += _temp[i]; } //Detecta um array no proximo elemento if (_temp[i] == '<') { bool_array_nome = true; } //Detecta o termino do nome do array //Detecta o termino de um array if (_temp[i] == '/' && _temp[i + 1] == '!') { bool_array = false; array = string.Empty; i++; } if (_temp[i] == '/' && _temp[i + 1] == '@') { break; } } #endregion //------------------------- _mochila = _Itens; Quantidades = _Quantidades; print("Mochila lenght = " + _mochila.Count); print("LoadQuests OK"); return(true); } print("LoadQuests Failed"); return(false); }
public static bool Load(int indice) { if (PlayerPrefs.HasKey("Quests" + indice)) { List <Quest> _Lista = new List <Quest>(); string _temp = PlayerPrefs.GetString("Quests" + indice); string variavel = string.Empty; string valor = string.Empty; string array = string.Empty; bool bool_variavel = false; bool bool_valor = false; bool bool_array = false; bool bool_array_nome = false; int ListaIndice = -1; int arrayindice = -1; //------------------------ #region Load for (int i = 0; i < _temp.Length; i++) { if (_temp[i] == '@' || _temp[i] == '|') { _Lista.Add(new Quest()); ListaIndice++; } if (_temp[i] == ']') { bool_variavel = false; } if (_temp[i] == '}') { bool_valor = false; #region Registrando if (!bool_array) { if (variavel == "Nome") { _Lista[ListaIndice].Nome = valor; } if (variavel == "Descricao") { _Lista[ListaIndice].Descricao = valor; } if (variavel == "Objetivo") { _Lista[ListaIndice].Objetivo = (ObjetivesType)System.Enum.Parse(typeof(ObjetivesType), valor); } if (variavel == "Repete") { _Lista[ListaIndice].Repete = System.Convert.ToBoolean(valor); } } else { if (array == "Itens") { arrayindice++; _Lista[ListaIndice].ItensColetaveis[arrayindice] = ResourceFind.FindItem(valor); } if (array == "Monstros") { arrayindice++; _Lista[ListaIndice].Monstros[arrayindice] = ResourceFind.FindMonster(valor); } if (array == "Quantidades") { arrayindice++; _Lista[ListaIndice].Quantidades[arrayindice] = System.Convert.ToInt32(valor); } } #endregion variavel = string.Empty; valor = string.Empty; } //Escreve o nome da variavel if (bool_variavel) { variavel += _temp[i]; } //Detectou uma variavel no proximo elemento if (_temp[i] == '[') { bool_variavel = true; } //Escreve o valor da variavel if (bool_valor) { valor += _temp[i]; } //Detecta um valor no proximo elemento if (_temp[i] == '{') { bool_valor = true; } //Detecta o inicio de um array if (_temp[i] == '!') { bool_array = true; arrayindice = -1; array = string.Empty; } //Detecta o termino do nome do array if (_temp[i] == '>') { bool_array_nome = false; } //Escreve o nome do array if (bool_array_nome) { array += _temp[i]; } //Detecta um array no proximo elemento if (_temp[i] == '<') { bool_array_nome = true; } //Detecta o termino de um array if (_temp[i] == '/' && _temp[i + 1] == '!') { bool_array = false; arrayindice = -1; array = string.Empty; i++; } if (_temp[i] == '/' && _temp[i + 1] == '@') { break; } } #endregion //------------------------- Lista = _Lista; print("LoadQuests OK"); return(true); } print("LoadQuests Failed"); return(false); }