playMaker

Author Topic: EzGUI button input delegate for tap and/or all events  (Read 12847 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
EzGUI button input delegate for tap and/or all events
« on: April 18, 2011, 07:24:24 AM »
Hi,

 Following the great action from sP0CkEr ( http://hutonggames.com/playmakerforum/index.php?topic=98.0 ), here's a variant that let you catch the tap event directly, so no post processing required in fsm and you can also if you want catch all events via another event.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

/// <summary>
/// PlayMaker Action for Delegating when a UIButton
/// has been invoked.
/// </summary>
/// <para>
/// This Action should be placed in the Start action of your
/// FSM. It will add itself as a delegate to the EZGui Button
/// to capture events that have been triggered by the
/// button.
/// </para>
/// <remarks>The Owner must contain a UIButton class</remarks>
/// <remarks>See the EZGui Documentation for More information on this Delegate</remarks>
///
/// <remarks>
/// Modified the original EzButtonInvoke, to catch only the tap event and/or all events. It's likely anyway that
///  only the tap event is needed on the fsm side, since ezgui will largely deal with the look and feel of the button itself.
/// </remarks>
///
[ActionCategory("EzGui")]
[Tooltip("EzGui Button Click")]

public class EzButtonInputDelegate : FsmStateAction {

[CheckForComponent(typeof(UIButton))]
public FsmOwnerDefault gameObject;
public FsmEvent tapEvent;
public FsmEvent allEvents;

private GameObject go;
private UIButton _object;

public override void Reset() {
gameObject = null;
tapEvent = null;
allEvents = null;
}

public override void OnEnter() {

// get the UIButton attached to this object

go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
_object = go.GetComponentInChildren<UIButton>();

// set the delegate to capture change event
_object.AddInputDelegate(MyInputDelegate);
Finish();
}

public override string ErrorCheck() {

// TODO: Missing UIButton Object

return "";
}


void MyInputDelegate(ref POINTER_INFO ptr) {

if (tapEvent!=null && ptr.evt == POINTER_INFO.INPUT_EVENT.TAP){
Fsm.Event(tapEvent);
}

if (allEvents!=null){
Fsm.EventData.StringData = ptr.evt.ToString();
Fsm.Event(allEvents);
}

}// MyInputDelegate

}


Bye,

 Jean

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: EzGUI button input delegate for tap and/or all events
« Reply #1 on: April 19, 2011, 07:58:05 PM »
Thanks!

I need to get to do those SpriteManager actions... I have a few weeks off work so now might be a good time. Unless someone more knowledgeable than me does them first! It should be fairly simple though so I'll try...

sP0CkEr

  • Playmaker Newbie
  • *
  • Posts: 25
Re: EzGUI button input delegate for tap and/or all events
« Reply #2 on: April 19, 2011, 08:39:46 PM »
Let's collaborate, what actions do u think would be useful at first?

Movement?
Collision?

- spocker

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: EzGUI button input delegate for tap and/or all events
« Reply #3 on: April 20, 2011, 12:22:38 AM »
Hi,

-- SM2 We'd need I think actions to control sprite animations, I find myself using a lot of that, instead of animating at a constant framerate for example, useful for powerbars, progress bars, realistic turny buttons etc etc.

-- SM2 Pause, play, etc etc

-- EzGui, controllers for the scroll list maybe

The thing that I don't know is how we can tight playmaker and ezgui sm2 when they initialize, I have already some trouble with SM2 and Ezgui in that phase. I'd need more time to properly experiment.

Bye,

 Jean

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: EzGUI button input delegate for tap and/or all events
« Reply #4 on: June 09, 2011, 11:54:48 AM »


Umm how do i use this?

I am totally new to EZ GUI and playMaker. I have an EZ GUI button set up and it is working.. So i added a playMaker script to it and then put the EZ Button Input Delegate on the Start event.. Not sure if this is correct.. or where to go from here?

Q

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: EzGUI button input delegate for tap and/or all events
« Reply #5 on: June 09, 2011, 07:33:52 PM »

-- SM2 We'd need I think actions to control sprite animations, I find myself using a lot of that, instead of animating at a constant framerate for example, useful for powerbars, progress bars, realistic turny buttons etc etc.

-- SM2 Pause, play, etc etc



Definitely agree. Also the ability to set what frame to play from, being able to set the loop type, play forward or backward etc. SM2 and Playmaker is one of the biggest things I am missing at the moment.

Wish I had time at the moment to experiment... I will in 8 weeks.

Worst case scenario, I might end up seeing if I can hire someone to create these actions for me if there's no progress on this front.

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: EzGUI button input delegate for tap and/or all events
« Reply #6 on: June 09, 2011, 10:34:46 PM »
OK so i figured out how to use it... Just save the code as a Name.cs file and put it in the Actions folder... Then it shows up. Put it on the Start action and set the Event for the different states... it throws an error until you add the Event into your FSM.. not rocket science i know but had never done it before..

So i needed to use Mouse down and Mouse up for FF and RW buttons so i added those to my Action with Press and Release events... Then i thought i might need Mouse Over and then Mouse Exit as well... So i was going to add those as well but i thought i would try the other original Action and it does that already... I do not understand that script and how it manages to call all the standard Events with one line but i guess that will be a mystery for another day..

Is there a drawback to using the original Action script? Why make one that only does Tap?

With this one you can specify the specific Events but i dont mind using the standard ones.

Q
« Last Edit: June 09, 2011, 10:49:53 PM by qholmes »

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: EzGUI button input delegate for tap and/or all events
« Reply #7 on: June 10, 2011, 12:13:45 AM »
Can anyone tell me how to get the value of a Radio button or a Toggle Button this way?

Q

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: EzGUI button input delegate for tap and/or all events
« Reply #8 on: June 10, 2011, 10:28:05 AM »
Ok, So Tried using the original Action Script and it does not seem to trigger my Events... They flash but they do not actually trigger.. I dont know why. But if i use the Action Script from this page with my additional edits then it works fine..

I still dont know how to get the Value from a Radio Button. IF anyone knows how to do that.

Q

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: EzGUI button input delegate for tap and/or all events
« Reply #9 on: June 10, 2011, 11:54:10 AM »
Update.. I was able to figure out how to get at the Values of the Radio Buttons.. so this is good. It is pretty ugly code right now.. But it works.

Although it does not pick up on the initial state of the button... i assume because there has not been a change. Not sure how to fix that.

Q