Hello Guest

Author Topic: tk2dButton  (Read 8396 times)

spartan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
tk2dButton
« on: May 21, 2012, 01:52:11 am »
Hi @unikron, I was wondering if exists a way to get which gameObject sent the message of a pressed button (tk2dButton). I have implemented a very simple trick that maybe you can include on your next update.
Replace Line 295 from tk2dButton by:
targetObject.SendMessage(messageName, gameObject.name);

And the function of the receive can get on the first parameter the message sender, this is very useful if you have few or a lot of buttons pointing to a general function and you need to identify which button has been pressed (eg: which level).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton
« Reply #1 on: May 21, 2012, 02:56:52 am »
I'll add this, but I think it should send the gameObject as a reference instead of the name. You can get the name from the GameObject, and also any additional components, which will be really useful.

Got a question for you - What happens if the SendMessage target doesn't have a signature accepting a string in your case?

MetalGreg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: tk2dButton
« Reply #2 on: May 26, 2012, 03:11:47 pm »
Maybe you could make that the function we call have a GameObject parameter ?
It's not a top 1 priority but it would save some lines for sure.
Quote
public void ButtonEvent(GameObject YouClickedThisOne){}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton
« Reply #3 on: May 27, 2012, 02:53:33 pm »
Do you mean for the delegate or the event callback? I took a quick look the other day, but I think it should be a tk2dButton component, at least for consistencies sake, and in the interest of backwards compatibility. In hindsight, I do agree that the source should have been a GameObject.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: tk2dButton
« Reply #4 on: June 13, 2012, 02:28:08 pm »
I think there should be an option for parameters to the SendMessage call on the button. Right now I am modifying it myself, but I'd like to keep it up to date with the latest release version.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton
« Reply #5 on: June 14, 2012, 04:52:41 pm »
I checked - if SendMessage with a target doesn't have a target, Unity does throw up an error, so I can't simply replace the behavior directly. I'm investigating a much nicer approach for my next gen UI components, but that so far doesn't work with the flash player export.

tjgillis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: tk2dButton
« Reply #6 on: September 26, 2012, 04:15:12 pm »
Hey all,
I had the same issue as the OP but I also didn't want to break the default behaviour and have what I think is a pretty clean solution if anyone is still looking:

Code: [Select]
public bool sendWithReference = false;

....
if (targetObject)
{
if(sendWithReference){
targetObject.SendMessage(messageName,this.gameObject);
}else{
targetObject.SendMessage(messageName);
}
}
....