Skip to content

PlayMaker

Easy way to connect with other extensions

PlayMaker

Postby Viziopleasure » 06 Apr 2011, 23:43

Hi. As this is my first SmartBlock I wan't to share it with you. This is a block specific to read data coming from a PlayMaker's FSM.
Basically it let you build code in Antares directly around what's going on into a targeted PlayMaker's FSM.
I'm using them together, so It'll be very handy for me, I hope this may help someone else too. Here it is:

Image

Syntax:
Using csharp Syntax Highlighting
/*
 Bruno Xavier L' - 05 April 2011
 Use this as you wish and on your own risk
 Files are granted as 'is' and published under General Public License
*/


using UnityEngine;
using HutongGames.PlayMaker;
using Antares.Vizio.Runtime;


[VisualLogicBlockDescription("References an existing PlayMaker's FSM Container (GameObject or Component Script)")]
[VisualLogicBlock("PlayMaker FSM", "PlayMaker\\Get", ParentName = "Get FSM")]
public class GetPlayMakerFSM: LogicBlock {

        //"inFSM.Value" will return the "Play Maker FSM (Script)" you drop in the field,
        //else PlayMaker will send here the first FSM Component if you drop the game object itself.
        //Be aware that Unity may memorise your dropped Script, when you want to select another FSM,
        //from the same gameObject, set the IN variable to NULL first. ("none")
        [Parameter(VariableType.In, typeof(PlayMakerFSM), Name = "PlayMaker FSM Instance")]
        public Variable inFSM;

        [Parameter(VariableType.Out, typeof(PlayMakerFSM), Name = "PlayMaker FSM Reference")]
        public Variable outFSM;

        // Private FSM Instance
        private PlayMakerFSM FSMbehavior;

        // FSM Variables
        [Parameter(VariableType.Out, typeof(FsmBool[]), Name = "FSM Bools")]
        public Variable outBoolsList;

        [Parameter(VariableType.Out, typeof(FsmColor[]), Name = "FSM Colors")]
        public Variable outColorsList;

        [Parameter(VariableType.Out, typeof(FsmFloat[]), Name = "FSM Floats")]
        public Variable outFloatsList;

        [Parameter(VariableType.Out, typeof(FsmGameObject[]), Name = "FSM Game Objects")]
        public Variable outGameObjectsList;

        [Parameter(VariableType.Out, typeof(FsmInt[]), Name = "FSM Ints")]
        public Variable outIntsList;

        [Parameter(VariableType.Out, typeof(FsmString[]), Name = "FSM Strings")]
        public Variable outStringsList;

        [Parameter(VariableType.Out, typeof(FsmVector3[]), Name = "FSM Vectors")]
        public Variable outVectorsList;

        // FSM States and Events
        [Parameter(VariableType.Out, typeof(FsmEvent[]), Name = "FSM Events")]
        public Variable outEventsList;

        [Parameter(VariableType.Out, typeof(FsmState[]), Name = "FSM States")]
        public Variable outStatesList;

        //

        public override void OnInitializeDefaultData() {
                RegisterOutputTrigger("Success");
                RegisterOutputTrigger("Failure");
        }

        //

        [EntryTrigger]
        public void Begin() {
                if (inFSM.Value != null) {
                        FSMbehavior = inFSM.Value as PlayMakerFSM;
                        //
                        outBoolsList.Value = FSMbehavior.FsmVariables.BoolVariables;
                        outColorsList.Value = FSMbehavior.FsmVariables.ColorVariables;
                        outFloatsList.Value = FSMbehavior.FsmVariables.FloatVariables;
                        outGameObjectsList.Value = FSMbehavior.FsmVariables.GameObjectVariables;
                        outIntsList.Value = FSMbehavior.FsmVariables.IntVariables;
                        outStringsList.Value = FSMbehavior.FsmVariables.StringVariables;
                        outVectorsList.Value = FSMbehavior.FsmVariables.Vector3Variables;
                        //
                        outEventsList.Value = FSMbehavior.FsmEvents;
                        outStatesList.Value = FSMbehavior.FsmStates;
                        //
                        inFSM.DisplayName = FSMbehavior.FsmName;
                        outFSM.DisplayName = FSMbehavior.FsmName;
                        outFSM.Value = FSMbehavior;
                        //
                        ActivateTrigger("Success");
                } else {
                        Debug.LogError(this.ToString()+": PlayMaker's FSM not found! Is it null? Please, check out 'Parametres IN'");
                        ActivateTrigger("Failure");
                }
        }
}
 
