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 - Rafe

Pages: 1 [2] 3 4 ... 6
16
NGUI 3 Support / Re: sorting the elements in the grid?
« on: September 04, 2012, 12:30:31 AM »
It would be extremely helpful to have the Grid (or a new component) provide a list interface (Add(), Remove(), RemoveAt(), Insert(), etc) and maintain order. I'm writing a lot of extra code to keep numbers in front of names as I add and remove items.

17
NGUI 3 Support / Re: Best way to scroll to bottom of UITable at runtime?
« on: August 27, 2012, 01:50:45 AM »
Oh I forgot I rotated my Grid 180 in Z so zero was at the bottom and new items get added to the top. I have a pretty special use case, but it works for what I need. Sorry if it didn't help.




18
NGUI 3 Support / Re: Best way to scroll to bottom of UITable at runtime?
« on: August 26, 2012, 10:29:08 PM »
I'm not sure what you mean. That is all of it. Just replace my gameobject with a reference to yours (the draggable panel). I'm using a Grid instead of a table, but from what I have read in the API docs it should work the same way.

  1. SpringPanel.Begin(<insert draggable panel gameObject reference here>, Vector3.zero, 50);

This will add the component and activate it to move the panel.

BY the way, you don't have to use a strength of 50. 8 is a nice slow smooth motion. 50 is just faster.

19
NGUI 3 Support / Re: Best way to scroll to bottom of UITable at runtime?
« on: August 26, 2012, 10:11:26 PM »
Aren just helped me with this:
Quote
Scrolling to the end can be done using SpringPanel.Begin(targetPosition), the same way CenterOnChild works (line 90).

In my case the target position to do this was Vector3.zero. It is a static method so you have to pass a reference to the panel you want to move, like so:
  1.         SpringPanel.Begin(this.dragPanel.gameObject, Vector3.zero, 50);
  2.  

Hope that helps you too,

- Rafe

20
NGUI 3 Support / Re: Disable Collider on Clipped DraggablePanel items
« on: August 26, 2012, 07:52:21 PM »
Quote
you can check to see if the widget is clipped by checking its bounds against the clipping area

Do you have a code sample for how to do this?

Cheers,

21
'm using this a lot in our project without an issue. My understanding is that it is just a safer (ordered) version of Unity's SetActiveRecursively. You might try that and see if you have the same problem:
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActiveRecursively.html

An interesting side-note. In Unity 4 this won't be needed anymore because Unity will manage child objects automatically when the parent is deactivated. I have my fingers crossed that the child state is kept so when the parent is toggled the child could stay hidden if it was to begin with. The new API suggests this will be true. it sounds like there are two functions to replace gameObject.active; one to test the current state and another to test the gameobject's local state.

22
NGUI 3 Support / Feature Suggestions
« on: August 26, 2012, 02:54:50 PM »
Hi,

Just a couple of things that could be nice to have

1) It would be handy to have the "static" toggle in the Panel Tool window.

2) UICenterOnChild calls SpringPanel.Begin() with a hard-coded strength of 8. I branched the script for our project to make this a public field in the inspector.

23
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 25, 2012, 04:48:30 PM »
First, the fixes I made to your code work. They fix the race issue and you have all the information you need to implement it I think. I can now call ResetPostion() as part of my init code (which makes a lot of sense in my particular usage case... I am setting up the GUI before I show it all in one function). Fixed.

"Better figure out why that's happening and fix it "

With all due respect. It is your API, you should protect against init races. It is frustrating when I run someone else's code and there is an unhandled exception. I paid for the full license, so I expect to be able to lean on the developer. I thought you would appreciate knowing you missed an unexpected null reference exception. I know how rare it is to get users that report tracebacks and possible fixes. A 'thank you' can go a long way. I'm sorry if this sounds harsh but I'm a bit frustrated on this Saturday afternoon. As a new user it is hard to ask the right questions sometimes.

