Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

loading quad images at runtime

A topic by MikkelSkovby created Jan 06, 2023 Views: 214 Replies: 6
Viewing posts 1 to 7

Hello

First, thanks for a great asset :)

I am trying to load custom images as a quad inline with the text using a custom tag like this:

unfortunately it is just displayed like this (this is the size of one character):

I tried changing the filtermode, but hoping you have some other ideas?

The texture loading works just fine when assigning the texture to a regular quad in unity.

Best Regards

Mikkel

Developer

Hey!


I think this is already possible by editing/creating a standard quad at runtime using the "<q=" tag instead of creating a custom one like this. If you're trying to create a set quad, just go into the text data editor by clicking the "T" in the top-right corner of any STM window, and define a quad, there.


That said...  what texture are you getting from LoadTexture()? What does that method look like?

The LoadTexture funtion looks like this, loading the texture from a file outside of the Unity asset system. When using the "T" to create a quad like you suggested, it's still creating an asset inside Unity, and I can't do this in my use case since the users can upload their own images at runtime.

Below the code in text form if you want to try it out - I just inserted my custom case below the case "<q=": section in the SuperTextMesh.cs.

 private Texture2D LoadTexture()

    {

        Texture2D texture = new Texture2D(2, 2);

string basePath = "D:\\Test\\";

        FileInfo fi = new FileInfo(Path.Combine(basePath, ParseText_myString + ".png"));

        if (fi.Exists)

        {

            if (texture.LoadImage(File.ReadAllBytes(fi.FullName)))

            {

            }

            else

            {

                // uh oh

            }

        }

        return texture;

    }

case "<em=":

                            ParseText_info.quadData = ScriptableObject.CreateInstance<STMQuadData>();

                            Texture2D texture = LoadTexture();

                            ParseText_info.quadData.texture = texture;

                            ParseText_info.quadData.filterMode = FilterMode.Trilinear;

                            ParseText_info.isQuad = true;

                            insertAfter = "\u2000";

                            break;


and the texture I am trying to load:


Developer

Ah got it, since users are uploading their own textures, that makes sense.

I believe that within the switch statement, you're missing...

ParseText_info.submeshChange = true;

...Which signals to SuperTextMesh to switch to a different material when using a quad, which is why it appears to be using the UVs of your quad, but with the font texture instead.

And later, after the switch statement, add the "em" tag to the switch statement that says "ignore single-use tags". (Quads should already be in that switch, so copy the formatting)


Hopefully this works! Thank you for your patience with me, it's been a while since I've modified the code for quads. I'd really love to switch this system to be more modular so you didn't have to edit a switch statement to add a custom tag, someday...

ParseText_info.submeshChange = true; did the trick! thank you very much, saved me a bunch of time, very kind of you to assist with this! :)

I didn't need to add the "em" tag to the "ignore single-use tags", but I can see that the q tag is in there, so I'll keep it in mind for later.

It would be a cool feature to be able to have gameobjects inline with the text as well, but the scaling might be tough to figure out :)

Developer

I'm really glad it worked!

Check out the "underline/strikethru" and more recently the "links" sample scene for some examples on how to spawn gameobjects inline with text! The included scripts there could be modified to spawn well... whatever you need. I think they only pass positional data, but you could use STM's array of textInfo to figure out the size of a given character, etc

Aha - very cool samples, and super useful to know. Thanks again! :)