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.

Topics - vexe

Pages: 1 2 3 [4]
NGUI 3 Support / How to achieve a folder structure ScrollView?
« on: August 27, 2013, 03:40:32 AM »
Hi, I wonder if I could achieve something like in the first attached picture, where in your scroll view, you have folders/holders, and if you click on them, they have contents inside. You could create a folder, name it and even drag items in it to organize them.

How can I achieve that? - Thanks.

NGUI 3 Support / Should I make my whole GUI in one UI?
« on: August 26, 2013, 01:01:04 PM »
I'm having trouble getting organized. Should I be using differing UIs or just fit everything in one UI? - why and when to use a whole new separate UI? - Thanks.

NGUI 3 Support / When and why to use seperate panels in one UI?
« on: August 26, 2013, 12:57:16 PM »
Hello, in the NGUI scroll view example, the one with the clipping panel. There's a lot of panels used. One for the clipped view, one for the main window, and one inside the main window, for the scroll bar. I just wonder why? - when and when should I do that?
can't everything fit in one panel? - what's the benefits of using separate panels? and how should I decide on how to separate them? - Thanks a lot.

I just noticed for some bizzare reason that SHIFT+ALT+N doesn't work anymore, any idea why would this happen? I use this a lot, thanks.

Hello, I have a very simple Icon prefab, which is just a gameObject with a UISprite script attached to it. It has a scale of 1,1,1.
I instantiate it dynamically:
  2. private void InitIcon(Texture t)
  3. {
  4.         GameObject go = NGUITools.AddChild(gameObject, inventory.iconTemplate);
  5.         icon = go.GetComponent<UISprite>();
  6.         icon.spriteName =;
  7. }

And then I need to get its size in pixels, which should be about (0.8, 0.8) so I use:
  1. bounds = NGUIMath.CalculateAbsoluteWidgetBounds(trans);
  2. var sMax = cam.WorldToScreenPoint(bounds.max);
  3. var sMin = cam.WorldToScreenPoint(bounds.min);
  4. return sMax - sMin;

This has worked for me very well, but for some reason, in this situation, it's not working right, it's giving me the same bounds.Min and bounds.Max, so bounds.Size is (0, 0, 0) - See attachment.

Any idea why? I really want to use this method - Thanks.

Hello, I've just added a new feature to my inventory system, just like in RTS games, if you hold the item with the mouse (pick it up) if you try to place it in a place where it can't fit, I change the color tint of the rect/background that's drawn behind the item texture to red, where if you hover over an area that the item can fit it, I change the color to green indicating that it can fit there.
(attachment no. 1)

Again, I do that by changing the color of the rect:
  1. public void ChangeFitIndicatorColor(bool doesItemFit)
  2. {
  3.         // rectTexture is a sliced sprite / has a UISlicedSprite script attached to it
  4.         rectTexture.color = (doesItemFit) ? fitColor : doesntFitColor;
  5. }

But sometimes, for no reason, I get some really awkward looking spdiy web-like thing, from the point I click to pick the item, to the cursor, inside that weby thing, I sometimes see some of the textures in my atlas, or the color tint (red|green), really strange. Please look at the 2nd attachment.

Any idea why this is happening and how to prevent it? - Thanks a lot!

In my inventory system, items could take more than one slot.
A slot prefab has:
1- UIButton script attached to it.
2- A 'background' as a child, which has a UISprite script attached to it.
3- An 'icon' as a child, which also has a UISprite script attached to it.

The way I setup the 'items take more than one slot' system, is that when I place an item in a place where it fits, I take the first slot background and icon and enlarge them to meet the item's dimensions, and for the rest of the slots it took, I disable their background and icon, take a look at the attachments.

But notice, I don't enlarge the collider to meet the item's dimensions, I leave the slots colliders to detect which slot I'm clicking at (I enlarge them a bit just to close down the spaces between the slots which will be left without a collider), this means, if I hover over a slot, other than the top-left one, the item won't highlight! - which is why whenever I add an item to some place, I make all its required slots 'refer to' the top-left one, and when I do that, I change their tween target, so that if I hover over any slot, the background of the top-left slot will get highlighted.

  1. public Slot ReferTo
  2. {
  3.         get { return referTo; }
  4.         set
  5.         {
  6.                 referTo = value;
  7.                 // if I'm referring to myself, my target tween is my background
  8.                 if (referTo == this)
  9.                         _button.tweenTarget = background.gameObject;
  10.                 // else my target tween is the bg of what I'm 'referring to'
  11.                 else _button.tweenTarget = referTo.background.gameObject;
  12.         }
  13. }

This all works well, however the problem arises when I pickup/hold the item with my mouse, when I do so, I free the slots that the item has taken (of course, when a slot is free, it 'refers to' itself now, which means its target tween is its background), when I do that, the slot I originally clicked on to add the item, will still have its highlight on! Refer to the "TheProblem" attachment.

