public void OnEnable() { editConfigPath = Path.Combine(Application.dataPath, "../ProjectSettings/ResourceManagerConfig.json"); if (File.Exists(editConfigPath)) { string editConfigMsg = File.ReadAllText(editConfigPath); editConfig = JsonUtility.FromJson<ResourceManagerConfig>(editConfigMsg); } if (null == editConfig) { editConfig = new ResourceManagerConfig(); } if (_lst == null) { Load(); } }
protected override void SendWebRequest(string path) { string pathWithFakeRemoteFolder = k_Pattern.Replace(ResourceManagerConfig.StripQueryParameters(path), m_FakeRemoteFolder); string fileText = null; Exception ex = null; if (File.Exists(pathWithFakeRemoteFolder)) { fileText = File.ReadAllText(pathWithFakeRemoteFolder); } else { ex = new Exception($"{nameof(TextDataProvider)} unable to load from url {path}"); } CompleteOperation(fileText, ex); }
/// <inheritdoc/> public override void Provide(ProvideHandle providerInterface) { var atlas = providerInterface.GetDependency <SpriteAtlas>(0); if (atlas == null) { providerInterface.Complete <Sprite>(null, false, new System.Exception($"Sprite atlas failed to load for location {providerInterface.Location.PrimaryKey}.")); return; } var key = providerInterface.ResourceManager.TransformInternalId(providerInterface.Location); ResourceManagerConfig.ExtractKeyAndSubKey(key, out string mainKey, out string subKey); string spriteKey = string.IsNullOrEmpty(subKey) ? mainKey : subKey; var sprite = atlas.GetSprite(spriteKey); providerInterface.Complete(sprite, sprite != null, sprite != null ? null : new System.Exception($"Sprite failed to load for location {providerInterface.Location.PrimaryKey}.")); }
public bool TryBeginOperation(ProvideHandle provideHandle) { retries = 0; assetBundle = null; downloadHandler = null; this.provideHandle = provideHandle; string path = provideHandle.ResourceManager.TransformInternalId(provideHandle.Location); if (!ResourceManagerConfig.ShouldPathUseWebRequest(path)) { return(false); } options = provideHandle.Location.Data as AssetBundleRequestOptions; provideHandle.SetProgressCallback(PercentComplete); BeginOperation(); return(true); }
public bool Load(long localBandwidth, long remoteBandwidth) { if (Time.unscaledTime > m_LastUpdateTime) { m_BytesLoaded += (long)Math.Ceiling((Time.unscaledTime - m_LastUpdateTime) * localBandwidth); m_LastUpdateTime = Time.unscaledDeltaTime; } if (m_BytesLoaded < m_AssetInfo.Size) { return(true); } if (!(Context is IResourceLocation)) { return(false); } var assetPath = (Context as IResourceLocation).InternalId; var t = typeof(TObject); if (t.IsArray) { SetResult(ResourceManagerConfig.CreateArrayResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { SetResult(ResourceManagerConfig.CreateListResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))); } else { var mainType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (mainType == typeof(Texture2D) && typeof(TObject) == typeof(Sprite)) { SetResult(AssetDatabase.LoadAssetAtPath(assetPath, typeof(TObject)) as TObject); } else { SetResult(AssetDatabase.LoadAssetAtPath(assetPath, mainType) as TObject); } } InvokeCompletionEvent(); return(false); }
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 bool Load(long localBandwidth, long remoteBandwidth, float unscaledDeltaTime) { if (IsDone) { return(false); } var now = m_LastUpdateTime + unscaledDeltaTime; if (now > m_LastUpdateTime) { m_BytesLoaded += (long)Math.Ceiling((now - m_LastUpdateTime) * localBandwidth); m_LastUpdateTime = now; } if (m_BytesLoaded < m_AssetInfo.Size) { return(true); } if (!(Context is IResourceLocation)) { return(false); } var location = Context as IResourceLocation; var assetPath = m_AssetInfo.m_AssetPath; object result = null; var pt = m_provideHandle.Type; if (pt.IsArray) { result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath)); } else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition()) { result = ResourceManagerConfig.CreateListResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath)); } else { if (ResourceManagerConfig.ExtractKeyAndSubKey(location.InternalId, out string mainPath, out string subKey)) { result = AssetDatabaseProvider.LoadAssetSubObject(assetPath, subKey, pt); }
private void ActionComplete(AsyncOperation obj) { object result = null; if (m_RequestOperation != null) { if (m_ProvideHandle.Type.IsArray) { result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, m_RequestOperation.allAssets); } else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition()) { result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, m_RequestOperation.allAssets); } else { if (string.IsNullOrEmpty(subObjectName)) { result = (m_RequestOperation.asset != null && m_ProvideHandle.Type.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null; } else { if (m_RequestOperation.allAssets != null) { foreach (var o in m_RequestOperation.allAssets) { if (o.name == subObjectName) { if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType())) { result = o; break; } } } } } } } m_ProvideHandle.Complete(result, result != null, null); }
public override void Provide(ProvideHandle pi) { Type t = pi.Type; bool isList = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition(); var internalId = pi.ResourceManager.TransformInternalId(pi.Location); if (t.IsArray || isList) { object result = null; if (t.IsArray) { result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(internalId, t.GetElementType())); } else { result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(internalId, t.GetGenericArguments()[0])); } pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null); } else { if (ResourceManagerConfig.ExtractKeyAndSubKey(internalId, out string mainPath, out string subKey)) { var objs = Resources.LoadAll(mainPath, pi.Type); object result = null; foreach (var o in objs) { if (o.name == subKey) { if (pi.Type.IsAssignableFrom(o.GetType())) { result = o; break; } } } pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null); }
private void BeginOperation() { string path = m_ProvideHandle.Location.InternalId; if (File.Exists(path)) { m_RequestOperation = AssetBundle.LoadFromFileAsync(path, m_Options == null ? 0 : m_Options.Crc); m_RequestOperation.completed += LocalRequestOperationCompleted; } else if (ResourceManagerConfig.ShouldPathUseWebRequest(path)) { var req = CreateWebRequest(m_ProvideHandle.Location); req.disposeDownloadHandlerOnDispose = false; m_RequestOperation = req.SendWebRequest(); m_RequestOperation.completed += WebRequestOperationCompleted; } else { m_RequestOperation = null; m_ProvideHandle.Complete <AssetBundleResource>(null, false, new Exception(string.Format("Invalid path in AssetBundleProvider: '{0}'.", path))); } }
/// <summary> /// Computes the amount of data needed to be downloaded for this bundle. /// </summary> /// <param name="location">The location of the bundle.</param> /// <param name="resourceManager">The object that contains all the resource locations.</param> /// <returns>The size in bytes of the bundle that is needed to be downloaded. If the local cache contains the bundle or it is a local bundle, 0 will be returned.</returns> public virtual long ComputeSize(IResourceLocation location, ResourceManager resourceManager) { var id = resourceManager == null ? location.InternalId : resourceManager.TransformInternalId(location); if (!ResourceManagerConfig.IsPathRemote(id)) { return(0); } var locHash = Hash128.Parse(Hash); #if ENABLE_CACHING if (locHash.isValid) //If we have a hash, ensure that our desired version is cached. { if (Caching.IsVersionCached(new CachedAssetBundle(BundleName, locHash))) { return(0); } return(BundleSize); } #endif //ENABLE_CACHING return(BundleSize); }
private void ActionComplete(AsyncOperation obj) { object result = null; Type t = m_ProvideHandle.Type; if (m_RequestOperation != null) { if (t.IsArray) { result = ResourceManagerConfig.CreateArrayResult(t, m_RequestOperation.allAssets); } if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition()) { result = ResourceManagerConfig.CreateListResult(t, m_RequestOperation.allAssets); } else { result = (m_RequestOperation.asset != null && t.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null; } } m_ProvideHandle.Complete(result, result != null, null); }
/// <inheritdoc/> public override long ComputeSize(IResourceLocation location, ResourceManager resourceManager) { var id = resourceManager == null ? location.InternalId : resourceManager.TransformInternalId(location); if (!ResourceManagerConfig.IsPathRemote(id)) { return(0); } var locHash = Hash128.Parse(Hash); if (!locHash.isValid) { return(BundleSize); } #if ENABLE_CACHING var bundleName = Path.GetFileNameWithoutExtension(id); if (locHash.isValid) //If we have a hash, ensure that our desired version is cached. { if (Caching.IsVersionCached(bundleName, locHash)) { return(0); } return(BundleSize); } else //If we don't have a hash, any cached version will do. { List <Hash128> versions = new List <Hash128>(); Caching.GetCachedVersions(bundleName, versions); if (versions.Count > 0) { return(0); } } #endif //ENABLE_CACHING return(BundleSize); }
private void LoginControl_ConnectRequest(object sender, System.EventArgs e) { // load legacy resources before connecting if (!ResourceManager.Initialized) { // initialize the resourcemanagerconfig ResourceManagerConfig config = new ResourceManagerConfig( Properties.Settings.Default.DownloadVersion, "resource/rsc0000.rsb", "resource/rooms", "resource/objects", "resource/roomtextures", "resource/wavs", "resource/music", "mail"); // init the legacy resources ResourceManager.InitConfig(config); } // start connect to server ServerConnection.Connect(MainForm.LoginControl.Hostname, MainForm.LoginControl.Hostport); }
internal static string GetLoadPath(AddressableAssetGroup group, string name, BuildTarget target) { var bagSchema = group.GetSchema <BundledAssetGroupSchema>(); if (bagSchema == null || bagSchema.LoadPath == null) { Debug.LogError("Unable to determine load path for " + name + ". Check that your default group is not '" + AddressableAssetSettings.PlayerDataGroupName + "'"); return(string.Empty); } string loadPath = bagSchema.LoadPath.GetValue(group.Settings); loadPath = loadPath.Replace('\\', '/'); if (loadPath.EndsWith("/")) { loadPath += name; } else { loadPath = loadPath + "/" + name; } if (!string.IsNullOrEmpty(bagSchema.UrlSuffix)) { loadPath += bagSchema.UrlSuffix; } if (!ResourceManagerConfig.ShouldPathUseWebRequest(loadPath) && !bagSchema.UseUnityWebRequestForLocalBundles) { char separator = PathSeparatorForPlatform(target); if (separator != '/') { loadPath = loadPath.Replace('/', separator); } } return(loadPath); }
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); } }
/// <summary> /// Computes the amount of data needed to be downloaded for this bundle. /// </summary> /// <param name="loc">The location of the bundle.</param> /// <returns>The size in bytes of the bundle that is needed to be downloaded. If the local cache contains the bundle or it is a local bundle, 0 will be returned.</returns> public override long ComputeSize(IResourceLocation loc) { if (!ResourceManagerConfig.IsPathRemote(loc.InternalId)) { // Debug.LogFormat("Location {0} is local, ignoring size", loc); return(0); } var locHash = Hash128.Parse(Hash); if (!locHash.isValid) { // Debug.LogFormat("Location {0} has invalid hash, using size of {1}", loc, BundleSize); return(BundleSize); } #if !UNITY_SWITCH && !UNITY_PS4 var bundleName = Path.GetFileNameWithoutExtension(loc.InternalId); if (locHash.isValid) //If we have a hash, ensure that our desired version is cached. { if (Caching.IsVersionCached(bundleName, locHash)) { return(0); } return(BundleSize); } else //If we don't have a hash, any cached version will do. { List <Hash128> versions = new List <Hash128>(); Caching.GetCachedVersions(bundleName, versions); if (versions.Count > 0) { return(0); } } #endif //!UNITY_SWITCH && !UNITY_PS4 return(BundleSize); }
void LoadImmediate() { if (m_Loaded) { return; } m_Loaded = true; string assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location); object result = null; if (m_ProvideHandle.Type.IsArray) { result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, LoadAssetsWithSubAssets(assetPath)); } else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition()) { result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, LoadAssetsWithSubAssets(assetPath)); } else { if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey)) { result = LoadAssetSubObject(mainPath, subKey, m_ProvideHandle.Type); }
public override void Provide(ProvideHandle pi) { Type t = pi.Type; bool isList = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition(); if (t.IsArray || isList) { object result = null; if (t.IsArray) { result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetElementType())); } else { result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetGenericArguments()[0])); } pi.Complete(result, result != null, null); } else { new InternalOp().Start(pi); } }
public bool Load(long localBandwidth, long remoteBandwidth) { if (Time.unscaledTime > m_LastUpdateTime) { m_BytesLoaded += (long)Math.Ceiling((Time.unscaledTime - m_LastUpdateTime) * localBandwidth); m_LastUpdateTime = Time.unscaledDeltaTime; } if (m_BytesLoaded < m_AssetInfo.Size) { return(true); } if (!(Context is IResourceLocation)) { return(false); } var location = Context as IResourceLocation; var assetPath = m_provideHandle.ResourceManager.TransformInternalId(location); object result = null; var pt = m_provideHandle.Type; if (pt.IsArray) { result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath)); } else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition()) { result = ResourceManagerConfig.CreateListResult(pt, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath)); } else { var i = assetPath.LastIndexOf('['); if (i > 0) { var i2 = assetPath.LastIndexOf(']'); if (i2 < i) { Debug.LogErrorFormat("Invalid index format in internal id {0}", assetPath); } else { var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1)); assetPath = assetPath.Substring(0, i); var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath); foreach (var o in objs) { if (o.name == subObjectName) { if (pt.IsAssignableFrom(o.GetType())) { result = o; break; } } } } } else { var obj = AssetDatabase.LoadAssetAtPath(assetPath, location.ResourceType); result = obj != null && pt.IsAssignableFrom(obj.GetType()) ? obj : null; } } SetResult(result); InvokeCompletionEvent(); return(false); }
/// <summary> /// Overriden initlegacyresources /// </summary> public override void InitLegacyResources() { // initialize the resourcemanagerconfig ResourceManagerConfig config = new ResourceManagerConfig( versionresources, false, false, false, false, false, false, STRINGSFILE, WORKPATH + "rooms", WORKPATH + "objects", WORKPATH + "roomtextures", WORKPATH + "wavs"); // init the legacy resources ResourceManager.InitConfig(config); }
public void ResourceManagerConfigExtractKeyAndSubKey_WhenPassedKey_ReturnsExpectedValue(object key, bool expectedReturn, string expectedMainKey, string expectedSubKey) { Assert.AreEqual(expectedReturn, ResourceManagerConfig.ExtractKeyAndSubKey(key, out string mainKey, out string subKey)); Assert.AreEqual(expectedMainKey, mainKey); Assert.AreEqual(expectedSubKey, subKey); }
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) { if ((m_PI.Location.Data as ProviderLoadOptions)?.FailureSettings == FailureSettings.SilentFail) { m_PI.Complete <object>(null, !m_IgnoreFailures, exception); } else { exception = new Exception(string.Format("Invalid path in " + nameof(TextDataProvider) + " : '{0}'.", path)); m_PI.Complete <object>(null, m_IgnoreFailures, exception); } } else { m_PI.Complete <object>(null, m_IgnoreFailures, exception); } } }
protected override bool IsValidPath(string path) { return(ResourceManagerConfig.ShouldPathUseWebRequest(path)); }