Author Topic: [SOLVED] UI vs World eventtype issue  (Read 3147 times)

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
[SOLVED] UI vs World eventtype issue
« on: November 08, 2013, 09:03:43 PM »
Hey guys,

from what I know about those two eventtypes, UI is for the 2d UI, and world is for the other game camera.

Now, the problem is, is in my in my inventory UI, when an item takes more than one slot to fit, (like 2x3: 2rows, 3cols) I leave the topleft widget active, adjust its UISprite dimensions, and for the rest of the slots, I just disable their UISprite (not the whole slot) - in other words they still have their colliders active on them. (see attachment) - but for some reason, when I do that and I'm on UI eventtype, it doesn't seem to detect events anymore. If I switch to world, it works!

How can I fix that? I still want the UI mode, but I also want my inventory to work (please don't suggest to use one collider, it doesn't work for my purposes)

One thing i could do, is leave everything as is, but just set the alpha to 0 for the slots I want to hide. But I believe there's something better.

Any ideas?

Thanks.

EDIT: It seems that setting the alpha to 0, isn't a great solution.
« Last Edit: November 10, 2013, 01:23:59 AM by vexe »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI vs World eventtype issue
« Reply #1 on: November 09, 2013, 07:48:14 AM »
I suggest disabling your colliders of the item slots you hide. Instead, set the "resize collider" flag to true on the widget you're resizing.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: UI vs World eventtype issue
« Reply #2 on: November 09, 2013, 08:28:13 AM »
Thanks for your reply. But as I said early, I can't use one collider. It is very important for me to determine the index of the slot in the item I click on - previously in Unity GUI, I used to do this by calculating the distance between the point where the mouse clicks, and the top left corner of the item, divide that by the size of the slot to get how many rows and cols I am away from the topleft (for example I click on the top right corner of the gun, this means I'm 2 cols and 0 rows away from the top left corner, so the index of the top right, is 0,2 relative to the item's slots in total). In NGUI it's a lot easier using separate colliders, slots have indices, when I click on the slot, I just take its index directly because I have a way to detect which slot I'm clicking on.

The point is, it is very important for me to keep separate colliders.

Can you please make another suggestion?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI vs World eventtype issue
« Reply #3 on: November 09, 2013, 10:20:17 AM »
And you still can do just that. When you get the press event, calculate which slot you're really on by doing the same math you used to do.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: UI vs World eventtype issue
« Reply #4 on: November 09, 2013, 10:55:32 AM »
Well, that would be worse case scenario.

However, setting the alpha to 0 seems to be working - to a certain extent - But sometimes, some of the slots maintain their alpha, not going to 0, although code-wise they should, but must!

Please take a look at my 1:45 video about the problem http://www.youtube.com/watch?v=JB-jxSA1Ay0&feature=player_detailpage

If you have any idea why this happens, or what's causing it, any direction and guide anything at all, please do suggest.

Thanks for your help and valuable time.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI vs World eventtype issue
« Reply #5 on: November 09, 2013, 07:15:07 PM »
When you set the alpha, you must also remove TweenColor and TweenAlpha components, or they will just change your alpha on the next update.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: UI vs World eventtype issue
« Reply #6 on: November 10, 2013, 01:23:39 AM »
You are a life saver! - Thanks a lot.