Welcome,
Guest
. Please
login
or
register
.
October 29, 2025, 08:57:42 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Setting width to anchored texture problem
« previous
next »
Print
Pages:
1
[
2
]
Author
Topic: Setting width to anchored texture problem (Read 19183 times)
AGB
Jr. Member
Thank You
-Given: 0
-Receive: 1
Posts: 74
Re: Setting width to anchored texture problem
«
Reply #15 on:
November 05, 2014, 02:40:41 PM »
Problem seems to be here:
UIRect.cs:
public void SetHorizontal (Transform parent, float localPos)
in this function, just after Instatiating, rect is null! But should be anchor target widget.
Logged
I'm a busy man... I have places to go,monsters to kill...
AGB
Jr. Member
Thank You
-Given: 0
-Receive: 1
Posts: 74
Re: Setting width to anchored texture problem
«
Reply #16 on:
November 05, 2014, 02:44:08 PM »
This code can be a dirty fix:
http://gyazo.com/ca23817b4c307f2f64dcd288a75724bc
public
void
SetHorizontal
(
Transform parent,
float
localPos
)
{
if
(
rect
==
null
&&
parent
!=
null
)
{
rect
=
parent
.
GetComponent
<
UIRect
>
(
)
;
}
....
But in reality - why is it happening like this?
Logged
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
Re: Setting width to anchored texture problem
«
Reply #17 on:
November 06, 2014, 02:06:09 AM »
Because you instantiate the object, then modify it. This means you are making changes right after its Awake() function. Its anchors don't get updated until later. You can update them by calling uiTexture.ResetAndUpdateAnchors() before altering the width and height, but you don't do that.
using
UnityEngine
;
public
class
ReceivedGiftPopup
:
MonoBehaviour
{
public
GameObject originalWidget
;
public
Texture2D graphics
;
public
void
SetGiftRandom
(
)
{
GameObject clone
=
NGUITools
.
AddChild
(
gameObject, originalWidget
)
;
UITexture uiTexture
=
clone
.
GetComponentInChildren
<
UITexture
>
(
)
;
uiTexture
.
ResetAndUpdateAnchors
(
)
;
// <-- you are missing this
uiTexture
.
mainTexture
=
graphics
;
uiTexture
.
width
=
graphics
.
width
;
uiTexture
.
height
=
graphics
.
height
;
}
}
Logged
AGB
Jr. Member
Thank You
-Given: 0
-Receive: 1
Posts: 74
Re: Setting width to anchored texture problem
«
Reply #18 on:
November 06, 2014, 02:39:32 AM »
Thanks, this is exactly what i was looking for!
Logged
I'm a busy man... I have places to go,monsters to kill...
Print
Pages:
1
[
2
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
Setting width to anchored texture problem