playMaker

Author Topic: New User - Quick question  (Read 5380 times)

bpritchard

  • Playmaker Newbie
  • *
  • Posts: 11
New User - Quick question
« on: February 07, 2012, 02:03:05 PM »
We picked up playMaker today and are looking at how we can integrate it into our existing project.. so bear with me as i'm 100% new to how playmaker works.

Our initial impressions were that we could use the tool for slightly less technical designer folks (who grasp tools like kismet) that don't have the chops to sit down and directly program. I'm pretty sure thats where playMaker will shine but the problem i'm having currently is how to setup all of our existing functionality to plug into playMaker. Are we required to build separate actions for EACH function that we have already created in unity directly?

Here's a for instance...

We currently use EZGUI as a major part of our development pipeline.. and we've created a ton of subclasses functions to do exactly what we need w/o using the EZGUI items directly. For instance.. we have a hotspot, which is a subclass of IUIObject. Within the hotspot we have additionally variables we define as well as functions specific to the hotspot.

So I guess what i'm asking is will we be required to essentially recreate all of that functionality as an action? Or is there a "relatively" easy way to integrate existing functionality into playMaker using existing scripts?

Bear in mind I haven't fully read through the docs and and just scratching the surface.. but i'm more looking for a general usability answer here if that makes sense.

Thanks in advance!
Bryan

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: New User - Quick question
« Reply #1 on: February 07, 2012, 02:54:19 PM »
Take a look at the ScriptControl actions here:
https://hutonggames.fogbugz.com/default.asp?W44

There are also generic Get/Set Property actions:
https://hutonggames.fogbugz.com/default.asp?W688

The Get/Set Property actions use runtime reflection, which is slower than direct property access - but you could always use them to develop quickly, then *if* you run into perf problems, make custom actions for the properties you access in performance critical loops.

Does that help?

bpritchard

  • Playmaker Newbie
  • *
  • Posts: 11
Re: New User - Quick question
« Reply #2 on: February 07, 2012, 03:07:52 PM »
I was looking at this a little bit ago and it seems the right direction, but (and pardon my ignorance here) I'm a little unclear on how to access variables within the individual scripts... or more over subclassed variables that are other scripts. I'll give it a stab using the ScriptControl actions and see what i can get to. I'm just concerned that the way we have everything nested (which works great in the Unity Inspector) may not translate as well/as easily to the PlayMaker controls. I'm also probably just being lazy to some degree. :)

Thanks for the quick response! I'll hit you back when we have any more questions.

Cheers!

bpritchard

  • Playmaker Newbie
  • *
  • Posts: 11
Re: New User - Quick question
« Reply #3 on: February 07, 2012, 03:20:28 PM »
That seems to be the way to go (at least in my simple test). We're using EZGui for all of our input methods so i'll need to dig up those add ons you have on the site here (or build our own i guess.. depending).

I also ran across this..

https://hutonggames.fogbugz.com/default.asp?W540

which seems useful, but would i be able to access subclasses variables within the on OnUpdate function?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: New User - Quick question
« Reply #4 on: February 07, 2012, 06:55:07 PM »
Not sure what you mean by "subclasses variables"?

You can access most anything from a custom action... do you have an example?

bpritchard

  • Playmaker Newbie
  • *
  • Posts: 11
Re: New User - Quick question
« Reply #5 on: February 07, 2012, 07:30:01 PM »
Probably not being very clear here.. thanks for the patience.

So we have a generic data class called ActionOnHelper... looks like this...

Code: [Select]
using UnityEngine;
using System.Collections;


/** generic data class used to provide public variables and functions for performing actions after an operation
 * ShowHide, Mover, etc. Have an action helper that runs at the end of the action..
 */

