playMaker

Author Topic: I want to learn how to wrote my own playmaker's action How do I start?[SOLVED]  (Read 2444 times)

naktim0819

  • Playmaker Newbie
  • *
  • Posts: 44
Sorry
If I want to learn how to wrote my own playmaker's action How do I start?

Because there are a lot of plug-in buy after I do not know how to combine with playmaker
So I want to learn how to write your own playmaker action
Where should I be able to find examples of it?

For example, I now buy a new plug-in
Need to write code that is the case there are three actions
How should I write for them to custom action

/ / Creating a breed, it must be given a name and a game object
Breed.Instance (). Create ("bullets", bulletPrefab);

/ / Spawn the bullet - use this instead of "Instantiate"
Breed.Instance (). Get ("bullets"). Spawn ();

/ / Unspawn the bullet - use this instead of "Destroy"
Breed.Instance (). GetPool ("bullets"). Unspawn (gameObject);

For more info, look at the Documentation


Thanks   Seeks for advice modestly

                                                                Tim
« Last Edit: June 04, 2013, 04:02:04 AM by naktim0819 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 The best way to go about this is to study the official custom actions.

Also, are you aware that there is an action builder provided by PlayMaker, in the tools menu? this will allow you to create the base script to expand on it.

Basically, taking the first example of creating a prefab, your method has two values, a string and a gameObject Prefab reference, so your action need to expose these two properties, you will do this by creating two public variable, one FsmString, and one FsmGameObject. Then your action will only need to perform once, as opposed to every frame, so you only need to call this method "onEnter".

 I have attached the custom action implementing this first method, this should be a good starting point for you to study what's there.

 Also, each public variable for a custom action can have many many options, and to learn them, the best way is to remind yourself where you found an official action that displayed a property exactly like you wanted, and open that script, and see how it was declared.

The process I went for for this custom is the following:

Creating the base:


1: I go to the playmaker menu and hit "PlayMaker/tools/ Custom Action Wizard"
2:For "action Name", I wrote "BreedCreate"
3:For "Description", I wrote "Create a new breed using a a Prefab"
4:For "Custom Category", I wrote "Breed"
5:For "Root Folder", I wrote "PlayMaker Custom Actions/" cause I don't want my custom actions to be in the playmaker official folder, but that's only personal taste here
6: I left the rest untouch, as OnEnter method is already checked, and I don't need anything else.
7: I hit "Save custom Action"
8: the action is already available in the PlayMaker Action browser :) but does nothing right now... right click on it and click "Edit Script"

Creating the interface:

ok, let's assume I know nothing about custom actions, so I don't know how to create the interface for the action ( that we see when we put it on a state), but I know I need a string and a gameobject reference, so
1: I search "string" in the action browser ( still with the preview check box on) and I am given a list, where for example I have "string Contains",
2: I select it, and I see it has a field "Contains string" that is exactly look like what I need for my breed name "bullets".
3: I right click on the action "string contains" and select "edit script"
4: I look up the  "Contains script" variable and copy paste the following

Code: [Select]
[RequiredField]
[Tooltip("Test if the String variable contains this string.")]
public FsmString containsString;


and paste it in my custom action
5: I refactor this property by renaming it name and editing the tooltip "The name of the breed to create", so I have this now:

Code: [Select]
[RequiredField]
[Tooltip("The name of the breed to create")]
public FsmString name;

5: We now need to find an action that let us reference a gameObject prefab, so let's edit the action "createObject" for example, in there we have a FsmGameObject variable totally ready for us:

Code: [Select]
[RequiredField]
[Tooltip("GameObject to create. Usually a Prefab.")]
public FsmGameObject gameObject;

6: Once you have pasted these two snippet in the "breedCreate" action and saved, look it up the action browser, and it will now present a string and a gameobject in its interface :) we are almost there!!!

The actual "action" itself.

locate the OnEnter method, and the Finish() call, we need to insert what we want to do just before Finish();

 so I copy the code I want to perform in there:
Code: [Select]
// Code that runs on entering the state.
   public override void OnEnter()
   {
      Breed.Instance (). Create ("bullets", bulletPrefab);
      Finish();
   }


BUT, "bullets" and bulletPrefab are not what we want, we want to use the public properties of the action instead, so that we can define the name and the prefab as we edit this action within a state. so replace "bullets with name.Value and bulletPrefab with gameObject.Value like so:

Code: [Select]
Breed.Instance().Create (name.Value, gameObject.Value);
NOTE: we use the name of the property plus '.Value' because Fsmxxx classes are wrappers and to access the actual data, we need to get it using the .Value.

and that's it, so I haven't actually wrote anything from scratch AT ALL :) I am just taking snippets where they match what I want.

this action should work, I don't own Breed plug ins, so this is not tested at all, but should work. Let me know.

 If you have specific questions on this, like some aspect that you want more explanations, let me know. Here is the full custom action pasted as well as attached to this post.

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

[ActionCategory("Breed")]
[Tooltip("Create a new breed using a a Prefab")]
public class BreedCreate : FsmStateAction
{
   
   [RequiredField]
   [Tooltip("The name of the breed to create")]
   public FsmString name;

   
   [RequiredField]
   [Tooltip("GameObject to create. Usually a Prefab.")]
   public FsmGameObject gameObject;
   
   // Code that runs on entering the state.
   public override void OnEnter()
   {
      Breed.Instance().Create (name.Value, gameObject.Value);
      Finish();
   }


}


bye,

 Jean

naktim0819

  • Playmaker Newbie
  • *
  • Posts: 44
Hey Jean ! I learned the basic interface produced!
But he seems unable to work I still can not figure out how to modify the
I send a letter by e-mail and ask you to

Thank you for your answer finally jean