Tasharen Entertainment Forum

Support => NGUI 3 Documentation => Topic started by: ArenMook on November 20, 2013, 08:27:59 PM

Title: UITexture
Post by: ArenMook on November 20, 2013, 08:27:59 PM
Overview

UITexture is the most basic drawable component in NGUI. It inherits all the functionality of the UIWidget (http://www.tasharen.com/forum/index.php?topic=6702), and adds a visible component -- a texture -- that gets stretched across its dimensions.

(http://www.tasharen.com/ngui/uitexture.jpg)

Choosing the "Make Pixel-Perfect" option from the context menu will make the UITexture assume its original size. So if the source texture happens to be 300 by 200 pixels, the width and height of your UITexture will be adjusted to exactly those dimensions.

Pro-Tip

You can create your entire UI using UITextures then easily add them to the atlas by opening the Atlas Maker (NGUI -> Open -> Atlas Maker), selecting the root of your UI, and hitting the Create button. All your textures will be placed within this atlas and will be replaced with Sprites instead.

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_texture.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.
Title: Re: UITexture
Post by: Brastik on February 11, 2014, 09:23:26 PM
Hi Aren,
I used to add UITexture without a texture, only material. But the material itself didn't have a texture either, I only used shader [Unlit/Transparent Colored]. This would draw a rectangle with plain color (and alpha channel, yes), but only in NGUI 2.x, not in 3.x as far as I see.
So can you please give me some guides on how to create a plain colored rectangle with UITexture. Or if it's not possible then, is there any other way to achieve the same? (it's best if I still can control it like a widget, I mean with the depth, width, height...) Thanks in advance :)
Title: Re: UITexture
Post by: ArenMook on February 11, 2014, 09:39:13 PM
This happens because the default texture is "black", which means (0, 0, 0, 0). It was done this way so that if there is no texture set, nothing will show.

You can either create a copy of the shader that changes "black" to "white" (right at the top), or just use a small plain white texture (a single 4x4 quad should do just fine).
Title: Re: UITexture
Post by: Brastik on February 11, 2014, 11:36:55 PM
Yea I've tried both ways. The first one seems new and yes it worked. Thanks a lot Aren!  ;D
Title: Re: UITexture
Post by: PoN on February 13, 2014, 08:59:21 PM
Hi Aren, I use UITexture with material which has my own shader, then i change params , like these :
  1. material.SetColor("_BrdColor",....
  2. material.SetColor("_BGColor",...
  3. material.SetColor("_FGColor",...
  4.  

but UITexture not update or not repainting , and only repainting (display with new params) when i click on UIInput or click on UIPopupList or just disable-enable UITexture component, why? what'w wrong?

P.S. that had been coming from NGUI 2.7 vers.
Title: Re: UITexture
Post by: PoN on February 17, 2014, 02:42:30 AM
Up !! Up!!!
Title: Re: UITexture
Post by: ArenMook on February 17, 2014, 01:47:17 PM
NGUI makes copies of materials so that it can modify them. You need to use widget.drawCall.material.SetColor instead.
Title: Re: UITexture
Post by: mitay-walle on June 19, 2015, 02:28:58 AM
Hello! I'm using UITexture with runtime-imported texture, for some reason it has wrong local scale after import, and I can't change it through code.
https://www.dropbox.com/s/71l3ty9udmosggc/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%202015-06-19%2009.57.47.png?dl=0
In a little different situation, Anchors helped, but this is not that case.

What I've tried to do:

            image.mainTexture = texture;

            image.transform.localScale = Vector3.one;  // no effect
            transform.localScale = Vector3.one;  // no effect
            //image.height = NGUIMath.AdjustByDPI(.01f); //this changes not the local scale, but pixel size in widget
            //image.width = NGUIMath.AdjustByDPI(.01f);
            //NGUIMath.MakePixelPerfect(image.uvRect,600,300); // no effect
            //image.transform.localScale = Vector3.one;  // no effect
            transform.localScale = Vector3.one;  // no effect

My main question: How can I change local scale (in transform) of UITexture?
Title: Re: UITexture
Post by: ArenMook on June 21, 2015, 08:31:40 PM
If something is anchored, then you won't be able to change its width or height, and you shouldn't be messing with its scale.

If you want to change dimensions of something not anchored:
  1. image.width = texture.width;
  2. image.height = texture.height;
If you want to change dimensions of something anchored with a bottom-left pivot point:
  1. image.rightAnchor.Set(0f, texture.width);
  2. image.topAnchor.Set(0f, texture.height);