Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

loading resources from specific folders...

Discussion in '2D' started by lostsoul, Jun 19, 2014.

  1. lostsoul

    lostsoul

    Joined:
    Jun 19, 2014
    Posts:
    2
    Hi All,

    I have created resources for different resolutions for my android game. The resources/sprites are in folders like xhdpi,hdpi,mdpi and ldpi. During design time i pick sprites from xhdpi folder and attach them to spriterenderer manually. My question how do I make it pick hdpi,mdpi,ldpi resources depending on the resolution when the actual apk is built.


    Thanks
     
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    Hey, like you've already said that at design time you are able to know the folder name from where you want to pick the assets, you need to create one string var(pathString) holding the reference of the assets path and set the path depending on the resolution, after that you can use Resources.load(pathString + "/" + "Filename");

    Note: make sure your assets folders reside inside the Resources folder.
     
  3. lostsoul

    lostsoul

    Joined:
    Jun 19, 2014
    Posts:
    2
    So how will this work for all the sprites on the scene. I load few assets dynamically and few hardcoded at design time in the unity ide, for the ones i load dynamically i can pick and choose the resource path but for the ones that are already there in the scene how do I change. Should i create a load script which will go through all the sprites in the scene and change the path before the scene loads ?
     
  4. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    For the assets which you've hardcoded at design time, you can change them at runtime via script by reassigning the sprite. to them.