[System.Serializable]
public class ActionOnHelper
{
public AudioClip playSound;
public GameObject audioSource;
public StatePrecondition AddState;
public StatePrecondition RemoveState;
public string methodName; // call out
public MonoBehaviour reflectTo;

public ShowHide[] ShowObjects;
public ShowHide[] HideObjects;
public Mover[] MoveObjects;
public Rotator[] RotateObjects;
public int GoToLevel = -1;
public string GoToChapter;
public ShowString Show_String;

public ListOfMultiStateToggles Toggle;
public int TogleIndex;
public ShowParticle[] showParticles;
public ZoomState ZoomControl = ZoomState.NONE;
public int PlayAnimation = -1;
public PackedSprite[] AdditionalSprites;
public int PlayAnimatedSequence = -1;
public HotSpotIsDone[] TheHotSpot;


public void RunAction(GameObject go, DialogBox textBox)
{
           //Do stuff here
        }

that class is used as a system wide variable whenever we need to run actions based on input/events. In the instance of the hotspot we use it like this..

Code: [Select]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class HotSpot : MonoBehaviour, IUIObject
{
/// <summary>
/// Controls whether this control is in an enabled
/// state or not. If it is not, input is not processed.
/// This can also be used to cause a control to take on
/// a "grayed out" appearance when disabled.
/// </summary>
public bool m_bEnabled = true;

public Scene_Items_t scene_item = Scene_Items_t.NONE;
public StringAction_t clickStringAction = StringAction_t.look;
public POINTER_INFO.INPUT_EVENT Type = POINTER_INFO.INPUT_EVENT.TAP;
public ConditionHelper EnabledWhen;
public ActionOnHelper ActionsOnClick = null;
// the inventory item that this hot spot wants to perform an action

public DialogBox TextBox;


Vector3 colliderSize;
protected List<EZInputDelegate> inputDelegates = null;

void Start ()
{
BoxCollider cs = GetComponent<BoxCollider> ();
if (cs != null)
{
colliderSize = GetComponent<BoxCollider> ().size;
}

}

public virtual bool controlIsEnabled {
get { return (m_bEnabled); }
set { EnableDisable (value); }
}

public virtual bool DetargetOnDisable
{
get;
set;
}


protected virtual void EnableDisable (bool bEnable)
{
if (m_bEnabled) {
if (bEnable == false) {
// disable an enabled object
Vector3 v = new Vector3 (0.0f, 0.0f, 0.0f);
GetComponent<BoxCollider> ().size = v;
}
m_bEnabled = false;
} else {
// disabled
if (bEnable == true) {
GetComponent<BoxCollider> ().size = colliderSize;
m_bEnabled = true;
}
}
}

// called when the inventory item is hoving over this hot spot
public virtual bool HitTestWantsInventory(Inventory_Items_t item)
{
return (false);
}

// returns the number of inventory items to remove
public virtual int OnDropInventoryItem(Inventory_Items_t item)
{
return (0); // don't accept the inventory

}


// Accessor for getting/setting a reference to the
// object that contains this one.
public virtual IUIContainer Container {
get { return (null); }
set { }
}

// Requests that the IUIObject accept the specified
// container as its container.  It should search
// up the hierarchy of parent objects first to see
// if a more immediate parent is a container, and
// if so, reject the request.
// <param name="cont">A reference to the object that is requesting containership.</param>
// <returns>True if succeeded, false if a closer container was found.</returns>
public virtual bool RequestContainership (IUIContainer cont)
{
return (false);
}

// Is called when a control receives the keyboard focus.
// <returns>The object should return true if it can process
// keyboard input (will result on displaying an on-screen
// keyboard on iPhone OS devices), or false if it cannot.</returns>
public virtual bool GotFocus ()
{
return (false);
}
 
/// <summary>
/// This is where input handling code should go in any derived class.
/// </summary>
/// <param name="ptr">POINTER_INFO struct that contains information on the pointer that caused the event, as well as the event that occurred.</param>
public virtual void OnInput (POINTER_INFO ptr)
{
if (inputDelegates != null)
{
foreach (EZInputDelegate d in inputDelegates)
d (ref ptr);
}
if (ptr.evt == POINTER_INFO.INPUT_EVENT.NO_CHANGE)
return;

if (ptr.evt == Type || (Type == POINTER_INFO.INPUT_EVENT.DRAG && ptr.evt == POINTER_INFO.INPUT_EVENT.TAP))
{
if (ptr.hitInfo.collider == null) {
// Debug.Log ("EZSimpleHotSpot::Delegate - no raycast info?");
}
else if (ptr.hitInfo.collider.gameObject == gameObject)
{

if (ClickActionSubclass(ref ptr) == true)
{

Precondition prec = null;
if (EnabledWhen.CheckConditions (ref prec) == true)
{
if (scene_item != Scene_Items_t.NONE)
{
ChapterData.instance.ShowString (TextBox, scene_item, this.clickStringAction, Inventory_Items_t.NONE);
}

if (ClickActionSubclass2(ref ptr) == true && ActionsOnClick != null)
{
ActionsOnClick.RunAction(this.gameObject, TextBox);

}
}
else if (prec != null)
{
EnabledWhen.ShowString(TextBox, prec, this.scene_item, Inventory_Items_t.NONE);
}
else
{

}
}
}
}
}
// subclasses can implement this in response to an event
protected virtual bool ClickActionSubclass(ref POINTER_INFO ptr) {  return (true); }

// this is called AFTER all conditions are evaluated.1 to 1 with "ActionOnClick"
protected virtual bool ClickActionSubclass2(ref POINTER_INFO ptr) { return (true); }


public virtual void SetInputDelegate(EZInputDelegate del)
{
inputDelegates = new List<EZInputDelegate>();
inputDelegates.Add(del);

}

/// <summary>
/// Adds a method to be called when input occurs (input is forwarded from OnInput()).
/// </summary>
/// <param name="del">A method that conforms to the EZInputDelegate pattern.</param>
public virtual void AddInputDelegate(EZInputDelegate del)
{
if (inputDelegates == null)
inputDelegates = new List<EZInputDelegate>();
inputDelegates.Add(del);
}

/// <summary>
/// Removes a method added with AddInputDelegate().
/// </summary>
/// <param name="del">A method that conforms to the EZInputDelegate pattern.</param>
public virtual void RemoveInputDelegate(EZInputDelegate del)
{
if (inputDelegates != null)
inputDelegates.Remove(del);
if (inputDelegates.Count == 0)
inputDelegates = null;
}

public virtual void SetValueChangedDelegate(EZValueChangedDelegate del) {}

/// <summary>
/// Adds a method to be called when the value of a control changes (such as a checkbox changing from false to true, or a slider being moved).
/// </summary>
/// <param name="del">A method that conforms to the EZValueChangedDelegate pattern.</param>
public virtual void AddValueChangedDelegate(EZValueChangedDelegate del) {}

/// <summary>
/// Removes a method added with AddValueChangedDelegate().
/// </summary>
/// <param name="del">A method that conforms to the EZValueChangedDelegate pattern.</param>
public virtual void RemoveValueChangedDelegate(EZValueChangedDelegate del) {}

public void RunAction()
{
ActionsOnClick.RunAction(this.gameObject,null);
}

}

so in the instance of using the ScriptController, i can get to any of the variables/functions defined in the  hotspot class, but accessing the ActionOnHelper variable (data class) and defining parameters within it eludes me.

Additionally i haven't quite figured out the EZGui integration but i'm assuming i can use the OnInput(POINTER_INFO ptr) public function in HotSpot and override that in the ScriptController? would it then pass in the ptr info to the HotSpot?

Thats a fairly generic example but it covers a TON of uses within how we have our tooling setup.
Thanks again for the help! Its greatly appreciated.

Cheers
Bryan
« Last Edit: February 08, 2012, 08:54:19 AM by bpritchard »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: New User - Quick question
« Reply #6 on: February 08, 2012, 08:24:14 PM »
Seems like a cool system! Do you currently setup ActionOnHelper data in the Unity inspector?

And now you want to set ActionOnHelper data inside Playmaker? Is it data that changes state a lot? Or just needs an initial setup? If it's more of an initial setup you could just keep using the Unity inspector for that, and make a few custom actions for the variables that change...

Sorry, still trying to wrap my head around your system and how it might map to Playmaker...

I can't help with EZGUI because I haven't used it yet :(

bpritchard

  • Playmaker Newbie
  • *
  • Posts: 11
Re: New User - Quick question
« Reply #7 on: February 08, 2012, 08:59:24 PM »
Thanks! its worked well for us for quite a while now.

Generally speaking, yeah ActionOnHelper doesn't change much, if at all. Its a set once and let it go kinda thing. Perhaps i'm thinking too hard about playmaker and how it can integrate to a pipeline, or mores interact with an existing pipeline... but essentially the ActionOnHelper items are typically set once live forever parameters on a per game object basis. Really there's not a lot of access to ActiononHelper (in that it typically is just called by a RunAction function within the main class its contained in).

IF this is something that makes sense to take offline i'd be more then happy to share more of our project source so you can take a look. We're really keen on getting PM setup in our pipe as i have a few designers that are "there technically" but would be better served w/a more fluid.. less type based system... and i think PM will fill that hole for sure.

So i would guess it makes more sense to subclass the functions that are USING items like ActionOnHelper, within the PlayMaker world..

I'll take a more in-depth look at that and see where i get.

NO worries on the EZGui stuff.. so far it seems the actions provided in the forums are really well written and highly usable.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: New User - Quick question
« Reply #8 on: February 09, 2012, 03:15:18 AM »
Hi,

 If you do need some specific EZgui actions, don't hesitate to request them, I'll make sure you'll get them.

http://hutonggames.com/playmakerforum/index.php?board=8.0

 Bye,

 Jean