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

Pages: 1 ... 7 8 [9] 10 11
121
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.

122
OK, I just read the docs for GetCompsInChildren and read your code in Calculate... and yes indeed there was a disabled object. But now I'm still stuck getting NaNs and Infinity. Problem might be that I'm adding the sprite to a normal game object that's not under a UI panel, that will cause trouble right? - widgets must be children to some panel, correct?

123
What do you mean active widgets under it? - trans is the transform of 'icon' ^ - which is a UISprite attached to an active gameobject, no widgets underneath it.

124
It just got back working by itself, no idea why. if any body knows why it happened, I'd like to know, thanks.

125
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.

126
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:
  1.  
  2. private void InitIcon(Texture t)
  3. {
  4.         GameObject go = NGUITools.AddChild(gameObject, inventory.iconTemplate);
  5.         icon = go.GetComponent<UISprite>();
  6.         icon.spriteName = texture.name;
  7. }
  8.  

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;
  5.  

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.

127
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. }
  6.  

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!

128
I solved the issue by manually calling OnHover(false) on all the former required slots of the item after I pick it up, I think one must get himself familiar with NGUI's code anyway :)

129
That's how I done it before, it worked. But previously I used to detect which slot I'm clicking on via some obscure calculations (finding the dist between the mouse and the top-left item slot, and dividing by slotSize+spaceBetweenSlots to get the index of the slot that I'm clicking on) - but now, with multiple colliders, all that is unnecessary! - I could easily get the index of the slot that I click on because it still has its collider. Please tell me there's another solution :( - Using multiple colliders made me do a lot of things, a LOT more easier...

Note that the highlight goes away again if I hover the mouse again over the slot! - So, there should be a way to, somehow programmatically send a signal or something to the slot, that the mouse is over you, even though it's really not.

130
THANKS!!! that helped a lot, you were right, there was something invisible intersecting/on the way of the camera, however the strange thing was 'that something' is from another layer, other than the camera's culling mask (belongs to another 2D layer, which has its own camera) - and not just that, the camera that the intersecting area belongs to, is disabled! - The problem was fixed by disabling that area, or just taking out its collider. However shouldn't it be enough just to have its camera disabled? - Thanks.

131
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. }
  14.  

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.


132
I disabled the menu by disabling the un-needed children (buttons/entries) in my custom created context menu - thanks. but just thought you should know about this, maybe a bug?

133
Thanks for your help anyway. I made my custom context menu, I had to make one anyways because I needed the 'menu appear where mouse click' functionality, UIPopupList just pops up under the button, making custom stuff gives more control.

134
Thank you so much for being helpful! - I was actually looking for a way to calculate the a sprite's width/height, this helped me a lot:
  1. var image = sprite.GetAtlasSprite();
  2. var imX = image.inner.width;
  3. var imY = image.inner.height;
  4.  

But I actually managed to find another, much easier way to fix the problem.

Testing that code on my Herb texture, it gave back the actual size, but on my 640x453 gun texture, I actually got a 525x320 or something, which I found to be really odd. Somebody's messing with the size. So I went out and googled "Unity change texture size on import" and found this >> http://answers.unity3d.com/questions/241605/image-size-altered-upon-import.html << - So I immediately disabled that compressing option, and re-added my texture to my atlas, but again, I'm not getting the right size. That is when I knew that NGUI must have something to do with this. I went to the Atlas tool, and found out a setting called "Trim Alpha" (Remove empty spaces) - I ticked that one off and BAM! without no code or anything, the icon/sprite scaled and fitted perfectly! :))

Wish I could upvote you or something, without your texture size finding code, I wouldn't have known where to look, thanks again.

135
In the inventory example, I saw the usage of Bounds and bound.Encapsulate, I'm not sure if this is relevant here or not...

Pages: 1 ... 7 8 [9] 10 11