Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Access RuntimeSpriteAtlas from sprite

Discussion in '2D Experimental Preview' started by lth3726381, Aug 25, 2016.

  1. lth3726381

    lth3726381

    Joined:
    Oct 15, 2013
    Posts:
    9
    WIth the new sprite atlas tool , we do not need a custom scriptObject to manager sprite any more,it can be very convenient,good job!~
    But in some case,we need to known which atlas does the sprite belong to,and we don't want to find the sprite in atlases on by one .If there are some property like sprite.getAtals will be perfect.
    btw:NGUI's atlas and spite provided this function.
    Thanks.
    lth
     
  2. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Thanks. That's a good suggestion.
     
  3. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    Hey lth, it's not a difficult thing to add a new API in Sprite to find out which atlas it packed into, but I am curious what is your use case for it? Are you intended to use it during Editor or just Runtime?
     
  4. lth3726381

    lth3726381

    Joined:
    Oct 15, 2013
    Posts:
    9
    Sorry for my late response.
    In my case , I use this feature in my localizion framewok,my atlas and sprites are localized,I have one atlas for one language,when the language changed ,all sprites in one atlas will be replace by another.I use the "atlas name + language" to find the new localized "atlas assets"(it's a custom scriptObject at present) in Resources folder.So, I need to get atlas and atlas name from origin sprite.To avoid find which atlas assets contain this sprite one by one ,I write a custom script to record the atlas name....It is hard to use.
    It might not commonly used for most user,But it can provide more possibilities and convenient.
    Thanks.
     
  5. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    Understood. At this moment, this feature is not handling your situation yet. When you mentioned localisation, I assume your sprite is a different sprite, e.g. japanese wording signboard vs english wording signboard, which sometime require different size / mesh. In your existing workflow, are you swapping the Sprite?

    In the next version of Sprite Atlas, we are providing ability to chose certain atlas from a selection of atlases the sprite belongs to. The limitation will be the Sprite need to be part of the Atlas, which I think still not able to solve your problem

    For example : You have a japaneseSignboard.png and a englishSignboard.png which made 2 different Texture asset in Unity. Then you created 2 different Atlases : signboard_jpn.spriteatlas (which take japaneseSignboard.png) & signboard_eng.spriteatlas (which take englishSignboard.jpg). Later you create a SpriteRenderer in the scene which originally take in the englishSignboard Sprite and wish to change it to a Japanese version later in runtime.

    Now, imagine you have the reference to the englishSignboard Sprite object during runtime, and assign the signboard_jpn.spriteatlas to it at the beginning of the scene. It will not work because englishSignboard Sprite is never part of signboard_jpn.spriteatlas. The correct way to change it to Japanese version is swap the SpriteRenderer.sprite to japaneseSignboard Sprite object. Which either you have reference of it from custom script or acquire it from signboard_jpn.spriteatlas.

    There is a silver lining though. In the next version, we will introduce a tag to each atlas and Sprite will store all the atlas's tag that it belongs to. You might make use of this tag later to identify the atlas group a Sprite belongs to and do the Sprite swap.

    Thank you for sharing your work flow. We are still gathering feedbacks and use cases and will certainly record yours into our development backlog.