Author Topic: Setting width to anchored texture problem  (Read 19632 times)

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Setting width to anchored texture problem
« on: October 21, 2014, 08:36:15 AM »
When setting width-height to texture - it works ok:


But when i do same thing, when everything is disabled - after enabling -- texture is twice bigger!


What i do - i set texture width and height to 100px. But it changes anchors to 50 and -50, as if the anchor target had 0x size.
 
NGUI 3.7.0
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #1 on: October 22, 2014, 05:17:37 AM »
Looks fine to me. Your original anchor is:

+4 and -4 with a width and height of 162. Add these up to get a total of 170.

Your second anchor is -50 and +50 with a width and height of 270. Add these up and you also get 170. Your anchored target is 170 pixels.

What's the issue exactly? Your anchor changes without you changing it? Most commonly anything related to anchors not having the expected dimensions happens because of either the UICamera not being there, or there being more than one UICamera drawing the same layer -- for example having your main camera draw your UI.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #2 on: October 23, 2014, 04:21:18 AM »
The problem is with second anchor. It was -4, 4, before i set width to 100.

After i set width and height to 100, it automaticly changed anchors to -50, 50
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #3 on: October 23, 2014, 03:36:08 PM »
Adjusting width/height will adjust the anchors for you. Not sure what else to say there. Why wouldn't? Alternative is that adjusting width and height would do absolutely nothing, as the widget is anchored. You can adjust the anchors directly if you prefer.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #4 on: October 27, 2014, 01:59:10 PM »
> Adjusting width/height will adjust the anchors for you.

Thats right, BUT it works wrong in this case.
Ahchor target with is 170px.
If i set sprite width to 100px - it should automatically change anchors to +35 and -35, because Anchor target is bigger.

But in this case, when i set width to 100px - it makes anchors to -50 and +50 (As if my sprite was BIGGER and anchor width in reality is 0!). Next what happens - Anchor target understands, that its with is not 0, but 170! so it expands itself and it changes width of my sprite from 100 to 270 (Because of wrong set anchors)
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #5 on: October 29, 2014, 04:59:28 AM »
I think I'm missing something. Can you create a simple example showing the issue using NGUI's atlases?

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #6 on: October 31, 2014, 03:11:56 PM »
Not sure, what is the best way to send sources here. Have completely isolated the problem and found simplest way to implement a problem:

  1.         GameObject clone = NGUITools.AddChild(gameObject, originalWidget);
  2.         UITexture uiTexture = clone.GetComponentInChildren<UITexture>();
  3.  
  4.         uiTexture.mainTexture = graphics;
  5.         uiTexture.width = graphics.width;
  6.         uiTexture.height = graphics.height;

originalWidget it this gameobject:
http://gyazo.com/97c33fd8ff45412242f21440f2f27438

it has this UITexture child:
http://gyazo.com/464f2d883ee1b189da5d56a2446a2166
(it is anchored with -4,4)

graphics is just any texture2d :)


As you can see - after cloning gameobject and in same time settings its width/height causes a problem, as if the anching stuff is not happening on awake or something..
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #7 on: November 01, 2014, 07:58:56 AM »
You shouldn't be trying to clone existing active game objects. You should only instantiate prefabs.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #8 on: November 01, 2014, 10:03:44 AM »
Same thing happens, when instatiating a prefab.   :'( Just with Cloning it can be easier reproduced.
I'm a busy man... I have places to go,monsters to kill...

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #9 on: November 01, 2014, 10:08:28 AM »
What is the best way to send you a source? if i add a zip with project files, but without NGUI source codes - meta files will disconnect my prefabs from your code..
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #10 on: November 02, 2014, 03:17:22 AM »
You can make meta files visible under project settings. Best way is to export a package though. But don't include NGUI as a part of that package.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #11 on: November 02, 2014, 06:39:29 AM »
I'm a busy man... I have places to go,monsters to kill...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting width to anchored texture problem
« Reply #12 on: November 03, 2014, 06:28:36 AM »
If you need it to look like that, then don't set width and height. Setting width and height changes anchors.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #13 on: November 03, 2014, 11:08:29 AM »
Yes, but it Changes anchors, as if it was anchored to something Zero sized! There is the problem. I Want to change anchors, but i want them to change correctly, because my texture is anchored to aa widget with size> 0. But just after AddChild widget things, that itw width is 0.

When setting width to 100, anchors will bekome -50 and 50 only if width of anchor-parent is 0. But you see, that it is not.
I'm a busy man... I have places to go,monsters to kill...

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Setting width to anchored texture problem
« Reply #14 on: November 05, 2014, 02:27:34 PM »
Another sample of broken anchors, in just created prefab and changed its width-height: http://i.imgur.com/Cp1NI4N.jpg
I'm a busy man... I have places to go,monsters to kill...