Author Topic: Is there a way to use multiple sprite sheets on a text object?  (Read 1091 times)

kruncher

  • Newbie
  • *
  • Posts: 7
Hi

Is it possible to override the behavior of the Text Mesh Pro "sprite" tag so that I can lookup the sprite in a custom way?

Code: [Select]
<sprite=xbox_a>
I would like to be able to:
  • Have a collection of sprites spread across several atlas textures.
  • Reference sprites by a string key rather than with a zero-based index. I dislike working with zero-based indices at this level since dependent data is hard to maintain in scenarios where sprites are removed.
  • Use my ordered dictionary asset to describe the library of sprites. This would essentially add a layer of abstraction making it super easy for me to map keys to any sprites that I want.
Perhaps there is a way to do something like the following?

Code: [Select]
public class SpriteLibrarySpriteResolver : TextMeshProSpriteResolver {

    [SerializeField]
    private SpriteLibrary _spriteLibrary;

    public override Sprite ResolveSprite(string key) {
        Sprite sprite;
        _spriteLibrary.TryGetValue(key, out sprite);
        return sprite;
    }

}

Many thanks!
« Last Edit: July 21, 2015, 05:55:14 AM by kruncher »

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #1 on: July 21, 2015, 09:03:40 PM »
The issue with supporting multiple sprite sheets is that a new sub object / mesh and material would be required per sprite sheet. Currently, the text is contained in its own mesh and the sprite into a sub mesh.

Once I add the ability to mix different fonts and material per text object, this might become easier to implement.

In terms of referencing the sprite by name, I just need to add similar functionality to the style sheet where a HashCode is used to find the styles. Basically, I can't use strings due to GC allocations so I need to convert your input string into a HashCode and then scan through the sprite asset to find the sprite that matches that hashcode value. Most of the functionality is inside TMP but I just need to get around to adding it the sprite assets.

kruncher

  • Newbie
  • *
  • Posts: 7
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #2 on: July 22, 2015, 07:00:38 AM »
The inability to reference sprites by name is a bit of a blocker; but I guess I could workaround the other limitation somewhat. Any idea of a time frame as to when these things will become available?

It would be neat if I could specify the sprite name in the data asset rather than relying upon the Sprite.name (which allocates upon access anyhow). This would essentially allow me to map multiple names to the same sprite.
« Last Edit: July 22, 2015, 07:52:49 AM by kruncher »

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #3 on: July 22, 2015, 08:47:17 PM »
The inability to reference sprites by name is a bit of a blocker; but I guess I could workaround the other limitation somewhat. Any idea of a time frame as to when these things will become available?

It would be neat if I could specify the sprite name in the data asset rather than relying upon the Sprite.name (which allocates upon access anyhow). This would essentially allow me to map multiple names to the same sprite.

Adding support to allow editing the names of the Sprites in the Sprite Asset as well as enabling them to be referenced by name should be too difficult. I am trying to get a new release out but I should be able to get that in the subsequent release.

Update
I was actually able to add initial support for referencing sprites by name tonight. Editing Sprite names in the Sprite Asset editor panel works as well.

This will need further testing as well as some tweaks but I'll be able to have this included in the next release.

Unfortunately, I'll be stuck driving for the next few days as my daughter is moving out to go to college. I would prefer not having to waste so much time driving but oh well. Hopefully I can get this next release out within the next 7 - 10 days.
« Last Edit: July 22, 2015, 11:32:47 PM by Stephan B. »

kruncher

  • Newbie
  • *
  • Posts: 7
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #4 on: July 23, 2015, 12:44:10 AM »
Awesome stuff, thanks!!  :)

kruncher

  • Newbie
  • *
  • Posts: 7
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #5 on: August 28, 2015, 09:09:59 PM »
Fantastic; thanks for adding the named sprite lookup!!

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5266
Re: Is there a way to use multiple sprite sheets on a text object?
« Reply #6 on: August 28, 2015, 09:16:25 PM »
Fantastic; thanks for adding the named sprite lookup!!

You might want to check out this thread http://digitalnativestudios.com/forum/index.php?topic=292.0

As I am currently adding support for using multiple fonts per text object, this will also make it possible to also use multiple Sprite Assets. Keep in mind that each Sprite Asset will result in an additional draw call since each Sprite Asset use their own texture but in cases where you really need to use more than one sprite asset because you can't fit all the sprites into a single texture, you'll have that option.