Wiki

Case Status
Log In

Wiki

 
Home ยป API Reference»Writing Custom Actions»A Simple Action in Unity Scrip…
Index
Navigation
Community Wiki

A Simple Action in Unity Script

A simple action written in Unity Script.

This is the same action as the one written in c# that you can find in the PlayMaker set of official Action. It will perform exactly the same.

import System;
import HutongGames.PlayMaker;

@ActionCategory(ActionCategory.Time)
@Tooltip("Gets system date and time info and stores it in a string variable")
public class GetSystemDateTime extends FsmStateAction {

    @UIHint(UIHint.Variable)
    @Tooltip("Store System DateTime as a string.")
    public var storeString : FsmString;
    
    @Tooltip("Optional format stringE.g., MM/dd/yyyy HH:mm")
    public var format : FsmString;

    public function Reset(){
        storeString = null;
        format = "MM/dd/yyyy HH:mm";
    }

    public function OnEnter(){
        storeString.Value = DateTime.Now.ToString(format.Value);
        Finish();
    }

}

This action should be fairly self explanatory, but here's a quick overview:

Attributes

You can mark up actions with Attributes like ActionCategory, Tooltip, and UIHint. See Action Attributes.

@ActionCategory(ActionCategory.Time)

Says this action should appear in the Time category in the Action Browser.

Note, you can use a built-in category in the ActionCategory enum, or use a string to define a custom category.

@Tooltip("...")

Used on classes and public fields to show descriptions and rollover tooltips in the Playmaker editor.

@UIHint(UIHint.Variable)

UIHint.Variable gives the user a variable dropdown allowing them to select a variable.

Reset

All actions should initialize public variables to useful default values.

Reset is called when the action is added to a state and when the user selects Reset from the Action Editor Settings Menu.

OnEnter

OnEnter is called when the state becomes active. Many simple actions do all their work in OnEnter.

storeString.Value = DateTime.Now.ToString(format.Value);

This statement is the heart of this simple action, storing DateTime as a string using the supplied format.

Note the use of the Value property to get at the FsmString's wrapped string value.

If an action can finish, it should call Finish() when it finishes. 

When all actions on a state have finished, the system sends a FINISHED event that can be used to transition to a new state.

 

 

 

 

 

Tags:

Last modified on 2/16/2015 1:24 AM by User.

  • RSS Feed