void GetAccountComplete(RecordAccount account) { List <RecordPet> pets = account != null ? account.pets : null; if (loading != null) { loading.SetActive(false); } if (pets != null) { for (int i = 0; i < pets.Count; i++) { MyPet myPet = Instantiate(myPetProto) as MyPet; myPet.gameObject.SetActive(true); myPet.Set(pets [i]); myPet.transform.SetParent(myPetProto.transform.parent); myPet.name = pets [i].id; if (myPets == null) { myPets = new List <MyPet> (); } myPets.Add(myPet); Debug.Log("create " + myPet.name); } } money.text = "money: " + (account != null ? account.money.ToString() : "---"); }
public void Show(RecordAccount account = null) { myPetProto.gameObject.SetActive(false); if (loading != null) { loading.SetActive(true); } if (myPets != null) { foreach (var pet in myPets) { Debug.Log("delete " + pet.name); Destroy(pet.gameObject); } myPets.Clear(); } if (account != null) { GetAccountComplete(account); } else { Server.GetAccount(GetAccountComplete); } }
IEnumerator IEGetAccount(System.Action <RecordAccount> callback) { using (WWW www = new WWW("http://localhost:8080/getaccount")) { yield return(www); RecordAccount account = JsonConvert.DeserializeObject <RecordAccount>(www.text); Debug.Log(account != null ? account.ToString() : "NULL"); callback(account); } }
IEnumerator IEDeletePet(string pet_id, System.Action <RecordAccount> callback) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(pet_id); using (WWW www = new WWW("http://localhost:8080/deletepet", bytes)) { yield return(www); RecordAccount account = JsonConvert.DeserializeObject <RecordAccount>(www.text); Debug.Log(account != null ? account.ToString() : "NULL"); callback(account); } }
IEnumerator IECreatePet(System.Action <RecordAccount> callback) { using (WWW www = new WWW("http://localhost:8080/createpet", new byte[] { 1 })) { yield return(www); Debug.Log(www.error); Debug.Log(www.text); RecordAccount account = JsonConvert.DeserializeObject <RecordAccount>(www.text); Debug.Log(account != null ? account.ToString() : "NULL"); callback(account); } }
void CreatePetComplete(RecordAccount account) { Show(account); }
public void OnDeleteComplete(RecordAccount account) { MenuPets.Instance.Show(); }
static void SaveAccount(RecordAccount account) { string json = JsonConvert.SerializeObject(account); File.WriteAllText("account", json); }
void UpdateMoney(RecordAccount account) { money.text = "money: " + (account != null ? account.money.ToString() : "---"); }