Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: henk on July 14, 2011, 10:57:25 AM

Title: EZ GUI Checkbox Action
Post by: henk on July 14, 2011, 10:57:25 AM

I want to thank Spocker for his EZ GUI Button Action:

Also, has anyone been able to modify this so that it works with a radio button and toggle button?

Title: Re: EZ GUI Checkbox Action
Post by: qholmes on July 14, 2011, 05:23:30 PM
Of course... It is easy to adapt all of those to any situation... Not sure what ones i have made up... will look later.

If you look at the code.,. I have not looked at this one yet but i will. Maybe it is better then what i have.. But it is very easy to change.

Title: Re: EZ GUI Checkbox Action
Post by: henk on July 14, 2011, 05:26:27 PM
Any pointers on how to adapt the code would be great. I'm super not very good at programing : )
Title: Re: EZ GUI Checkbox Action
Post by: qholmes on July 14, 2011, 06:06:35 PM
Neither am i really... I can code but i just have almost no experience.

Will write out a little tutorial for you. Now this will be my take on it and like i said i am not a coder either... but it has gotten me what i needed..

Title: Re: EZ GUI Checkbox Action
Post by: henk on July 14, 2011, 06:14:06 PM
 :) That's very generous of you. I'm looking forward to figuring out how to get EZ Gui and Playmaker (two great plugins) working together!
Title: Re: EZ GUI Checkbox Action
Post by: qholmes on July 14, 2011, 07:14:03 PM
Ok well dont get too excited... you still need to know kind of how to code a bit... but i just went through the Slider script and commented each line to say what it did or what i thought it did.... ;D

Then i actually added a few from a normal button as well.. This script will probably  not run... but that is not what it is for.. Look at the comments and then look at the script that you want to change or modify.. look at other action scripts in the playMaker folder... everything you need is there.. Look at the EZGUI manual and Scripting Reference too... you need the base Classes from there as well as the function properties that you need to use to access the information.. like '.Value'

I probably have spelling mistakes in this as well as i could be calling something a function when it is not etc... i only know the basics my self.. Hope this helps at least a bit!!  If anyone wants to make this better go right ahead.

All my comments are way to the Right..

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

/// <summary>
/// PlayMaker Action for Delegating when a UISlider
/// 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 Slider
/// to capture events that have been triggered by the
/// button.
/// </para>
/// <remarks>The Owner must contain a UISlider class</remarks>
/// <remarks>See the EZGui Documentation for More information on this Delegate</remarks>
[Tooltip("EzGui Slider Get Value")]

