-
- tylerwsavatronix
- Posts: 13
- Joined:
Unity advanced use: Loading all UI at runtime from external source
Hi there,
We have a fairly advanced use case where, to enable robust mod support we're building our game using as close to the same process as we envision modders will also use (highly modular design, loading and converting assets at runtime from external locations, etc... etc...). The way we're planning for this is to not have any of these dynamic assets be directly assets in Unity itself, but probably streaming assets for our build (and subfolders in a /mods directory for modders).
Modders (and by extension us) should be able to modify existing UI via XAML manipulation (adding, editing, etc..) and/or add entirely new UI elements and their own custom user controls using blend or any other text editor, without having to use Unity itself in any way.
Modifying XML/XAML in memory before loading it is itself not a problem, generally speaking (there's a few different standards for manipulating XML based stuff in memory and then loading that). I have read here on the forums that things like dependencies won't work this way (using LoadXAML/ParseXAML) and am not sure if that's still the case, and if it is how that could be resolved.
My questions are,
Is this possible with Noesis?
If so what is the best way to go about reaching this goal using Noesis?
If dependencies can't be resolved automatically, is there some way to do this manually?
-----
Supplemental Info
It might make more sense if I give a use case for kind of how we expect to be able to do these things.
Modifying existing:
The user would create a diff XML file following https://www.rfc-editor.org/rfc/rfc5261, at runtime our app would load the original in memory (probably via System.XML) and then iterate through all mod folders, patching the XML/XAML as needed and then load that result as the final UI XAML. The existing might be our MainView.XAML of any of the user controls we're creating.
Creating New:
User would use blend or whatever other tools they desire to create their custom user controls, along with creating and compiling an assembly for the accompanying code (to be loaded at runtime by us). They would diff in (see above) their user control so that it appears where they want it (for example, appending their new user control to the end of a list view or whatever to have their new menu button appear in game).
We have a fairly advanced use case where, to enable robust mod support we're building our game using as close to the same process as we envision modders will also use (highly modular design, loading and converting assets at runtime from external locations, etc... etc...). The way we're planning for this is to not have any of these dynamic assets be directly assets in Unity itself, but probably streaming assets for our build (and subfolders in a /mods directory for modders).
Modders (and by extension us) should be able to modify existing UI via XAML manipulation (adding, editing, etc..) and/or add entirely new UI elements and their own custom user controls using blend or any other text editor, without having to use Unity itself in any way.
Modifying XML/XAML in memory before loading it is itself not a problem, generally speaking (there's a few different standards for manipulating XML based stuff in memory and then loading that). I have read here on the forums that things like dependencies won't work this way (using LoadXAML/ParseXAML) and am not sure if that's still the case, and if it is how that could be resolved.
My questions are,
Is this possible with Noesis?
If so what is the best way to go about reaching this goal using Noesis?
If dependencies can't be resolved automatically, is there some way to do this manually?
-----
Supplemental Info
It might make more sense if I give a use case for kind of how we expect to be able to do these things.
Modifying existing:
The user would create a diff XML file following https://www.rfc-editor.org/rfc/rfc5261, at runtime our app would load the original in memory (probably via System.XML) and then iterate through all mod folders, patching the XML/XAML as needed and then load that result as the final UI XAML. The existing might be our MainView.XAML of any of the user controls we're creating.
Creating New:
User would use blend or whatever other tools they desire to create their custom user controls, along with creating and compiling an assembly for the accompanying code (to be loaded at runtime by us). They would diff in (see above) their user control so that it appears where they want it (for example, appending their new user control to the end of a list view or whatever to have their new menu button appear in game).
Re: Unity advanced use: Loading all UI at runtime from external source
Modding is supported in NoesisGUI in a very natural way and there are many games already exposing it (for example this mod for BG3).
Right now in Unity, you can load XAMLs from memory using ParseXaml but if this XAML is using resources (images, fonts) we won't find them if they are not in your project (and imported by Unity).
But we could implement callbacks in our resource providers, just in case we can't find the resource you can load it manually (for example using UnityWebRequestTexture).
Please, let me know how this sounds to you.
Right now in Unity, you can load XAMLs from memory using ParseXaml but if this XAML is using resources (images, fonts) we won't find them if they are not in your project (and imported by Unity).
But we could implement callbacks in our resource providers, just in case we can't find the resource you can load it manually (for example using UnityWebRequestTexture).
Please, let me know how this sounds to you.
-
- tylerwsavatronix
- Posts: 13
- Joined:
Re: Unity advanced use: Loading all UI at runtime from external source
Yeah, a callback would probably be a good way to handle it. Since we'll probably be storing loaded assets like those in an in memory DB, our handler would just need to, in theory, find it in there and return it.Modding is supported in NoesisGUI in a very natural way and there are many games already exposing it (for example this mod for BG3).
Right now in Unity, you can load XAMLs from memory using ParseXaml but if this XAML is using resources (images, fonts) we won't find them if they are not in your project (and imported by Unity).
But we could implement callbacks in our resource providers, just in case we can't find the resource you can load it manually (for example using UnityWebRequestTexture).
Please, let me know how this sounds to you.
Should I do up a ticket in the bugtracker?
Re: Unity advanced use: Loading all UI at runtime from external source
Yes, please, file a ticket about this. Thank you!
-
- tylerwsavatronix
- Posts: 13
- Joined:
Re: Unity advanced use: Loading all UI at runtime from external source
Apologies for the delay, it's been a hectic couple of weeks.Yes, please, file a ticket about this. Thank you!
The issue's been posted.
As a side note, is a possible current workaround to bind to a property on the viewmodel (e.g. Texture2d MyImage on the viewmodel) that we'd set on the viewmodel at runtime instead of using resources and might that actually be a better solution for dynamic content?
-
-
sfernandez
Site Admin
- Posts: 2794
- Joined:
Re: Unity advanced use: Loading all UI at runtime from external source
Yes, you can bind to Texture2D properties exposed in the ViewModel without problems. But I don't see how you plan to use it for dynamic content... would it be something like binding to a dictionary in your view model with the new textures?As a side note, is a possible current workaround to bind to a property on the viewmodel (e.g. Texture2d MyImage on the viewmodel) that we'd set on the viewmodel at runtime instead of using resources and might that actually be a better solution for dynamic content?
-
- tylerwsavatronix
- Posts: 13
- Joined:
Re: Unity advanced use: Loading all UI at runtime from external source
Depends on what the image is. If it's, say, static UI (part of the hud or a menu, whatever) it'd be a single texture2d property. Like, say, a heart icon serving as a label to a health bar.Yes, you can bind to Texture2D properties exposed in the ViewModel without problems. But I don't see how you plan to use it for dynamic content... would it be something like binding to a dictionary in your view model with the new textures?
For list-based content (like an inventory) it would probably have to be a list of items that include the texture2d as a property on the specific item data.
The specific asset to use would be determined when loading the game as part of the mod-loading system. e.g. if a mod wants to replace the above mentioned heart icon, they'd just provide their own and when the game is loading it would load that instead of ours (probably via in mem database). We'd then inject that either via constructor or property injection to wherever needed.
-
-
sfernandez
Site Admin
- Posts: 2794
- Joined:
Re: Unity advanced use: Loading all UI at runtime from external source
Understood, that makes sense then. I think that could be a good approach for allowing custom textures in mods.The specific asset to use would be determined when loading the game as part of the mod-loading system. e.g. if a mod wants to replace the above mentioned heart icon, they'd just provide their own and when the game is loading it would load that instead of ours (probably via in mem database). We'd then inject that either via constructor or property injection to wherever needed.
Who is online
Users browsing this forum: Bing [Bot] and 8 guests