So.... Lets start over.

I have a snapping scroll list now. Awesome! (not sarcastic at all, I'm happy.)


My big questions now are, from a script...

1) ...how do I scroll to the last item?

2) ...how do I insert/remove items?


These are the last two things I need to figure out to get our GUI fully moved over to nGUI.

24
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 25, 2012, 03:22:15 PM »
Regarding the ResetPosition() error. It is a NullReferenceException at line 331 of NGUIMath.cs:
  1.                 UIWidget[] widgets = child.GetComponentsInChildren<UIWidget>() as UIWidget[];
  2.  

I put in a log message and child IS null here. Regardless of the reason, it would be cool to protect against this. I'll look a bit more and edit this post if I can find anything new.

'child' comes from line 135 in UIDraggablePanel.cs: mTrans which is set in awake. I'm still trying to figure out how it ends up null:
  1.                                 mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans);
  2.  

Expanded TraceBack:
  1. NullReferenceException
  2. UnityEngine.Component.GetComponentsInChildren[UIWidget] (Boolean includeInactive) (at C:/BuildAgent/work/d9c061b1c154f5ae/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:146)
  3. UnityEngine.Component.GetComponentsInChildren[UIWidget] () (at C:/BuildAgent/work/d9c061b1c154f5ae/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:149)
  4. NGUIMath.CalculateRelativeWidgetBounds (UnityEngine.Transform root, UnityEngine.Transform child) (at Assets/NGUI/Scripts/Internal/NGUIMath.cs:332)
  5. UIDraggablePanel.get_bounds () (at Assets/NGUI/Scripts/Interaction/UIDraggablePanel.cs:135)
  6. UIDraggablePanel.SetDragAmount (Single x, Single y, Boolean updateScrollbars) (at Assets/NGUI/Scripts/Interaction/UIDraggablePanel.cs:364)
  7. UIDraggablePanel.ResetPosition () (at Assets/NGUI/Scripts/Interaction/UIDraggablePanel.cs:417)
  8. <MyScript>.Refresh (.Unit target) (at Assets/Scripts/UI/<MyScript>.cs:323)

By the way, it would really help code readability if you put "this." before all instance fields and the name of the class before all static functions. That way it would be easy to tell what is just a function-scope variable and waht is an instance or static field.

OK ------------------------------------------------

It looks like this is a race-situation. I am starting the level with this panel hidden, so I guess Awake() hasn't run for this panel when I call ResetPosition(). I added a check for this in UIDraggablePanel.bounds:
  1.         public Bounds bounds
  2.         {
  3.                 get
  4.                 {
  5.                         if (!mCalculatedBounds)
  6.                         {
  7.                                 mCalculatedBounds = true;
  8.                 if (this.mTrans == null)
  9.                     this.mTrans = this.transform;
  10.  
  11.                                 mBounds = NGUIMath.CalculateRelativeWidgetBounds(mTrans, mTrans);
  12.                         }
  13.                         return mBounds;
  14.                 }
  15.         }

25
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 25, 2012, 02:53:40 PM »
OK, I added the center on children component to the grid (code comments say "container" by the way) and it seems to work. It would be cool to have an option for bounding box too. My items are all positioned based on the bottom right corner. I'm sure once I add parent transforms that are centered it will work.

I'm not sure how I would have figured this out if it wasn't for your last post. I missed it in the example.

Thanks!

26
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 25, 2012, 01:20:53 PM »
I'll look in to the UICenterOnChild. It is very important that the scrolling content always snaps to the nearest center. Perhaps this will fix the other issue I am seeing too, but the default behavior feels random so I am trying to understand it...

A. The SpingPanel (added at runtime, or added by me, same result) changes from (0, 0, 0) to (0, 19.00002, 0).

This happens when it is activated by the draggable panel (I assume). If I set it back to 0, then drag and let go, it resets to 19.

If I set the draggable panel to not spring anymore, and do it manually, the number doesn't change.

