Author Topic: UIButton  (Read 81296 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #30 on: May 29, 2014, 08:24:06 AM »
  1. void Start ()
  2. {
  3.     UIButton btn = GetComponent<UIButton>();
  4.     EventDelegate.Add(btn.onClick, MyFunction);
  5. }
  6.  
  7. public void MyFunction ()
  8. {
  9.     Debug.Log("Clicked!");
  10. }

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: UIButton
« Reply #31 on: July 14, 2014, 10:10:14 PM »
Aren , Why this component doesn't have a text property , which set a text on a UILabel component of control button ? i think that is right logic for the UIButton component, like in other languages, for example .NET WindowForms - Button class or JavaFX. so what do you think ?
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #32 on: July 15, 2014, 01:00:40 AM »
How often would something like this be needed? I don't like cluttering the inspector window with seldom-used functionality. For something like that simply write a new script that would change the specified label's text in its OnHover / OnPress functions.

justkevin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIButton
« Reply #33 on: July 19, 2014, 01:06:09 PM »
How do I set the default color of a button in script?

If I change defaultColor, the change doesn't show up until the next time the user interacts with the button (e.g., by hovering).

The documentation talks about UpdateColor in the the parent class, but that method doesn't seem to exist?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #34 on: July 20, 2014, 11:50:04 AM »
UIButton.normalColor

Cyphermage

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIButton
« Reply #35 on: August 11, 2014, 03:24:18 AM »
Hi guys, I'm working out UIButtons at the moment. I've set a UISprite on the same element as my UIButton, and set the colours (for normal, hover, pressed, disabled) in UIButton.

The colours/states work if I put a Box Collider on the object, but not if I use a Box Collider 2D.  Is there a reason UIButton needs to have a non-2D collider?  It seems strange to me.  Am I doing something wrong, or have I misunderstood some functionality?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #36 on: August 12, 2014, 07:33:31 AM »
UICamera type events define what kind of raycasts are done -- either 3D, or 2D.

vikti

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: UIButton
« Reply #37 on: August 28, 2014, 11:38:50 AM »
I have a function here attached to a Sprite :

  1.         public void OnPress(bool isPressed){
  2.                 if(isPressed) {
  3.                         Debug.Log("Down");
  4.                 }
  5.                 else{
  6.                         Debug.Log("Up");
  7.                 }
  8.  
  9.         }
  10.  

In a UIbutton I drag the sprite in the On Press -> Notify of a UIEvent trigger component.
I select the Sprite/OnPress function but it asks me for an argument. Where do I find the "bool isPressed" ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #38 on: August 28, 2014, 09:45:18 PM »
Don't try to do this. OnPress is a regular event that gets sent out by NGUI's event system. You can attach this script as-is to any collider, and it will receive your press events. Nothing else is necessary.

HeavensSword

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIButton
« Reply #39 on: November 04, 2014, 09:00:38 AM »
Hello, I have a dynamic table of UIButtons. If I change the text value of the button's UIlabel to something that is larger than a single line of text I find that the buttons will overlap in the table, but calling execute on the table in the Unity editor will reposition everything just fine.

What I am doing in my code when creating the buttons and setting their text is:

  1. labelComponent.text = question;
  2. abelComponent.MarkAsChanged();
  3.  

After all buttons are added I call:

  1. questionTable.repositionNow = true;
  2.  

I'm not seeing the buttons properly positioned though, and I'm wondering if the reposition is occurring before the UILabel has had a chance to re-calculate its bounds. I was wondering what the best way to go about this would be.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #40 on: November 04, 2014, 10:56:48 AM »
You need to call UITable's Reposition() function, not set its repositionNow value.

HeavensSword

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: UIButton
« Reply #41 on: November 04, 2014, 11:37:20 AM »
Thanks for the response; I changed repositionNow to Reposition(), but I'm still seeing the overlap. I've also tried changing the MarkAsChanged() call to ProcessText().

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #42 on: November 06, 2014, 02:20:41 AM »
Thinking about it, label's dimensions won't update until later -- not unless you call panel.Refresh() to do it early.

stevej

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: UIButton
« Reply #43 on: November 07, 2014, 11:08:53 PM »
Noticed that if you have both Click and Double-Click notifications assigned, then a double-click actually fires 3 events: click, click, double-click.

Any way to suppress that so you just get a single event for click and single event for double-click?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton
« Reply #44 on: November 09, 2014, 09:31:19 PM »
No, it's intentional like that. Click and double click and separate events. Double click is a result of a click happening soon after another click. It's the same as a click event is a result of OnPress(true) and OnPress(false) being fired on the same object -- different events.