MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Loading resources at run-time

05 Oct 2014, 04:47

Hi,

One of the requirements for the project I'm working on, is to be able to load in XAML files dynamically at runtime, from an outside source. The idea is to support new views being brought in, similar to AssetBundles.

I've managed to write a script that allows me to build the XAML files using Unity's command line runner, and the files that are created in the StreamingAssets folder are generated properly. We plan to put this on our build server so when new commits are made to the XAML, changes are automatically built and zipped up and uploaded to one of our servers, where we expose an API to download them.

Now the problem is trying to bring those assets in at run-time. Because the StreamingAssets folder is read-only at runtime, I'm not sure if we are able to load the data files in at runtime. Is there a way to load the Data files in dynamically while the game is already running?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Loading resources at run-time

06 Oct 2014, 17:36

In v1.1, NoesisGUI loads the file guids.txt at init time. This table is used to translate from xaml uris to internal GUIDs. That is the reason you are having problems to load files in dynamically while the game is already running.

We changed this in v1.2, there is no table. So, you could copy a new xaml (preprocessed) into the streaming assets folder and loat it at runtime.

I think this is what you are after, aren't you?
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: Loading resources at run-time

06 Oct 2014, 18:25

This is what I would like, yes, however, if there is no mapping from filename -> guid anymore, does that mean guids will stay static? Or will the files in StreamingAssets be the same name as the original ource files? Also, how would we go about downloading the resources at run-time and loading it into the StreamingAssets folder? I thought the StreamingAssets folder was read-only? (from what I've heard. Haven't actually tried it though)

EDIT: It seems that might be the case for Android because of the JAR files. Since we don't plan to ship with the views in the StreamingAssets folder, and would like to have them downloaded and loaded on run-time, is there a way to get the views to be loaded from another folder?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Loading resources at run-time

06 Oct 2014, 18:57

Yes, in v1.2 the files inside StreamingAssets folder have the name of the source (we experimented with the idea of naming them with the GUID given by Unity, but we found problems and decided to go with this solution in 1.2). That is not problem. But it is true that the StreamingAssets folder is expected to be read only.

The solution here could be exposing a new c# function to add new folders (this functionality is available in c++ already) where resources are looked for.

What happen if the xaml are stored inside an AssetBundle. Where does Unity store those files?
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: Loading resources at run-time

06 Oct 2014, 19:11

I haven't tried assetbundles yet, and is next on my list to try. AFAIK, they are loaded in and not really extracted anywhere, and you're expected to load from it using Resource.Load<> which isn't useful in this case.

However, I did notice this line in the NoesisGUISystem.cs file (v1.1.11):
int deviceType = Noesis_Init(UnityEngine.Application.streamingAssetsPath,
            UnityEngine.Application.dataPath + "/Plugins");
Is the first parameter the path where the resources are loaded from? If so, then I could modify that to point to the location where the generated xaml resources reside, and that should solve all the problems.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Loading resources at run-time

06 Oct 2014, 19:30

Yes, you can change the root mount point that way. If you do that you will have to move all the resources to the new location.

Although, in v1.1 you still have the guids.txt problem commented above.
 
MrHayato
Topic Author
Posts: 36
Joined: 19 Sep 2014, 21:29

Re: Loading resources at run-time

06 Oct 2014, 21:40

Great. I should be able to modify the guids file as I need to, but I think changing that mounting point is a great step for us.

Thanks!

Who is online

Users browsing this forum: No registered users and 1 guest