Parsed in 0.023 seconds, using GeSHi 1.0.8.4




-------------------------


:!: [EDIT]: I've done some little minor changes to the GUI stuff for the blocks and attached a package. Goes a little guideline and explanation as requested by holyjewsus:

Image

(Area Inside Green Square): This will show up only in runtime, when you hit "play" button. You can use that to check if the variable you are using is really the one you want to.
(1): This is an Activator. In this case I'm using Awake, could be Start too. It is not good idea to use Update and other ones like that.
(2): "Get FSM" is the local representation of the PlayMaker's FSM you want to track on. It's where your FSM data comes from.
(3): This is the input for your real PlayMaker's FSM. You need to drag your FSM to that field in order to "Get FSM" to work.
(4): These output variables exposes the data retrieved from your FSM. You can use other SBs to use that data.
(5): This is a SB connected to the FsmBool[] data that can expose and select the actual variable you want to use, for example "Bool5" that was created in PlayMaker's Editor.
(6): This field let you insert the index of the variable you want to use in this Smart Block. If you know exactly the variables index or there's too many of them, it is quicker to use this for selection.
(7): These arrows allow you to select a variable too, you can decrease/increase selection value.
(8): This is actually the selected variable this Smart Block uses. In this case in the image, variable number #4(Bool5) that was created in PlayMaker's Editor.
(9): Here you can check the INDEX of the variable you want to use, so you can insert this index into the Selection field and the SB will use the one you want.
(10): The name of the variables you created in PlayMaker's Editor into the FSM.
(11): The actual value of that variable you see in item "10".

So, after you get those data you can do whatever you want with it's value into your Universe program. You ca modify it's values too, but I think it's better to not interfere in PlayMaker programs, just keep track of what is going on inside that and than react about it within Universe program. That way I still didnt find the need for manual scripting at the moment. Hope this helps, good luck! :)
Attachments
Antares Universe - PlayMaker Interface.unitypackage
Little pack of SBs for simple PlayMaker integration.
(9.54 KiB) Downloaded 233 times
Last edited by Viziopleasure on 14 Apr 2011, 00:21, edited 7 times in total.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby pax » 07 Apr 2011, 06:48

Great work Viziopleasure!
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: PlayMaker

Postby pax » 07 Apr 2011, 08:24

To run graph branches from playmaker you can use simple messages. You can call VizioComponent.Message("messageName"); and use this block to receive it:

Image

It will call graph branch immediately.
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: PlayMaker

Postby Viziopleasure » 07 Apr 2011, 14:17

Thank you Pax. The massaging system is really perfect for that. I'm thinking about to add a block for messaging just to have it in the same SB folder though.

Another SB, this gets the "actual active state" from the given PlayMaker FSM. Good to use when I want to fire some code in Antares based on what the FSM is doing now, but I think sending a message from PlayMaker is better to use. I still didn't tested that option, I'm focusing in exposing PlayMaker's stuff to Universe directly, them I'll start the other way around latter.
This must be linked to Update, so I'll check if I have a better option latter.

Image
Syntax:
Using csharp Syntax Highlighting
/*
 Bruno Xavier L' - 07 April 2011
 Use this as you wish and on your own risk
 Files are granted as 'is' and published under General Public License
*/


using UnityEngine;
using HutongGames.PlayMaker;
using Antares.Vizio.Runtime;

[VisualLogicBlockDescription("Get the Name of the actual FSM State in a referenced PlayMaker's FSM")]
[VisualLogicBlock("Active FSM", "PlayMaker\\Get", ParentName = "Get Name")]
public class GetActiveFsmName: LogicBlock {

        [Parameter(VariableType.In, typeof(PlayMakerFSM), Name = "PlayMaker FSM Reference")]
        public Variable inFSM;
       
        [Parameter(VariableType.Out, typeof(string), Name = "Active FSM State")]
        public Variable outActive;
       
        // Private FSM Instance
        private PlayMakerFSM FSMbehavior;
       
        //

        public override void OnInitializeDefaultData() {
                RegisterOutputTrigger("Success");
        }
       
        //

        [EntryTrigger]
        public void Begin() {
                if (inFSM.Value != null) {
                        FSMbehavior = inFSM.Value as PlayMakerFSM;
                        //
                        outActive.DisplayName = FSMbehavior.FsmName;
                        outActive.Value = FSMbehavior.ActiveStateName;
                        //
                        ActivateTrigger("Success");
                } else {
                        Debug.LogError(this.ToString()+": PlayMaker FSM's Reference is null! Please, connect a Reference.");
                }
        }
}
 
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
Last edited by Viziopleasure on 07 Apr 2011, 14:24, edited 1 time in total.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby Neodrop » 07 Apr 2011, 14:23

