Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tr4np

Pages: [1] 2
1
NGUI 3 Support / Re: UICenterOnChild broken in 3.6.9?
« on: August 13, 2014, 09:18:52 AM »
Thanks for the link!  That fixed the problem.

I have to admit I'm guilty of not searching before posting. :)  I scanned the first page, didn't see anything about it, and posted...

2
NGUI 3 Support / UICenterOnChild broken in 3.6.9?
« on: August 12, 2014, 11:28:25 AM »
I just updated to 3.6.9 (my last update was a few months ago), and now my UICenterOnChild no longer works.  It no longer springs to my pages to the center.  It's just like a normal scroll view now.

I have a tabbed window layout, and clicking the tabs will still center on the appropriate objects, so some functionality still works.  However, I have code to track centeredObject (to indicate which tab is selected when the user scrolls manually), and centeredObject is no longer changing.  Any ideas?

[update] I was troubleshooting, and I discovered that if I disable the UICenterOnChild script (while in Play mode in the editor) and then re-enable it, things start working again.  I'm not sure if this makes a difference, but this scrollview is in a panel that is initially disabled.  Once I enable the panel, everything shows as enabled (including the UICenterOnChild component) although the UICenterOnChild component doesn't seem to work (until I disable and re-enable it).

3
You can remove the need for MarkAsChanged() if you just modify the UILabel's 'text' property to this:

Thanks for the info.  Is this going into a future version of NGUI?  I'd rather not make changes to the NGUI source, since I tend to copy & paste code among different projects.  I just know I would forget to make the change to the NGUI source in another project and run into the issue again.

4
One more piece of info...

Even when the panel is already enabled, the panel size is still sometimes calculated incorrectly due to the label.  I was able to get it working 100% with this:

  1. label.text="something";
  2. label.MarkAsChanged();
  3. label.UpdateAnchors();
  4.  
  5. Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(label.transform);
  6. // bounds is now always correct
  7.  

