Example #1
0
            private void RequestOperation_completed(AsyncOperation op)
            {
                var       webOp     = op as UnityWebRequestAsyncOperation;
                object    result    = null;
                Exception exception = null;

                if (webOp != null)
                {
                    var webReq = webOp.webRequest;
                    if (string.IsNullOrEmpty(webReq.error))
                    {
                        result = m_Provider.Convert(m_PI.Type, webReq.downloadHandler.text);
                    }
                    else
                    {
                        exception = new Exception(string.Format(nameof(TextDataProvider) + " unable to load from url {0}, result='{1}'.", webReq.url, webReq.error));
                    }
                }
                else
                {
                    exception = new Exception(nameof(TextDataProvider) + " unable to load from unknown url.");
                }

                m_PI.Complete(result, result != null || m_IgnoreFailures, exception);
            }
Example #2
0
            public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures)
            {
                m_PI = provideHandle;
                provideHandle.SetProgressCallback(GetPercentComplete);
                m_Provider       = rawProvider;
                m_IgnoreFailures = ignoreFailures;
                var path = m_PI.ResourceManager.TransformInternalId(m_PI.Location);

                if (File.Exists(path))
                {
#if NET_4_6
                    if (path.Length >= 260)
                    {
                        path = @"\\?\" + path;
                    }
#endif
                    var    text   = File.ReadAllText(path);
                    object result = m_Provider.Convert(m_PI.Type, text);
                    m_PI.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {m_PI.Type} from location {m_PI.Location}.") : null);
                }
                else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
                {
                    UnityWebRequest request = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null);
                    m_RequestQueueOperation = WebRequestQueue.QueueRequest(request);
                    if (m_RequestQueueOperation.IsDone)
                    {
                        m_RequestOperation = m_RequestQueueOperation.Result;
                        if (m_RequestOperation.isDone)
                        {
                            RequestOperation_completed(m_RequestOperation);
                        }
                        else
                        {
                            m_RequestOperation.completed += RequestOperation_completed;
                        }
                    }
                    else
                    {
                        m_RequestQueueOperation.OnComplete += asyncOperation =>
                        {
                            m_RequestOperation            = asyncOperation;
                            m_RequestOperation.completed += RequestOperation_completed;
                        };
                    }
                }
                else
                {
                    Exception exception = null;
                    //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created
                    if (!m_IgnoreFailures)
                    {
                        exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path));
                    }
                    m_PI.Complete <object>(null, m_IgnoreFailures, exception);
                }
            }
 private object ConvertText(string text)
 {
     try
     {
         return(m_Provider.Convert(m_PI.Type, text));
     }
     catch (Exception e)
     {
         if (!m_IgnoreFailures)
         {
             Debug.LogException(e);
         }
         return(null);
     }
 }
            public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures)
            {
                m_PI = provideHandle;
                provideHandle.SetProgressCallback(GetPercentComplete);
                m_Provider       = rawProvider;
                m_IgnoreFailures = ignoreFailures;
                var path = m_PI.Location.InternalId;

                if (File.Exists(path))
                {
#if NET_4_6
                    if (path.Length >= 260)
                    {
                        path = @"\\?\" + path;
                    }
#endif
                    var    text   = File.ReadAllText(path);
                    object result = m_Provider.Convert(m_PI.Type, text);
                    m_PI.Complete(result, result != null, null);
                }
                else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
                {
                    m_RequestOperation            = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null).SendWebRequest();
                    m_RequestOperation.completed += RequestOperation_completed;
                }
                else
                {
                    Exception exception = null;
                    //Don't log errors when loading from the persistentDataPath since these files are expected to not exist until created
                    if (!m_IgnoreFailures)
                    {
                        exception = new Exception(string.Format("Invalid path in RawDataProvider: '{0}'.", path));
                    }
                    m_PI.Complete <object>(null, false, exception);
                }
            }