Beispiel #1
0
        private IEnumerator loadFromWeb(string url, Action <Exception> errorHandler)
        {
            UnityWebRequest download = UnityWebRequest.Get(url);

                        #if UNITY_2017_3_OR_NEWER
            download.SendWebRequest();
                        #else
            download.Send();
                        #endif

            while (!download.isDone)
            {
                // wait for the download complete
                yield return(null);
            }

                        #if UNITY_2017_1_OR_NEWER
            if (download.isNetworkError)
            {
                errorHandler(new Exception("Network Error"));
            }
            else if (download.isHttpError)
            {
                errorHandler(new Exception("HTTP Error"));
                        #else
            if (download.isError)
            {
                errorHandler(new Exception(download.error));
                        #endif
            }
            else
            {
                jsonDoc = JsonUtility.FromJson <JsonWordDictDocument> (download.downloadHandler.text);
                yield return(init());
            }

            // clear the cache to release memory
                        #if UNITY_2017_1_OR_NEWER
            Caching.ClearCache();
                        #else
            Caching.CleanCache();
                        #endif
        }

        #endregion
    }
Beispiel #2
0
        private void loadFromFile(string filePath, MonoBehaviour obj)
        {
            StringBuilder strBuilder = new StringBuilder();

            try {
                StreamReader reader = new StreamReader(filePath);

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    strBuilder.Append(line);
                }
            }
            catch (Exception ex) {
                throw ex;
            }
            jsonDoc = JsonUtility.FromJson <JsonWordDictDocument> (strBuilder.ToString());
            obj.StartCoroutine(init());
        }
Beispiel #3
0
 private void loadFromAsset(TextAsset asset, MonoBehaviour obj)
 {
     jsonDoc = JsonUtility.FromJson <JsonWordDictDocument> (asset.text);
     obj.StartCoroutine(init());
 }