...why?

27
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 24, 2012, 10:01:46 PM »
I'm just replying to bump this. I know you have a lot of posts to get through and this one is quite involved. Perhaps it could be tutorialized since it is a common need. Anyway, please see my last post above.

Cheers,

28
NGUI 3 Support / Re: UIDraggablePanel: Help with overshoot
« on: August 22, 2012, 01:17:52 AM »
"Drifts off" doesn't paint the right picture. I mean it doesn't do a hard snip, it stops off-"center".

A. The SpingPanel (added at runtime, or added by me, same result) changes from (0, 0, 0) to (0, 19.00002, 0).
B. When I drag half way between the two items and let go, the spring doesn't activate at all
C. I can drag past the panels in both directions, I need it to stop when it hits the edge of a panel.

What is changing the spring value and why is it off-center?

I don't know what you mean by "script that does the snapping". I am only using a Draggable Panel set to MomentumAndSpring. It adds a Spring Panel at runtime as soon as I drag and let go. It is on the same GameObject as a UIPanel in the hierarchy I posted above.



[Edit:] I have two UIDragPanelContents in this grid. The first springs to the odd value I described. The second springs to the right value. They should be snaped at 0 and -150 in Y and I'm getting 19 and -150.

+ I need the panel to snap to the nearest no matter where the player lets go.

Also, can you comment on my second bullet point in my original post?:
Quote
"How do I reset the scroll back to its start position of 0? Should I just set the transform? I tried ResetPosition() but it threw an error"


29
NGUI 3 Support / UIDraggablePanel: Help with overshoot
« on: August 21, 2012, 12:53:13 AM »
Hi,

I'm hoping you can offer some advice. I think followed the example scene to setup a draggable/scrolling panel correctly. It mostly works. I have...
  1. UIDraggablePanel
  2. -- Grid
  3. -- -- UI Drag Panel Contents
  4. -- -- UI Drag Panel Contents
  5.  

Issues I need to solve:
  • The panel doesn't snap when released. The spring is too weak and drifts off rather than snaps. I tried to change the target of the spring panel to 0, and up the strength, but the panel takes over control and sets it to a value that is off zero. How can I get a crisp snap?
  • How do I reset the scroll back to its start position of 0? Should I just set the transform? I tried ResetPosition() but it threw an error

I need to learn how to do this quickly because the next widget I have to convert to nGUI is a programatically driven queue of icons that I need to pop, insert and scroll via script.

I did some searching and checked the examples, but I feel like I am missing something.


Cheers,

30
NGUI 3 Support / Re: DestroyImmediate Bug
« on: August 21, 2012, 12:45:41 AM »
I don't use Update() unless it is a very low frequency implementation. For example, using it on every enemy in our game would kill performance. Everything is done with direct calls or delegates and co-routines. In this particular case imagine a bullet hitting an enemy. The enemy is told it is hit directly when the bullet's collider makes contact. In this OnHit() function, the enemy decides it is dead and "despawns" (pooled) via deactivation (and just before it does, it also despawns its life-bar). I am pretty sure there is no way to delay this until later in the current frame since this is async and you can't really be sure if you can trigger something before the end of the frame. Update() already ran anyway. To do what you suggest, I think i would have to wait for the next frame? The trouble with this is it is a pretty major game-play workaround for a single UI issue. The GUI layer shouldn't need to dictate what the game needs to do.

Doesn't Destroy() already queue destruction for later for this exact reason? Why is destroy-immediate needed during game-play?

The docs say:
Quote
Destroys the object obj immediately. It is strongly recommended to use Destroy instead.

This function should only be used when writing editor code since the delayed destruction will never be invoked in edit mode. In game code it is recommended to use Object.Destroy instead. Destroy is always delayed (but executed within the same frame...

Maybe I'm just tired, but I can't think of a reason this can't work with regular Destroy().

Pages: 1 [2] 3 4 ... 6