Search Unity

Using Addressable for Runtime Themes?

Discussion in 'Addressables' started by helloworldgames, Jul 26, 2018.

  1. helloworldgames

    helloworldgames

    Joined:
    Mar 16, 2017
    Posts:
    60
    Hi there,

    I'm building game which will have different themese and user will b able to switch between them on runtime. Idea is game is launched, and on first scene selects which theme is selected and then show both graphics (as addressable assets) and text colors based on the theme on any next scenes.

    Is this something achieveable with addressable?

    Thanks
     
  2. Meneghetti

    Meneghetti

    Joined:
    Aug 26, 2014
    Posts:
    3
    I just started trying Addressables, so I can be far off the road here, but I think you can make ScriptableObjects assets that holds information of Colours and Images and then download and apply them via AddressableAssets. If it works or you can find another solution, let us know! :)
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Hi, yes what you're after is achievable via Addressables. There are a number of solutions that you could implement by extending our system (some of which we intend to add ourselves later), but I'll just mention what works out of the box now (the other systems could be a little more straightforward, but until we provide them, it's not worth going into here)

    When loading through Addressables, you can provide a single lookup key (address or label) or multiple. If providing multiple, you can ask that Addressables returns only the items that match all keys.
    My recommendation here is to give all assets that serve the same purpose the same address. So your main background in each theme could be called "background". Then give all assets in a theme a label tied to that theme. That would support something like this:

    Code (CSharp):
    1.  
    2.         string themeName = "sunny";
    3.         Addressables.LoadAssets<IResourceLocation>(
    4.             new List<object> { "background", themeName },
    5.             null,
    6.             Addressables.MergeMode.Intersection
    7.           ).Completed += op =>
    8.         {
    9.             foreach (var loc in op.Result)
    10.                 Addressables.Instantiate<GameObject>(loc);
    11.         };
    Hope that helps,
    Bill
     
  4. Dottorhouse

    Dottorhouse

    Joined:
    May 29, 2018
    Posts:
    1
    Hi Bill,
    first of all congratulations for this new addressable asset system, that's a great improvement and also something I needed so much for my ongoing project. I need, just like OP, this "theme" functionality in my game. The approach you described in your post is clear and would work on most scenarios I need.

    However, I'm not sure about what's the best way to tackle some scenarios in my mobile game:

    1) UI elements.
    How should I manage them? If I had to turn an UI.Image into a "themed" component, what's the best strategy? Should I make the Sprite addressable? Or maybe make the whole UI.Image object a prefab, and make that addressable? That would increase dramatically the number of prefabs.
    I thought that making the lowest level resource an addressable (the Sprite / png itself), could be the best approach.

    2) UI elements, and their default appearance in Scene View.
    Depending on how scenario 1 is managed, I'm afraid that in Scene View I could end up seeing empty / white images and UI components.
    Of course I want to avoid those side effects, and I'd rather see at least one default theme. Best solution would be to be able to switch themes also in Scene View to see if everything looks fine without actually running the game.

    3) In-game labels.
    I would use addressables to localize some labels, is that a good idea in your opinion? My original plan was to use some sort of dictionary file, a txt, csv, json, anything would be fine. From that file, I would get the localized strings by loading the addressable with LoadAsset<TextAsset>. This seems to work right now; do you see any problem with this approach?

    4) One-time full bundle download.
    I guess they are not called bundles anymore, is it groups now? However, when the user switch the theme, I want it to be a one-time only action. The old theme is unloaded and - ideally - deleted to use less space as possible, while the new theme is loaded. Nothing unusual: blocking pop-up, download percentage shows up, when everything is downloaded the new theme is loaded.

    I know that quite some stuff, maybe a bit too specific, but I'm kinda stuck since the addressable system is quite new. I'm afraid that if I choose the wrong strategy now, I might have to rewrite lots of code later. Thanks for taking time to read this :)
     
    Last edited: Aug 6, 2018
  5. Soulside

    Soulside

    Joined:
    Nov 1, 2018
    Posts:
    30
    @unity_bill, we are also very interested to see answers for the questions above!
     
  6. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311