Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on April 20, 2011, 03:11:36 AM
-
Hello Everyone,
Just a very minor but quite important mod actually ( at least for my needs :) )
Basically the original action requires you to select a gameObject to set, but in many cases, it is important to be able to remove the reference. so I modified the action to allow for this. I might miss an obvious drawback maybe.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
//
// This version allow setting the variable to null,
// the original version requires a gameobject to be selected,
// but in many situation, it is important to be able to remove any reference.
//
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.StateMachine)]
[Tooltip("Set the value of a Game Object Variable in another FSM. Accept null reference")]
public class SetFsmGameObject : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmName)]
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
[RequiredField]
[UIHint(UIHint.FsmGameObject)]
public FsmString variableName;
public FsmGameObject setValue;
public bool everyFrame;
GameObject goLastFrame;
PlayMakerFSM fsm;
public override void Reset()
{
gameObject = null;
fsmName = "";
setValue = null;
}
public override void OnEnter()
{
DoSetFsmGameObject();
if (!everyFrame)
Finish();
}
void DoSetFsmGameObject()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
if (go != goLastFrame)
{
goLastFrame = go;
// only get the fsm component if go has changed
fsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
}
if (fsm == null) return;
FsmGameObject fsmGameObject = fsm.FsmVariables.GetFsmGameObject(variableName.Value);
if (fsmGameObject == null) return;
if (setValue == null) {
fsmGameObject.Value = null;
}else{
fsmGameObject.Value = setValue.Value;
}
}
public override void OnUpdate()
{
DoSetFsmGameObject();
}
}
}
Bye,
Jean
-
how to change the specify gameobject named "Enemy" in this fsmstate to other gameobject by code?
-
The easiest way is to set it to a variable then set the value of that variable in your script:
https://hutonggames.fogbugz.com/default.asp?W329
In general you should try to interface with FSMs using events and variables.
-
I have an question about the function GetOwnerDefaultTarget();
currentFSM.FsmStates[0].Fsm.GetOwnerDefaultTarget("How to get currentFSM.FsmStates[0] 's FsmOwnerDefault?"));
-
GetOwnerDefaultTarget is a helper function that returns either the GameObject that owns the FSM or a specified target, based in the user selection. What are you trying to do with this function?
-
question
1: "How to get currentFSM.FsmStates[0] 's FsmOwnerDefault?",
2:how to re agsin new gameobject in FsmOwnerDefault by code?
I want to chang user selected the GameObject that owns the FSM or a specified target by code,then give this FSM runing on the new gameobject
-
any help?
-
Hi,
the default gameobject owner is a fsm wide value, it's simply the "owner" property of the fsm, you don't need to look into states to get this info.
Bye,
Jean