public void LoadLocalMarkersOnStartup(bool isRecognitionManagerRunning, string[] markerIds, string[] discoverIds)
        {
            LoadLocalDiscoverModelsOnStartUp(discoverIds);

            if (markerIds.Length < 1)
            {
                return;
            }

            string srcMarkerPath = Application.streamingAssetsPath + "/markers/";

#if UNITY_EDITOR || UNITY_IOS
            if (!Directory.Exists(Application.streamingAssetsPath) || !Directory.Exists(srcMarkerPath))
            {
                return;
            }
#endif
            string dstMarkerPath = RecognitionManager.GetAppDataPath() + "markers/";

            if (!Directory.Exists(dstMarkerPath))
            {
                Directory.CreateDirectory(dstMarkerPath);
            }
            else
            {
                string[] files = Directory.GetFiles(dstMarkerPath);
                foreach (string ff in files)
                {
                    File.Delete(ff);
                }
            }

            foreach (string markerId in markerIds)
            {
                Debug.Log("Loading marker " + markerId);
                if (markerId == "")
                {
                    continue;
                }

                string markerString = null;

#if UNITY_EDITOR || UNITY_IOS
                markerString = File.ReadAllText(srcMarkerPath + markerId + ".dat");
#else
                WWW reader = new WWW(srcMarkerPath + markerId + ".dat");
                while (!reader.isDone)
                {
                }
                if (!String.IsNullOrEmpty(reader.error))
                {
                    continue;
                }
                markerString = reader.text;
#endif
                if (markerString.Length > 0)
                {
                    Debug.Log("Loading marker save " + markerId);
                    WSMarkerResponse.WSMarker markerData = JsonUtilities.ToObject <WSMarkerResponse.WSMarker>(markerString);
                    DateTime now    = DateTime.Now.ToUniversalTime();
                    Marker   marker = new Marker(markerData.markerId,
                                                 markerData.markerDescriptor, markerData.markerCustomData,
                                                 DateTime.Parse(markerData.markerUpdateDate), now, now,
                                                 markerData.publishedFrom != null ? (DateTime?)DateTime.Parse(markerData.publishedFrom) : null,
                                                 markerData.publishedTo != null ? (DateTime?)DateTime.Parse(markerData.publishedTo) : null,
                                                 markerData.cacheEnabled,
                                                 new MarkerDatabase(markerData.markerDatabase.id, markerData.markerDatabase.code,
                                                                    markerData.markerDatabase.customData, markerData.markerDatabase.cloud, now, now),
                                                 markerData.arLogoEnabled);

                    SaveLocalMarker(marker, isRecognitionManagerRunning, true, false);
                }
            }
            PikkartARCore.SyncMarkersWithFolder();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Web service request coroutine.
        /// </summary>
        /// <param name="url">URL.</param>
        /// <param name="requestBody">Request body.</param>
        /// <param name="callbackWithResponse">Callback with response.</param>
        /// <param name="errorCallback">Error callback.</param>
        /// <typeparam name="T">Response type.</typeparam>
        public IEnumerator CallWS <T> (
            string url,
            Dictionary <string, string> requestBody = null,
            SuccessCallbackWithResponse <T> callbackWithResponse = null,
            ErrorCallback errorCallback = null)
        {
            m_www = null;
            yield return(0);

            byte[] requestBodyBytes        = null;
            byte[] escapedRequestBodyBytes = null;
            if (requestBody != null)
            {
                requestBodyBytes        = NetUtilites.GetRequestBody(requestBody);
                escapedRequestBodyBytes = NetUtilites.GetEscapedRequestBody(requestBody);
            }
            yield return(0);

            Dictionary <string, string> headers = NetUtilites.GetHeaders(
                requestBodyBytes == null ? GET : POST,
                new Uri(url).PathAndQuery,
                requestBodyBytes);

            yield return(0);

            m_www = new WWW(url, escapedRequestBodyBytes, headers);

            PikkartARHelper.Instance.LaunchCoroutine(StartTimeout());
            yield return(0);

#if UNITY_IPHONE
            while (m_www != null && !m_www.isDone)
            {
                yield return(null);
            }
#else
            yield return(m_www);            // Cannot be interrupted by m_www.Dispose() on iOS
#endif

            if (m_www == null)
            {
                Debug.LogWarning("WWW timed out!");
                if (errorCallback != null)
                {
                    errorCallback("timeout");
                }
            }
            else
            {
                if (m_www.error == null || m_www.error.Length == 0)
                {
                    //Debug.Log ("WWW Ok: " + m_www.text);
                    try {
                        WSResponse response = JsonUtilities.ToObject <WSResponse> (m_www.text);

                        //Debug.Log ("CallWS deserialized response to object");
                        if (response.result.code == 200)
                        {
                            //Debug.Log ("Response result code is 200");
                            T specificResponse = JsonUtilities.ToObject <T> (m_www.text);
                            //Debug.Log ("CallWS deserialized response to specific object");
                            if (callbackWithResponse != null)
                            {
                                callbackWithResponse(specificResponse);
                            }
                        }
                        else
                        {
                            Debug.LogWarning(response.result.message);
                            if (errorCallback != null)
                            {
                                errorCallback(response.result.message);
                            }
                        }
                    } catch (Exception e) {
                        Debug.LogError("CallWS exception catched: " + e.Message);
                        if (errorCallback != null)
                        {
                            errorCallback(e.Message);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("WWW Error: " + m_www.error);
                    if (errorCallback != null)
                    {
                        errorCallback(m_www.error);
                    }
                }
            }

            yield return(0);

            ClearWWW();
        }