You can create a self-updated SB, which don't need in Activator Update
Pax will explain it better soon.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: PlayMaker

Postby Viziopleasure » 07 Apr 2011, 14:25

Neodrop wrote:You can create a self-updated SB, which don't need in Activator Update
Pax will explain it better soon.


Omg. How do I do that? I'll look forward to this. Thank you Neodrop.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby Neodrop » 07 Apr 2011, 15:18

It's really simple. Just 2-3 lines of code. But Pax will explain it better, because it's a new ability for me too.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: PlayMaker

Postby Viziopleasure » 07 Apr 2011, 18:32

Hi. I have another question.
I'm building some GUI stuff and I'd like to know how could I make the code into [EntryTrigger] to run while in edit mode.
I tried [ExecuteInEditMode] but didn't work.
I want to be able to click a variable then the block uses it, like this:
Image

But at the moment the buttons with the variable names run only in Play mode, because I'm sending the PlayMakerFSM only when Awake executes.
Any ideas? Thanks.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby Viziopleasure » 08 Apr 2011, 02:10

Ok, this is not exactly what I wanted to do, but works quickly and dirty :roll:
This block exposes all the incoming booleans, so I can check the list and select the one I want to use,
But it will display the list only in Play mode. Not perfect, but good enough to use for a while:
Image

The SB:
Syntax:
Using csharp Syntax Highlighting
/*
 Bruno Xavier L' - 07 April 2011
 Use this as you wish and on your own risk
 Files are granted as 'is' and published under General Public License
*/


using UnityEngine;
using HutongGames.PlayMaker;
using Antares.Vizio.Runtime;

[VisualLogicBlockDescription("Get a Bool variable from a FSMBool[] List")]
[VisualLogicBlock("Get FSM Bool", "PlayMaker\\Get", ParentName = "Get FSM Bool")]
public class GetPlayMakerFsmBool: LogicBlock {
       
        // FSM Index
        [Parameter(VariableType.In, typeof(int), Name = "Select Bool Index >>>")]
        public Variable inBoolID;
       
        // FSM Bools
        [Parameter(VariableType.In, typeof(FsmBool[]), Name = "FSM Bools")]
        public Variable inBoolsList;
       
        [Parameter(VariableType.Out, typeof(FsmBool), Name = "FSM Bool")]
        public Variable outBool;
       
        // Private FSM Instance
        private FsmBool[] boolList;
       
        //

        public override void OnInitializeDefaultData() {
                RegisterOutputTrigger("Success");
        }
       
        //

        [EntryTrigger]
        public void Begin() {
                if (inBoolsList.Value != null) {
                        boolList = inBoolsList.Value as FsmBool[];
                        //
                        if ((int)inBoolID.Value >= boolList.Length) {inBoolID.Value = boolList.Length-1;}
                        outBool.DisplayName = boolList[(int)inBoolID.Value].Name;
                        outBool.Value = boolList[(int)inBoolID.Value];
                        //
                        ActivateTrigger("Success");
                } else {
                        Debug.LogError(this.ToString()+": PlayMaker Bool[]'s Reference is null! Please, connect a Reference.");
                }
        }
}
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


And the GUI:
Syntax:
Using csharp Syntax Highlighting
/*
 Bruno Xavier L' - 07 April 2011
 Use this as you wish and on your own risk
 Files are granted as 'is' and published under General Public License
*/


using Antares.Vizio.Editor;
using Antares.Vizio.Runtime;
using HutongGames.PlayMaker;
using UnityEngine;

[CustomInspector(typeof(GetPlayMakerFsmBool))]
public class GetPlayMakerFsmBoolGUI : LogicBlockInspector {
        string selection = "";
        public override void OnInspectorGUI() {
                FsmBool[] boolList = null;
                int selectionID = (int)target.variables[0].Value;
                //
                GUILayout.BeginHorizontal();
                        GUILayout.Button(target.variables[0].DisplayName,GUILayout.MinWidth(250));
                        GUILayout.Space(5f);
                        if (GUILayout.Button("<",GUILayout.MaxWidth(30))) {if (selectionID > 0){selectionID--;}}
                        GUILayout.Button("Bool #"+selectionID.ToString());
                        if (GUILayout.Button(">",GUILayout.MaxWidth(30))) {
                                if (boolList != null && selectionID >= boolList.Length) {selectionID = boolList.Length-1;} else {selectionID++;}
                        }
                        GUILayout.Space(5f);
                GUILayout.EndHorizontal();
                //
                GUILayout.TextField(selection,GUILayout.MinHeight(20));
                //
                if (target.variables[1].Value != null) {
                        boolList = target.variables[1].Value as FsmBool[];
                        for (int I=0; I<boolList.Length; I++) {
                                GUILayout.BeginHorizontal();
                                        GUILayout.Button("#"+I.ToString(),GUILayout.MaxWidth(40));
                                        GUILayout.Button(boolList[I].Name);
                                        GUILayout.Box(boolList[I].Value.ToString(),GUILayout.MinWidth(100));
                                        GUILayout.Space(5f);
                                GUILayout.EndHorizontal();
                        }
                        if (selectionID < boolList.Length) {selection = boolList[selectionID].Name;}
                } else {
                        selection = "";
                }
                target.variables[0].Value = selectionID;
        }
}
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4





