Author Topic: can I make a non-rect button in NGUI?  (Read 6063 times)

zhangjiq1983

  • Guest
can I make a non-rect button in NGUI?
« on: November 11, 2012, 10:50:09 PM »
For example, make a circle button.
I can make it looks circle using alpha channel of the texture.
Can I make it respond to mouse like a circle button too?

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: can I make a non-rect button in NGUI?
« Reply #1 on: November 12, 2012, 12:05:54 AM »
Of course.  If you don't want to respond to the entirety of a square collider, you can pick an arbitrary point, compute the vector from that point to the click location, and then check to see if it falls inside the radius.

This is computer programming.  There is very little logic you cannot implement if you are a competent programmer.

zhangjiq1983

  • Guest
Re: can I make a non-rect button in NGUI?
« Reply #2 on: November 12, 2012, 12:14:27 AM »
Of course.  If you don't want to respond to the entirety of a square collider, you can pick an arbitrary point, compute the vector from that point to the click location, and then check to see if it falls inside the radius.

This is computer programming.  There is very little logic you cannot implement if you are a competent programmer.

no, no I don't think so.
I just take circle buttons for just example.
I want a more general solution,  maybe I can test the alpha value of the button after the collider ray trace successed.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: can I make a non-rect button in NGUI?
« Reply #3 on: November 12, 2012, 12:25:16 AM »
why don't replace a sphere collider ? or even a mesh collider for custom shape

zhangjiq1983

  • Guest
Re: can I make a non-rect button in NGUI?
« Reply #4 on: November 12, 2012, 12:39:25 AM »
why don't replace a sphere collider ? or even a mesh collider for custom shape
Because UI design is a pixal artist work.
There are lots of icons like sword, shield, apple....and many many more non-rect buttons.
They all have alpha chennels ready, and we use pixel test before in some other engine.
I want to know is this possible in Unity3d and GUI.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: can I make a non-rect button in NGUI?
« Reply #5 on: November 12, 2012, 02:13:57 AM »
Then do a coordinate lookup against a source texture and check the returned alpha value or something.  There are many ways you could code this.  Will NGUI do it for you?  No.  Can you do it with a little coding?  Yes.