Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: santelia on July 11, 2012, 07:02:07 AM
-
Here's our first try to create a custom action.
Created with custom action tool, assigned to Math category, then filled with the code in MonoDevelop and saved.
But when finally we put it in a state, it shows up completely empty :(
Surely we forgot something...
Any help, including process?
Here is the code
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Math)]
[Tooltip("gets point along a circle for naval route purposes")]
public class FloatCircleCalculate : FsmStateAction
{
// distance from target point
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat distanzaPuntoTarget;
// target point
public FsmVector3 posizionePuntoTarget;
// ship point
public FsmVector3 posizioneNave;
// angle between ship and X
public FsmFloat angoloNaveSuX;
// angle between ship and target point
public FsmFloat angoloNaveSuTarget;
// temporary point of route
public FsmVector3 puntoDiRotta;
// check box for every frame
public bool everyFrame;
// Code that runs on entering the state.
public override void OnEnter()
{
if (angoloNaveSuTarget.Value != 0) {
puntoDiRotta.Value.x = posizioneNave.Value.x+distanzaPuntoTarget.Value*Mathf.Cos(angoloNaveSuX.Value*Mathf.PI/180);
puntoDiRotta.Value.z = posizioneNave.Value.z+distanzaPuntoTarget.Value*Mathf.Sin(angoloNaveSuX.Value*Mathf.PI/180);
}
if (!everyFrame)
Finish();
}
// Code that runs every frame.
public override void OnUpdate()
{
if (angoloNaveSuTarget.Value != 0) {
puntoDiRotta.Value.x = posizioneNave.Value.x+distanzaPuntoTarget.Value*Mathf.Cos(angoloNaveSuX.Value*Mathf.PI/180);
puntoDiRotta.Value.z = posizioneNave.Value.z+distanzaPuntoTarget.Value*Mathf.Sin(angoloNaveSuX.Value*Mathf.PI/180);
}
}
}
-
Hi,
Ok, here is a corrected version of this action.
1: notice that I am using the hutongs namespace, not sure if it play a role, but I always built actions like that.
2: you had an c# error, you cannot set the components of a vector without making it first as a variable
3: I removed redundant code, so now it's cleaner and easier to maintain.
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("gets point along a circle for naval route purposes")]
public class FloatCircleCalculate : FsmStateAction
{
// distance from target point
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat distanzaPuntoTarget;
// target point
public FsmVector3 posizionePuntoTarget;
// ship point
public FsmVector3 posizioneNave;
// angle between ship and X
public FsmFloat angoloNaveSuX;
// angle between ship and target point
public FsmFloat angoloNaveSuTarget;
// temporary point of route
public FsmVector3 puntoDiRotta;
// check box for every frame
public bool everyFrame;
// Code that runs on entering the state.
public override void OnEnter()
{
computePoint();
if (!everyFrame)
{
Finish();
}
}
// Code that runs every frame.
public override void OnUpdate()
{
computePoint();
}
private void computePoint()
{
if (angoloNaveSuTarget.Value != 0) {
Vector3 _puntoDiRotta = puntoDiRotta.Value;
_puntoDiRotta.x = posizioneNave.Value.x+distanzaPuntoTarget.Value*Mathf.Cos(angoloNaveSuX.Value*Mathf.PI/180);
_puntoDiRotta.z = posizioneNave.Value.z+distanzaPuntoTarget.Value*Mathf.Sin(angoloNaveSuX.Value*Mathf.PI/180);
puntoDiRotta.Value = _puntoDiRotta;
}
}
}
}
Bye,
Jean
-
Again, thank you Jean.
Also, what exactly have I to do to add it at the playmaker actions without breaking any data base (or whatever) integrity? I mean, copy the code, open a new action in MonoDevelop, paste and save it with the right name under "actions" folder, or what else?
-
Hi,
nothing else, it just scan the project folder or something. You are not going to break anything, unless you create an action that exists already ( clashing class names), bu you will get an error in Unity console anyway.
bye,
Jean