Search Unity

Help with new Unity 2017 Sprite Atlas.

Discussion in '2D' started by edaw22, Nov 22, 2017.

  1. edaw22

    edaw22

    Joined:
    Aug 20, 2012
    Posts:
    14
    Hey all, question regarding new Sprite Atlas asset.

    In my game I have a series of sprites that represent paint splats. They are used in two ways: when a paint splatter is spawned, a sprite renderer displays the selected splat on the screen, but a separate function also uses to the source texture of the selected splat to perform some scoring calculations. Difficult to explain, but suffice to say the splat sprites are used for display as well as for their source texture.

    Up until now I have been calling Sprite.Texture to access the source texture of the sprite and this works fine. However for performance I would like to Atlas these sprites and would like to use Unity's new Sprite Atlas asset to do so. However as per the documentation, when I try to access a selected sprites texture, the whole atlas is returned, which completely screws up my calculations.

    My question is, is there any way to access the original source texture of an atlased sprite, or is there any way to find the location/offset within the atlas of a given sprite so I can calculate which portion of the returned atlas I need to process?

    Any assistance with this would be much appreciated, as it has taken up far more time than it should.
     
  2. edaw22

    edaw22

    Joined:
    Aug 20, 2012
    Posts:
    14
    I've also thought about storing a separate array of the sprites in the inspector for grabbing the textures from. But there appears to be no guarantee of the order that Atlas.GetSprites() will return the sprite array in. Which means I would need to sort my secondary sprite array into the same order as the returned sprite array. this seems very clunky and not ideal as it would have to be sorted by sprite name I imagine.
     
  3. edaw22

    edaw22

    Joined:
    Aug 20, 2012
    Posts:
    14
    No one has any idea at all about how I could approach this? Any Unity staff around who could give me an idea if this is possible, or if there is a reasonable work around?