コード例 #1
0
        // Creates the sheet data with the current state of all CloudDataFields
        protected virtual void CreateFromURL()
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Debug.LogWarning("[Unity Cloud Data] Internet connection not detected; skipping create for '" + this.GetType().Name + "'");
                return;
            }

            // fecth the newEntries
            string rawData = "{" +
                             "\"name\": \"" + path + "\"," +
                             "\"description\": \"created from editor\"," +
                             "\"values\": " + newSheetEntries +
                             "}";

            byte[] byteArray = Encoding.UTF8.GetBytes(rawData);
            var    headers   = new Dictionary <string, string>();

            headers["Content-Type"] = "application/json";
            Debug.Log(string.Format("[Unity Cloud Data] Creating sheet in Unity Cloud Data at path: {0}", path));

            isCreating = true;
#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
            WWWUtility.StartRequest(sheetWriteUrl, byteArray, headers, FinishedCreatingFromURL);
        }
コード例 #2
0
        protected virtual void LoadSheetToken()
        {
            Debug.Log("[Unity Cloud Data] Requesting sheet token from Unity Cloud Data for sheet: '" + path + "'");
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Debug.LogWarning("[Unity Cloud Data] Internet connection not detected; skipping sheet token request for '" + path + "'");
                return;
            }

            isRefreshing = true;
#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
            WWWUtility.StartRequest(tokenReadUrl, FinishedLoadingSheetToken);
        }
コード例 #3
0
        bool DoRefresh()
        {
            SaveSettings();

            // Find all tweak table prefabs
            List <Component> dataSheets = UnityCloudData.EditorTools.GetAllComponentsInPrefabs <CloudDataSheet>();

            string baseAssetPath = Application.dataPath + "/" + assetFolder;

            if (false == Directory.Exists(baseAssetPath))
            {
                Directory.CreateDirectory(baseAssetPath);
            }

            // Fancy LINQ syntax to build a list of DownloadItem structs
            IEnumerable <DownloadItem> urls =
                from component in dataSheets
                select new DownloadItem
            {
                Url       = ((CloudDataSheet)component).sheetReadUrl,
                AssetName = ((CloudDataSheet)component).path,
                AssetPath = baseAssetPath + "/" + ((CloudDataSheet)component).path.Replace("/", "-") + ".txt"
            };

            bool refreshResult = true;

            // Save each URL to asset
            foreach (DownloadItem item in urls)
            {
                if (m_sync)
                {
                    WWW request = new WWW(item.Url);
                    while (false == request.isDone)
                    {
                        System.Threading.Thread.Sleep(100);
                    }

                    // Make sure we return false if there are any failures
                    refreshResult &= HandleResponseForDownloadItem(request, item);
                }
                else
                {
                    WWWUtility.StartRequest(item.Url, FinishedCreatingFromURL, item);
                }
            }

            return(refreshResult);
        }
コード例 #4
0
        void WriteQueueEntries()
        {
            if (m_WriteQueue.Count > 0)
            {
                m_CurrentWriteEntry = m_WriteQueue.Dequeue();

                // Create request headers
                var headers = new Dictionary <string, string>();
                headers.Add("Content-Type", "application/json");
                Debug.Log(string.Format("[Unity Cloud Data] writing key '{0}' for sheet at path '{1}'", m_CurrentWriteEntry.sheetKey, path));
                byte[] body = Encoding.UTF8.GetBytes(m_CurrentWriteEntry.putEntry);
                WWWUtility.StartRequest(m_CurrentWriteEntry.putUrl, body, headers, FinishedWritingEntry);
            }
            else
            {
                Debug.Log(string.Format("[Unity Cloud Data] Done saving sheet at path '{0}'!", path));
                // wait until after the refresh completes to trigger the callback
                onRefreshCacheComplete += PostWriteRefreshFinished;
                RefreshCache();
            }
        }
コード例 #5
0
        // Updates the sheet data with data stored on a remote HTTP server
        protected virtual void LoadFromURL()
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogWarning("[Unity Cloud Data] Not loading sheet - no path set!");
                return;
            }

            Debug.Log("[Unity Cloud Data] Requesting sheet from Unity Cloud Data at path: '" + path + "'");
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Debug.LogWarning("[Unity Cloud Data] Internet connection not detected; skipping update for '" + path + "'");
                return;
            }

            isRefreshing = true;
#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
            WWWUtility.StartRequest(sheetReadUrl, FinishedLoadingFromURL);
        }