Runtime resource registration
I am working on an app that is meant to load a bunch of resources from the file system(user generated content), so the content won't initially be in any resource dictionaries during startup. I need to know how to register new content with the system such that it can be used by Noesis.
It seems that I can register a texture using this for example
I tried exposing the resource dictionary created inside LoadApplicationResources through a static field but when I try to add new content with it, such as
Further, why is the ResourceDictionary loaded by LoadApplicationResources not accessible by default?
Is there a way to use uri paths and skip the resource dictionary entirely?
It seems that I can register a texture using this for example
But I don't know how to register this URI with a key in a resource dictionary dynamically.NoesisTextureProvider.instance.Register("URI_TestImage", new Texture2D(100, 100, TextureFormat.ARGB32, false));
I tried exposing the resource dictionary created inside LoadApplicationResources through a static field but when I try to add new content with it, such as
I get this errorNoesisUnity.AppResources["TestImage"] = "URI_TestImage";
So is there another way to dynamically register resource dictionary content?[noesis] Can't modify ResourceDictionary when loaded from a Source
Further, why is the ResourceDictionary loaded by LoadApplicationResources not accessible by default?
Is there a way to use uri paths and skip the resource dictionary entirely?
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: Runtime resource registration
We have an open issue about that: #1505, the Application.Resources is something we will expose in a future release.why is the ResourceDictionary loaded by LoadApplicationResources not accessible by default?
This error is not very clear, it means that the ResourceDictionary is in a read-only state. I verified that this is not correct compared to WPF, as application resource dictionary can be modified. We will fix that as part of previous issue also.I get this error: "[noesis] Can't modify ResourceDictionary when loaded from a Source"
Anyway, if you only want to load runtime textures in Noesis you can do that by creating a TextureSource from unity's Texture object, and then assign it to an Image or ImageBrush:
Code: Select all
UnityEngine.Texture2D texture = ... dynamically created or loaded in Unity;
Noesis.Image image = new Noesis.Image { Source = new Noesis.TextureSource(texture)};
Re: Runtime resource registration
Thanks. I've finally figured out how to runtime load textures as you describe, but will definately need to do other resource types in the near future. Any ETA on that? Even my textures I'd like to atlas and make image brushes for, which will presumably require runtime registration.
Re: Runtime resource registration
Just for confirmation, the missing feature is exposing a writable global resource dictionary right?
Re: Runtime resource registration
Right, you can track this feature in #1505. We added it in the 2.3 roadmap.
Who is online
Users browsing this forum: Google [Bot] and 53 guests