public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider) { m_PI = provideHandle; m_PI.SetWaitForCompletionCallback(WaitForCompletionHandler); provideHandle.SetProgressCallback(GetPercentComplete); m_Provider = rawProvider; // override input options with options from Location if included if (m_PI.Location.Data is ProviderLoadRequestOptions providerData) { m_IgnoreFailures = providerData.IgnoreFailures; m_Timeout = providerData.WebRequestTimeout; } else { m_IgnoreFailures = rawProvider.IgnoreFailures; m_Timeout = 0; } 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 = ConvertText(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); m_Complete = true; } else if (ResourceManagerConfig.ShouldPathUseWebRequest(path)) { SendWebRequest(path); } 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) { m_PI.Complete <object>(null, true, exception); m_Complete = true; } else { exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path)); m_PI.Complete <object>(null, false, exception); m_Complete = true; } } }
public void Start(ProvideHandle provideHandle, float loadDelay) { m_Loaded = false; m_ProvideHandle = provideHandle; m_ProvideHandle.SetWaitForCompletionCallback(WaitForCompletionHandler); if (loadDelay < 0) { LoadImmediate(); } else { DelayedActionManager.AddAction((Action)LoadImmediate, loadDelay); } }
public void Start(ProvideHandle provideHandle) { provideHandle.SetProgressCallback(ProgressCallback); provideHandle.SetWaitForCompletionCallback(WaitForCompletionHandler); subObjectName = null; m_ProvideHandle = provideHandle; m_RequestOperation = null; List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list m_ProvideHandle.GetDependencies(deps); var bundleResource = LoadBundleFromDependecies(deps); if (bundleResource == null) { m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location)); } else { var bundle = bundleResource.GetAssetBundle(); if (bundle == null) { m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location)); } else { var assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location); if (m_ProvideHandle.Type.IsArray) { m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetElementType()); } else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition()) { m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(assetPath, m_ProvideHandle.Type.GetGenericArguments()[0]); } else { if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey)) { subObjectName = subKey; m_RequestOperation = bundle.LoadAssetWithSubAssetsAsync(mainPath, m_ProvideHandle.Type); }
public void Start(ProvideHandle provideHandle) { provideHandle.SetProgressCallback(ProgressCallback); provideHandle.SetWaitForCompletionCallback(WaitForCompletionHandler); subObjectName = null; m_ProvideHandle = provideHandle; m_RequestOperation = null; List <object> deps = new List <object>(); // TODO: garbage. need to pass actual count and reuse the list m_ProvideHandle.GetDependencies(deps); var bundleResource = LoadBundleFromDependecies <IAssetBundleResource>(deps); if (bundleResource == null) { m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location)); } else { m_AssetBundle = bundleResource.GetAssetBundle(); if (m_AssetBundle == null) { m_ProvideHandle.Complete <AssetBundle>(null, false, new Exception("Unable to load dependent bundle from location " + m_ProvideHandle.Location)); return; } var assetBundleResource = bundleResource as AssetBundleResource; if (assetBundleResource != null) { m_PreloadRequest = assetBundleResource.GetAssetPreloadRequest(); } if (m_PreloadRequest == null || m_PreloadRequest.isDone) { BeginAssetLoad(); } else { m_PreloadRequest.completed += operation => BeginAssetLoad(); } } }
public void Start(ProvideHandle provideHandle, TextDataProvider rawProvider, bool ignoreFailures) { m_PI = provideHandle; m_PI.SetWaitForCompletionCallback(WaitForCompletionHandler); provideHandle.SetProgressCallback(GetPercentComplete); m_Provider = rawProvider; if ((m_PI.Location.Data as ProviderLoadRequestOptions) != null) { m_IgnoreFailures = (m_PI.Location.Data as ProviderLoadRequestOptions).IgnoreFailures; } else { 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 = ConvertText(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); m_Complete = true; } 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) { m_PI.Complete <object>(null, true, exception); m_Complete = true; } else { exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path)); m_PI.Complete <object>(null, false, exception); m_Complete = true; } } }