Author Topic: WWW Loading texture into NGUI  (Read 13781 times)

jason0202

  • Guest
WWW Loading texture into NGUI
« on: April 23, 2012, 12:03:52 AM »
Hi,

I wonder is there anyway to dynamically load texture into NGUI sprite or any workaround to display texture??

I tried UITexture, but it load my picture oversize  :-[ 

Here's my code:
  1. UITexture ut = NGUITools.AddWidget<UITexture>(ProfilePicContainer);
  2.         ut.material = new Material(Shader.Find("Unlit/Transparent Colored"));
  3.         ut.material.mainTexture = ProfilePicTexture;
  4.         //ut.MakePixelPerfect();




Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: WWW Loading texture into NGUI
« Reply #1 on: April 23, 2012, 01:16:31 AM »
UITexture is what you use to display dynamically loaded textures. You can't easily modify an atlas. With enough expertise you could change an atlas at run-time (or create a new one for thumbnails, for example), but it's an advanced technique that I don't have an example for. Stick to textures.

The widgets added via AddWidget will come in with a scale of (1, 1, 1) by default until you call MakePixelPerfect. If the parent of whatever you are adding the widget to is huge, you will end up with a huge widget.

Is a ProfilePicContainer a sliced sprite with a large scale? That would cause an issue. It needs to have a scale of (1, 1, 1) -- every object except UIRoot needs to have a scale of one leading up to your widgets.

jason0202

  • Guest
Re: WWW Loading texture into NGUI
« Reply #2 on: April 23, 2012, 04:12:34 AM »
Thanks for quick reply  :)

I fixed the problem myself by calling

  1. ut.transform.localScale = Vector3.one;

and comment up
  1. ut.MakePixelPerfect();

because it makes the texture become huge.

Another problem is the position of UITable will somehow auto reposition after I added gameobjects into it using Instiatiate.
I did work around by adding codes to re-initialize its position in hard-code way. Is it a bug?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: WWW Loading texture into NGUI
« Reply #3 on: April 23, 2012, 01:20:02 PM »
You need to work with proper scales. If setting the local scale to 1 fixes this issue, then it's as I expected -- you don't use scales of (1, 1, 1) leading up to your widget. This is going to cause you headaches later down the line. Please fix it properly or I won't be able to help you as one thing leads to another and you will run into more issues.

The table doesn't reposition itself. It repositions its children. If you used a clipped camera with UIDraggablePanel script on it, then it might reposition a child UITable to make it fit.

iretrograde

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: WWW Loading texture into NGUI
« Reply #4 on: October 10, 2012, 10:08:28 PM »
Hi there Aren,

I wasn't sure whether to start a new thread or not and since I found this one I figured I'd put it here.

I've bought NGUI and I'm currently building out a words-with-friends like game interface and I'm currently getting it to load pretty alright. Still haven't gotten the UISprites to update based on user profile images (in-app Facebook friends list). Having said that, I'm just doing that right now and was looking for examples on how to do so.

Now, I kinda got this down, I request the texture, get a texture/material setup and assign it to the UISprite, alright. Now my question is about getting the atlas going. I just read this thread and saw that for each texture changed, there will have to be draw call, so I just want to make sure that if a user has 400 friends, that my game won't crawl to a halt...

I'm pretty much at that stage now since I have my friends lists being loaded and everything, I just want to make sure that I develop a solution that will work here and I'm very interested in what suggestion you might throw my way.

Cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: WWW Loading texture into NGUI
« Reply #5 on: October 11, 2012, 04:29:29 AM »
If you intend to display all 400 friends at once, then yes you will have 400+ draw calls. I suggest limiting the number of friends visible on the screen at a time.