Пример #1
0
        IEnumerator DoLoad()
        {
            Debug.Log("Loading...");

            // Disable load button.
            loadButton.interactable = false;
            // SaveGameWeb web = new SaveGameWeb(url, secretKey, usernameInputField.text, passwordInputField.text);
            SaveGameWeb web = new SaveGameWeb(url, secretKey, userName, password);
            yield return StartCoroutine(web.Download(identifier));

            // Enable load button.
            loadButton.interactable = true;
#if UNITY_2017_1_OR_NEWER
            if ( web.Request.isHttpError || web.Request.isNetworkError )
			{
                Debug.LogError("Load Failed");
                Debug.LogError(web.Request.error);
                Debug.LogError(web.Request.downloadHandler.text);
            }
            else
            {
                Debug.Log("Load Successful");
                Debug.Log("Response: " + web.Request.downloadHandler.text);
                //dataInputField.text = web.Load<string>(defaultValue);
                SaveItemsList loadItems = new SaveItemsList();
                loadItems = JsonUtility.FromJson<SaveItemsList>(web.Load<string>(defaultValue)) ;
                Debug.Log(loadItems.saveList[0].tag);
                foreach(SaveItems item in loadItems.saveList)
                {
                    foreach(GameObject prefab in prefabList)
                    {
                        if (prefab.tag == item.tag)
                        {
                            GameObject tileAdded = (GameObject)Instantiate(prefab, item.pos, item.rot);
                            //objLoad.PushItem(tileAdded);
                            //if (scrollList != null)
                            //    scrollList.TryTransferItemToOtherShop(cartItem);
                            tileAdded.transform.parent = GameObject.FindGameObjectWithTag("Manager").transform;
                        }
                    }
                }
            }
#else
            if (web.Request.isError)
            {
                Debug.LogError("Load Failed");
                Debug.LogError(web.Request.error);
                Debug.LogError(web.Request.downloadHandler.text);
            }
            else
            {
                Debug.Log("Load Successful");
                Debug.Log("Response: " + web.Request.downloadHandler.text);
                dataInputField.text = web.Load<string>(defaultValue);
            }
#endif
        }
Пример #2
0
        IEnumerator DoSave()
        {
            Debug.Log("Saving...");

            // Disable save button.
            saveButton.interactable = false;
            //SaveGameWeb web = new SaveGameWeb(url, secretKey, usernameInputField.text, passwordInputField.text);
            SaveGameWeb web = new SaveGameWeb(url, secretKey, userName, password);
            SaveItemsList saveDataList =  new SaveItemsList();
            List<SaveItems> saveList = new List<SaveItems>();
            string saveJsonData = string.Empty;
            Transform[] ts = WorldManager.GetComponentsInChildren<Transform>();
            foreach (Transform t in ts)
            {
                if (t.gameObject.tag.Contains("Placed"))
                {
                    SaveItems saveData = new SaveItems();
                    saveData.itemName = t.name;
                    saveData.pos = t.transform.position;
                    saveData.rot = t.transform.rotation;
                    saveData.scale = t.transform.localScale;
                    saveData.tag = t.tag;
                    saveList.Add(saveData);
                }
            }
            saveDataList.saveList = saveList;
            saveJsonData = JsonUtility.ToJson(saveDataList);
            yield return StartCoroutine(web.Save(identifier, saveJsonData));// dataInputField.text));

            // Enable save button.
            saveButton.interactable = true;
#if UNITY_2017_1_OR_NEWER
            if ( web.Request.isHttpError || web.Request.isNetworkError )
			{
				Debug.LogError ( "Save Failed" );
				Debug.LogError ( web.Request.error );
				Debug.LogError ( web.Request.downloadHandler.text );
			}
			else
			{
				Debug.Log ( "Save Successful" );
				Debug.Log ( "Response: " + web.Request.downloadHandler.text );
			}
#else
            if (web.Request.isError)
            {
                Debug.LogError("Save Failed");
                Debug.LogError(web.Request.error);
                Debug.LogError(web.Request.downloadHandler.text);
            }
            else
            {
                Debug.Log("Save Successful");
                Debug.Log("Response: " + web.Request.downloadHandler.text);
            }
#endif
        }