PLEASE help me fix this, been struggling for about a week! I can't make progress cuz I'm stuck :((( - Do I have to mess with the UIButton script's code?

Thanks a lot for the help, I would really appreciate it.

I'm having a really weird issue: I have an inventory system with slots instantiated at run-time via a slot/button prefab.
My Anchor is set to topleft. Everything works as expected when I run in maximized mode. However, if I change the inventory position OR run in normal non-maximized view, some if not all the buttons will not detect input at all! Nothing will happen if I hover over them, etc. Although I checked to see if something went wrong with the slots after I moved the bag/inventory, everything is still set right, the colliders, etc. See the images in the attachment.

I created a simple button and changed its anchor, played around with its position in both normal and maximized views, it worked OK, which means it must be a problem with my slot prefab... However, it seems like it's a normal button, see the inspector image I provided as well :/

Please help, I'm really puzzled here... Thanks.

EDIT: If you want to see the code for instantiating:
  1.         public void AddSlot(int i, int j)
  2.         {
  3.                 GameObject slotObj = NGUITools.AddChild(gameObject, slotTemplate);
  4.                 Transform slotTrans = slotObj.transform;
  5.                 float x = SPACE_BETWEEN_SLOTS * (j + 1) + j * slotSize;
  6.                 float y = -SPACE_BETWEEN_SLOTS * (i + 1) - i * slotSize - headerPadding;
  7.                 slotTrans.localPosition = new Vector3(x, y, 0f);
  8.                 var slot = slotObj.GetComponent<Slot>();
  9.                 slot.Init(new Index2D(i, j), new Dimension2D(x, y), slotSize);
  10.                 slots[i].Add(slot);
  11.         }

Hello, In my inventory system, an item could take more than one slot, 2x2, 2x3, 3x3, etc. Each item has a texture - I don't care about the texture size (for a 2x2 item, the texture size doesn't have to be like, 256x256 or 128x128, but it would be better if it was)

Since I'm using NGUI, the item slot is actually a button, with a background, an icon (both sprites) and a label. I instantiate the slots, by using a Slot prefab, which has a script that stores the Slot size, for now I'm using 50. There's also a spaceBetweenSlots variable, which is 5.

So if I had a 2x2 item, its background would be of size 105x105, I scale the background to that size.

But the problem is, the item icon. I can't seem to know how to scale the icon, for it to fit perfectly inside the background. Take a look at the attached pictures.

Now the RedHerb fits, because its size is 594x601 and I'm scaling it by 100x100x1, but the gun is 640x453, if I scale it by the same scale as the Herb, you would get the results above.

Now the question is, how can I scale the icon to perfectly sit inside the background?

My attempts:
I came up with an idea of finding the difference between the icon's and the background's size, I keep scaling down the icon till there's a low dif between the two sizes. But NGUI is giving me a hard time of doing anything -_-

For my idea to work I just need the icon's and the background's size. I searched and found NGUIMath.CalculateAbsoluteWidgetsBounds, I'm not sure how to use it, it asks for a transform, and returns a Bounds, so I gave my background's, it got me back a bound with size of 0.2x0.2, did the same for the icon it gave me back a size of 0.0x0.0 lol O_O what is that?!

I tried background.relativeSize, I got back a V3 of (50,50,1) - The forums says to Scale that by background.cachedTransform.relativeSize, to get the size in pixles, so I did:

  1.  background.relativeSize.Scale(background.cachedTransform.localScale);

Is that correct? is that how to scale two vectors? - I got back a V2 of (1.0, 1.0) :D

Any help would be much appreciated, thanks a lot.

This is a follow-up question for: (only the first part)

After I added the line that ArenMook suggested:
  1. if (textLabel == null) mSelectedItem = null;
It worked well that it didn't auto select an item, but a new problem was introduced, I got what you see in the picture below, whenever I first click on a slot, I get this strange highlight...

What changes should I make in the UIPopupList in order to fix this? Thanks.

Hi, when I try to disable the UIPopupList component on one of my objects, clicking on on the object still shows the popup menu, this is strange. Why is this happening? Thanks.

NGUI 3 Support / Widgets change their parent by themselves? [SOLVED]
« on: August 12, 2013, 06:42:51 AM »
Why is it that whenever I add a widget, with a parent other than the panel, let's say a button, the button will get added under the parent I specify, but the background and its other stuff will go under the panel, why? - And if I manually get everything to where they belong (move the button background from the panel and parent it to the button I created), after a while, the button background just changes parents again, and goes under the panel once more! this is REALLY annoying. What can I do to prevent this?

I would order them nicely, then they suddenly go like the pic in the attachment (happens when I reload stuff from Visual Studio)


In the attached picture is what I'm trying to achieve (this was done in UnityGUI)

The question is, how can I achieve that with NGUI using a popup menu/list?
I believe this could be done by instantiating the list/menu EXPANDED in the place I want (where I right click), how can I instantiate it in its expanded state?

Thanks for the help.

Hello, I'm completely new to NGUI, I have watched the tutorials, videos and whatnot but I'm still lacking skills.

I have an advanced inventory system that I've been working on for the past 2 months or so here's an old demo

My understanding is that I should first create the buttons/slots and then instantiate them somehow.
But there's a lot of things that I don't know how to achieve, for example in UnityGUI I could provide by buttons with an image, they would show the image but still maintain the button's background. how can I do that in NGUI? I messed around with 'image button' template but didn't seem to know how to make an image appear on it :/

The way I'm drawing my bag (inventory) is that i have a loop looping over my slots and doing:
  1. var rect = new Rect(slots[i][j].position.x, slots[i][j].position.y, slots[i][j].width, slots[i][j].height);
  2. var button = GUI.Button(rect, slots[i][j].texture, slotStyle);
  3. if (button && !contextMenu.shouldBeShown && acceptInput)
  4. // do stuff...

How can I convert that code to NGUI?? :/

If you notice from my video, whenever I pickup an item, there's a box drawn around it (using GUI.Box). As well as a custom cursor texture and the item texture (using GUI.DrawTexture)... how can I do those things in NGUI?? :/

(If there is any important stuff that I should be aware of, please let me know if it)

Thanks a lot in advance...

Pages: 1 2 3 [4]