If either MarkAsChanged() or UpdateAnchors() is missing, the label size is not updated immediately.  Is this a bug, or just something we need to be aware of (I don't see any mention of this in the docs)?

Despite this fix, the label is still not positioned correctly if the panel is disabled initially (and re-enabled just before the positioning code).  The size is correct, but the position is not (the label is anchored to another label, and I called MarkAsChanged() and UpdateAnchors() on that label first).

[edit] Oops, I used the wrong term.  Everywhere I wrote "panel", I meant "UI Widget".  Sorry about that.  I named each of my widgets with "panel", since I use them as floating windows on my UI.

5
Thanks for the quick reply!  Unfortunately, using UpdateAnchors() didn't work.  Using a co-routine to wait until the end of the frame gives me the correct size for the labels, but the scroll view clip region still isn't updated by that time.

I have more info now, though.  I was enabling the scroll view before running this code.  I found that if the scroll view is already enabled before that re-positioning code runs, then it works fine (I don't even need to wait until end of frame).  If the scroll view is disabled (and enabled via the code on the same frame), I get that positioning error.

I use this to enable to scroll view:
  1. NGUITools.SetActive(calibrationScrollView.gameObject, true);

So there's something that delays the size/position update when the scroll view is enabled.  Any ideas?

6
I have a panel inside a scroll view.  I have a method that changes the panel size based on the panel's children (variable-length text fields), then changes the scroll view size to match (+2 pixels, to account for the border), and then positions the panel at the top of the scroll view.

The problem is that the scroll view's size isn't updated as soon as I change the panel's size.  However, if I set a timer (e.g. half a second), then the same code works the second time it is run.  I'm guessing that the panel's children's sizes aren't updated immediately after setting their text contents.

Here's some sample code:
  1. label.text="something";
  2. Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(label.transform);
  3. panel.width = (int)(label.transform.localPosition.x + bounds.max.x) + 15;
  4.  
  5. // debug output shows the label bounds is still the old value
  6.  
  7. Vector3 calPos = panel.transform.position;
  8. calPos.x = calibrationScrollView.finalClipRegion.x - calibrationScrollView.finalClipRegion.z / 2 + 1;
  9. calPos.y = calibrationScrollView.finalClipRegion.y + calibrationScrollView.finalClipRegion.w / 2 - 1;
  10.  
  11. panel.transform.localPosition = calPos;
  12. calibrationScrollView.rightAnchor.Set(0, panel.width + 2);
  13.  

So my question is whether I can force the label to update its size before getting its new bounds.  Again, if I run this same code again about half a second later, then it moves the panel in the expected location.

7
NGUI 3 Support / Re: method/function to move widget to screen edge?
« on: April 11, 2014, 08:28:48 AM »
Yes it would execute every time the widget gets enabled. The other option is every Update.

So does this mean choosing "OnEnable" is not an option for me?  I don't want it to execute each time I activate the widget.  I have a moveable window with a close button that deactivates/hides the window.  When I reactivate it, I want it to show up at the same place it was before.  However, I want to be able to reset the layout as needed.  What is the best way to go about doing this?

8
It would help if you posted a screen shot containing these three things:

1. the hierarchy view with the camera selected
2. scene view
3. inspector view

9
NGUI 3 Support / Re: method/function to move widget to screen edge?
« on: April 10, 2014, 02:29:36 PM »
UIAnchor is a legacy component. Widget shave anchoring built-in now. If you don't want it to update every frame, choose "OnEnable" as the Execute option, then call UpdateAnchors() yourself.

Does choosing "OnEnable" never move the widgets automatically, or only moves them one time (on startup)?  I saw that option, but the name made me think that it would run each time the widget was activated (since we set an object to Active to enable it).  I don't want the widget moved each time it is re-activated.

10
NGUI 3 Support / Re: "Bring to front" during run-time?
« on: April 10, 2014, 02:16:35 PM »
NGUITools.BringForward

Great, I'm glad it was so simple!  I was worried I'd have to iterate through all the widgets and keep track of all the depths myself.

Are these methods documented somewhere?  I'd like to know what other useful methods I might be missing out on.

thanks,
Phong

11
For anything custom like that you should write a script. Note that the callback being called on initialization is intentional, so that the callback is in the same state as the toggle on init.

That's fine, I can just write a script.  I was just thinking that perhaps this was a common-enough request that a new widget script could be provided for everyone to use.  Controls like list boxes and radio button groups are common enough that most GUI systems have a dedicated widget type for them.  No need to make every developer re-invent the wheel, right?

Anyway, thank you for the clarification. 

12
NGUI 3 Support / Re: UIToggle triggers OnValueChange upon SetActive
« on: April 09, 2014, 10:52:41 PM »
I just ran into this myself.  What's happening is that it's calling your method with a value of 0 when it initializes.  This is what I did to resolve this:

1. add an int parameter to the callback method.  Add this to the beginning of the method: if the value is 0, just return (i.e. ignore it).
2. in the inspector, the int parameter will need to be provided.  Drag your UIToggle to it, then select "value" from the property list

13
NGUI 3 Support / "Bring to front" during run-time?
« on: April 09, 2014, 02:12:36 PM »
Is there an NGUI method to bring a widget to the front, similar to the right-click menu option in the editor?  I have multiple draggable windows that could overlap, and I want the most recently touched window to be on top.

14
I just spent some time troubleshooting a group of UIToggles.  It turns out that every UIToggle widget was calling my notification script during initialization.  I'm using these as a list box, so I'm only interested in the one that's currently selected (why doesn't NGUI have a list box widget, anyway?).  Anyway, I realized that my method was being notified for every UIToggle in my panel, even when they were all unselected initially.

I ended up having to add an int parameter to my methods, and have the notification pass in the UIToggle's value.  My methods were modified to ignore the notification if the value was 0.  It was tedious to have to do this for every single UIToggle in my GUI, though.

Is it possible to add a UIToggle option to only notify when the value is changed to 1?  Or perhaps have a UIGroup script that will notify when a UIToggle in its group is selected.  That is, the UIGroup would have a list of UIToggles, and notify an object with the index/name/gameobject of the selected UIToggle.  Or is there already a way to determine which UIToggle in a group is currently selected?

15
What about my question? How do I pass an int?

What I did was just create a bunch of methods to call the generic method.  For example, I wanted to call this:

public void setIndex(int index) { ... }

So I had to create:

public void setIndex0() { setIndex(0); }
public void setIndex1() { setIndex(1); }
public void setIndex2() { setIndex(2); }

which I can then choose from the list.  It's a little messy, but it works.

Pages: [1] 2