[Edit]:
This is super generic. If you replace the words bool and Bool, to color and Color for example, you'll have a SB for all the incoming colors from FsmColor[]:
Image
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby pax » 08 Apr 2011, 07:09

hello, I was absent yesterday.

Now we do not have the Update method in the editor mode.
But for runtime you can use this way to use MonoBehaviour events in any SB:
Syntax:
Using csharp Syntax Highlighting
[MonoBehaviourEvent(MonoBehaviourEventType.Update)]
public void Update(params object[] parametres)
{

}
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


  1. Create a method with next format:
    Syntax:
    Using csharp Syntax Highlighting
    public void MethodName(params object[] parametres)
    Parsed in 0.005 seconds, using GeSHi 1.0.8.4
  2. Mark it by MonoBehaviourEvent attribute
  3. Choose event by specifing MonoBehaviourEventType enum

In next build we will add update in edit mode option to MonoBehaviourEventType.
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: PlayMaker

Postby Viziopleasure » 08 Apr 2011, 13:03

Thank you Pax, but I don't understand how to use that.
Could you give a short example please? Thanks.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby emadgh » 08 Apr 2011, 13:29

You know, I get it work with [Antares.Vizio.Runtime.Core.MonoBehaviourEvent(Antares.Vizio.Runtime.Core.MonoBehaviourEventType.Update)].

Syntax:
Using csharp Syntax Highlighting
[VisualLogicBlock("Toggle ", "Tests")]
    public class testSelfActive : LogicBlock
    {
        [Parameter(VariableType.In, typeof(UnityEngine.GameObject), Name = "Target")]
        public Variable target;

        [Parameter(VariableType.In,typeof(KeyCode),Name = "Key")]
        public Variable key;

        [Antares.Vizio.Runtime.Core.MonoBehaviourEvent(Antares.Vizio.Runtime.Core.MonoBehaviourEventType.Update)]
        public void Update(params object[] parametres)
        {
            if (Input.GetKeyDown((KeyCode)key.Value))
            {
                ((GameObject)target.Value).active = !((GameObject)target.Value).active;
            }
        }


    }
Parsed in 0.009 seconds, using GeSHi 1.0.8.4
Unify Smart blocks are for you to use in your projects with Universe.
User avatar
emadgh
 
Posts: 48
Joined: 01 Feb 2011, 03:22
Location: 192.168.0.1

Re: PlayMaker

Postby Viziopleasure » 08 Apr 2011, 13:40

Thank you very much emadgh! That explains a lot.

I made a funny tricky output for that and it works lol. Its just an ".Out" link I connect to "Begin" and the code self repeat:
Image

Now I'll try the MonoBehaviourEventType thing. Thank you for the help.

Edit: Omg! It is perfect. No need for entryTriggers.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: PlayMaker

Postby pax » 08 Apr 2011, 14:02

When you use such loops be careful. Universe automaticaly creates coroutine with one frame step. But if you do it without coroutine - you need to create condition chunk to end loop.
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: PlayMaker

Postby Viziopleasure » 08 Apr 2011, 14:42

pax wrote:When you use such loops be careful. Universe automaticaly creates coroutine with one frame step. But if you do it without coroutine - you need to create condition chunk to end loop.


Hmm... I'll take note about that.

Anyways, those blocks are all I wanted to be able to interact with my PlayMaker's FSMs. I've done another one for it's Actions, but still I don't see any use for that.
I'm managing event driven objects within PlayMaker, but I'll code the general program in Antares. Now that I don't need to write scripts to link PlayMaker and Antares anymore, it's going to be a lot of fun.
Thank you all for the help! :D
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Next

Return to Bridges

Who is online

Registered users: No registered users