public class UISliderValueDelegate : FsmStateAction { //You have to declare a unique class name.. Unique to any other scripts you have in Unity

[CheckForComponent(typeof(UISlider))] //You check for the type of Component here to make sure you have the correct one..."UISlider" is the Class Name for this one.. all the types are in the EZGUI help docs
public FsmOwnerDefault gameObject; //This is the playMaker variable for a game object and it defaults to the Owner of this FSM

public FsmEvent tapEvent; //This is an event we could set in the FSM... just added this as an example for Button types..

public FsmFloat sliderValue; //Just a Fsm Float value that you can set to a playMaker variable

private GameObject go; //This is the game object reference we use for looking for the EZGUI components... i think
private UISlider _object; //This declaration has to be the proper "Class" type that you are looking for like above from the EZGUI docs

public override void Reset() { //I am not sure what the override section is for but i put my declared variables in there.. I think that it is a condition of 'Reset' on the Action that will Reset the function with clean values

gameObject = null; //game objects and the like are set to null
tapEvent = null;
sliderValue = 0; //i set floats and ints to 0


public override void OnEnter() { //this portion of the script is the code that runs when it first runs.. i think... OnEnter.. get it?

// get the UISlider attached to this object

go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value; //assigns the game object reference.. i think it doesnt matter what it does as it will always be the same in these.. for me anyway
_object = go.GetComponentInChildren<UISlider>(); //This gets the EZGUI component that you specify... like before the correct 'Class'  in this case again it is UISlider.

// set the delegate to capture change event
_object.AddInputDelegate(MyInputDelegate); //i put in an input delegte so you know what it looks like as well.. it will trigger 'MyInputDelegate' when there is an input to a button or something.
_object.AddValueChangedDelegate(MyDelegate); //Now this line adds a Value Changed Delegate.. instead of an Input delegate.. All that means is that if the value changes the it will call the Delegate or Function that is called MyDelegate
Finish(); //this line 'Finish()' has to do with every frame kind of functionality.. When you are using a Delegate this is fine to not run every frame as the Delegate is watching for change for you.
} //if you are not using a Delegate then you can put in a Bool and check it to either Finish or not.. I do this when i am getting values from EZGUI components with out using a Delegate..

public override string ErrorCheck() { //I am not sure what this is..  Error checking but i dont think it is really set to do anything in this case.

// TODO: Missing UISlider Object

return "";

void MyDelegate(IUIObject obj) { //So here is your delegate.. This is where you DO something... this one is the value changed Delegate

sliderValue.Value = _object.Value; // Just assigning the variable we have set up to the _object.Value we got from the EZGUI component.. if you are using a Fsm type variable you have to use  '.Value' to get and set the value..
} //The _object.Value in this case is actually from the EZGUI manual.. '.Value' is also how you get that value..  just a coinsidence..

void MyInputDelegate(ref POINTER_INFO ptr) { //this is the basic input delegate function if called.. again just in this one as an example although i think they might even work on this type of GUI element..

if (tapEvent!=null && ptr.evt == POINTER_INFO.INPUT_EVENT.TAP){ //checking to see what kind of input it was..
Fsm.Event(tapEvent); //if it was a top then we would run send the tapEvent we set up in the FSM

if (pressEvent!=null && ptr.evt == POINTER_INFO.INPUT_EVENT.PRESS){

if (releaseEvent!=null && ptr.evt == POINTER_INFO.INPUT_EVENT.RELEASE){

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


} //make sure all your {  and }  are matched... in MonoDevelop if you click beside one it will show the corresponding one.. it really helps.
Title: Re: EZ GUI Checkbox Action
Post by: qholmes on July 14, 2011, 07:49:32 PM
Hehh i thought that first link was to a different script.. it is just mine..

There are other scripts by Jean that are very close to mine.. They are how i started and still use the same base to start from..

For Radio buttons i just checked for a Tap on each button and then ran the code for it. The visual is run by EZGUI.

For Toggle buttons i used the '.StateNum' property to see which state it was in then used an Int Switch to choose a path

And just adding a note about the every frame thing.. You need to have an onUpdate function in there that will be run every frame.. kind of like this.. not sure why i was wanting to set the Toggle state every frame but it was something i wrote when i was playing with ideas... i did not use it in the end.. probably a bad idea.. but it is an example.

        if (!everyFrame)                 //every frame is a bool that i check to see if it is set.. a check box in the FSM
          Finish();                     // if it is not on then Finish()
   public override void OnUpdate()      // if it is turned on then i am pretty sure it runs this routine
      _object.SetToggleState(intVariable.Value);      // and here i was setting the Toggle state to a variable i had set in the FSM...

oh i remember why i wanted to do this every frame.. i am using an EZGUI Toggle as an information box in my project.. each Toggle state is a different image that goes with my auto tour so it is scripted and plays like a movie.. so i watch an animated variable and set the state accordingly.. I think i am using it actually...
Title: Re: EZ GUI Checkbox Action
Post by: henk on July 15, 2011, 05:55:40 AM
Thanks qholmes! I'll work on this today.
Title: Re: EZ GUI Checkbox Action
Post by: henk on July 15, 2011, 03:27:43 PM
qholmes... I read very carefully through your comments and they look helpful. I thought that, before I tried to modify the code, however, I'd try to use the "EzButtonInvoke" script first. That set me off on a several hour long detour  :D  Here's a link to where I'm at now:

Once I get this down I'll go back to your commented script and see if I'm able to modify it.

Thanks - Henk