jswigart
Topic Author
Posts: 11
Joined: 14 Mar 2019, 02:35

Runtime resource registration

25 Jun 2019, 06:26

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
NoesisTextureProvider.instance.Register("URI_TestImage", new Texture2D(100, 100, TextureFormat.ARGB32, false));
But I don't know how to register this URI with a key in a resource dictionary dynamically.

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
NoesisUnity.AppResources["TestImage"] = "URI_TestImage";
I get this error
[noesis] Can't modify ResourceDictionary when loaded from a Source
So is there another way to dynamically register resource dictionary content?

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?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1610
Joined: 22 Dec 2011, 19:20

Re: Runtime resource registration

25 Jun 2019, 11:50

why is the ResourceDictionary loaded by LoadApplicationResources not accessible by default?
We have an open issue about that: #1505, the Application.Resources is something we will expose in a future release.
I get this error: "[noesis] Can't modify ResourceDictionary when loaded from a Source"
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.

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:
UnityEngine.Texture2D texture = ... dynamically created or loaded in Unity;
Noesis.Image image = new Noesis.Image { Source = new Noesis.TextureSource(texture)};
 
jswigart
Topic Author
Posts: 11
Joined: 14 Mar 2019, 02:35

Re: Runtime resource registration

25 Jun 2019, 15:09

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.
 
User avatar
jsantos
Site Admin
Posts: 2538
Joined: 20 Jan 2012, 17:18
Contact:

Re: Runtime resource registration

26 Jun 2019, 14:33

Just for confirmation, the missing feature is exposing a writable global resource dictionary right?
 
jswigart
Topic Author
Posts: 11
Joined: 14 Mar 2019, 02:35

Re: Runtime resource registration

27 Jun 2019, 00:29

Yes
 
User avatar
jsantos
Site Admin
Posts: 2538
Joined: 20 Jan 2012, 17:18
Contact:

Re: Runtime resource registration

27 Jun 2019, 12:55

Right, you can track this feature in #1505. We added it in the 2.3 roadmap.

Who is online

Users browsing this forum: No registered users and 2 guests