Jump to content

[Solved] Texture issues


Recommended Posts

Problem 1

3329ko1.png

I use a DialogGUIButton and an image (weird target sight) to create an image button (code). However, the resulting button is not quite what I desire. The default state of the button is missing the button texture while the highlighted state is missing the image. It acts as if the button texture is changed instead of overlaying multiple textures. Can anyone figure out why it does this?

Problem 2

uvO2g60.png

This image is explicitly set to 32 in both width and height (code) but the resulting image is stubbornly more than 32 in width as shown in the above picture (the green borders are drawn by DebugStuff). I do not understand why this particular image is stretched despite its width is locked to 32.

The interface engine has a free reign to how to draw bunch of GUI components. So I edited the DialogGUILabel object next to the DialogGUIImage to be excessive in its width so that it "steals" all the free space, leaving the image no space to expand in width.

Edited by TaxiService
Link to comment
Share on other sites

I found the answer to the first problem. A UIStyle is necessary to point to a number of sprites if you want to override the DialogGUIButton's default skin (UISkinDef class) when creating an image button. 

UIStyle focusButtonStyle = new UIStyle(); // necessary for multiple button states
focusButtonStyle.normal = new UIStyleState(); // ? (not same as DialogGUIButton.image)
focusButtonStyle.normal.background = Sprite.Create(focusTexture, new Rect(0, 0, 32, 32), Vector2.zero);
focusButtonStyle.normal.textColor = Color.black;
focusButtonStyle.highlight = focusButtonStyle.normal; // when hovering your cursor over it
focusButtonStyle.active = focusButtonStyle.normal; // when pressing
focusButtonStyle.disabled = focusButtonStyle.normal; // when button is disabled (no reaction when clicking)

DialogGUIButton focusButton = new DialogGUIButton("", magicFunction, a, 32, 32, false, focusButtonStyle); // pass focusButtonStyle to this image button
focusButton.image = Sprite.Create(focusTexture, new Rect(0, 0, 32, 32), Vector2.zero); // when your cursor is not near it anywhere i.e. what you see

The downside is you cannot use the default button skin for your image button i.e. you better draw different images for different button states.

Link to comment
Share on other sites

  • 3 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...