Playmaker Forum

Playmaker Updates & Downloads => Share New Actions => Topic started by: Lane on March 06, 2015, 09:22:17 AM

Title: Authoring Custom Actions
Post by: Lane on March 06, 2015, 09:22:17 AM
There are often questions about making your own custom actions. You'll need a basic understanding of C# typically as this is what we use in all of the official actions but you could author them in any of the supported Unity languages if you have a better understanding of them.

You should take a look at the Wiki section for writing custom actions:
Writing Custom Actions (Wiki) (https://hutonggames.fogbugz.com/default.asp?W166)

It includes a JS example, a lot of good information, tips and core ideas.

Here is an example of the UI Hints / Action Attributes (Wiki) (https://hutonggames.fogbugz.com/default.asp?W352) and how to use them:
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Input)]
[Tooltip("UI Hint Examples.")]
public class UIHintExamples : FsmStateAction
{
[RequiredField] // this is a required field, you have to put something in it.
[CheckForComponent(typeof(Rigidbody))] // tells the ui to look for a type of component, like a Rigidbody.
[Tooltip("The GameObject you want.")] // basic tooltip for hover descriptions.
public FsmOwnerDefault gameObject; // FsmOwnerDefault uses the owner GameObject as the variable.

[ActionSection("  UI Hints")]

[UIHint(UIHint.Layer)] // Use on an integer field for a Layer popup button.
public FsmInt layerSingle; // Not an array, single choice.

[UIHint(UIHint.Layer)]
public FsmInt[] layerMulti; // As an array, this allows for multiple layer choices.

[ActionSection("Behavior")]

[UIHint(UIHint.Behaviour)]
[Tooltip("The name of the Behaviour.")] // See Enable Behavior
public FsmString behaviour;

[ActionSection("Coroutine")]

[UIHint(UIHint.Coroutine)]
[Tooltip("The name of the coroutine method.")] // See StartCoroutine
public FunctionCall functionCall;

[ActionSection("Script")]

[UIHint(UIHint.Script)]
[Tooltip("The name of the script.")] // See AddScript
public FsmString someString;

[ActionSection("Tags")]

[UIHint(UIHint.Tag)]
public FsmString someTagSingle; // See SetTag

[UIHint(UIHint.Tag)]
public FsmString[] someTagMultiple;

[ActionSection("Text Area")]

[UIHint(UIHint.TextArea)]
public FsmString textArea;

[ActionSection("Description Area")]

[UIHint(UIHint.Description)] // Use on a string field to format the text in a large readonly info box.
public string descriptionArea;

[ActionSection("Comment Area")]

[UIHint(UIHint.Comment)]
public FsmString commentArea;

[ActionSection("Basic Variables")]

[UIHint(UIHint.Variable)] // Use on an Fsm Variable field (FsmFloat, FsmInt, FsmBool...)
public FsmFloat numbers;

[UIHint(UIHint.Variable)]
public FsmBool boolean;

[ActionSection("Animation Hint")]

[UIHint(UIHint.Animation)]
public FsmString animation;

public override void Reset() // the Reset area defines the default values for your action variables.
{
gameObject = null;
someTagSingle = null;
someTagMultiple = new FsmString[2];
textArea = "Regular text area";
commentArea = "Stuff, comment stuff.";
descriptionArea = "lorum ipsum bippity bop doo dah lorum ipsum bippity bop doo dah lorum ipsum bippity bop doo dah lorum ipsum bippity bop doo dah lorum ipsum bippity bop doo dah lorum ipsum bippity bop doo dah";
layerSingle = null;
layerMulti = new FsmInt[3];
numbers = 14.3f;
boolean = true;
animation = null;

}

public override void Awake()
{

}

public override void OnEnter()
{

}

public override void OnFixedUpdate()
{

}

void DoLook()
{

}
}
}
(http://i.imgur.com/lymhh5x.png)

If you have other questions regarding writing custom actions or suggestions about new formatting attributes, feel free to post them!