playMaker

Author Topic: Dynamic Action Attributes  (Read 7112 times)

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Dynamic Action Attributes
« on: March 12, 2015, 10:59:05 AM »
Hello!  :)

What I'm trying to make is an Actor that will handle my database. using a enum to select which method to run, insert/update/create and so on.
I could ofc. make different actions for each method but I would prefer to have it all baked into one "easy to use, out of the box" action.
So I'm looking for a way to make the action's attributes/parameters depend on the method selector enum.
I have looked around a bit on the forums but didn't find anything about this.
Anyone of you have som ideas?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #1 on: March 12, 2015, 11:29:09 AM »
Check out the Vector3 Operation action for an example of how Enums work.

You should be able to apply your idea with that example, please post back if you have trouble.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #2 on: March 13, 2015, 04:09:21 AM »
Hi. Thanks, I have been looking at the operations actions to get my enum working already. but it doesn't help me.
since the parameters are always the same(not value but type).
I'm looking for a way to use the enum as a way of selecting which params. to be shown. since the params. needed may change.

« Last Edit: March 15, 2015, 09:48:47 AM by Jonnte »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #3 on: March 16, 2015, 07:52:57 AM »
You'll need a custom editor for this, I actually did this over the weekend so you can see some example code here (haven't really thoroughly tested it much yet, fyi):

https://github.com/LaneF/PlayMaker-Bolt-Networking/blob/master/Editor/CallbackEditor.cs

[EditField] is really all you need, it defines which fields are visible in the Action... its just a matter of identifying in your editor script the exposed variables that are in your action script, based on the enum switch. You could implement this in your own way, but this seems to be efficient to me.
« Last Edit: March 16, 2015, 07:54:57 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #4 on: March 16, 2015, 10:50:20 AM »
Thanks alot!  :)
That's exactly what i need. Just one more question ;)

Would it be possible to create and define the params at runtime. so if i for example make a query to a database, "asking" what columns it contains and then update the actions/editors params to fit?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #5 on: March 16, 2015, 10:53:04 AM »
Yes, Jean and I were just talking about that actually =)

I dont have a direct example at the moment, but we'll probably have something this week and could clarify how doing this works... You may be able to look at ArrayMaker or XmlMaker to figure out something that might work.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #6 on: March 16, 2015, 12:38:52 PM »
Ok. Once again thanks alot.
I'll get back to you when I have something that works as intended. Might take a while tho since I'm not used to C# ;)
Might become something that more ppl need in the end.


Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #7 on: March 17, 2015, 08:22:08 AM »
Or a way to create a dynamic enum would also help :)
Is there som other way to create a "dropdown" for the editor that I can fill with for example different table names/field names? Since it is impossible to know what the names will be, i need to make the selectors depend on queries.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #8 on: March 17, 2015, 08:47:01 AM »
Enum's aren't really used in that sense, if there is a fixed list then they're great but you'll need something else for a flexible list.

You can look at the XmlMaker / DataMaker addon for some references in this regard. The actions use a Source reference dropdown from a string array that the custom editor is defining.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #9 on: March 17, 2015, 12:08:18 PM »
Thanks again, could you maybe send a link to the addon? I cant find it :/ and i have been searching alot on how to create dynamic drop-downs but have not found anything on this.


Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #10 on: March 17, 2015, 12:13:32 PM »
Xml/Datamaker
https://hutonggames.fogbugz.com/default.asp?W1133

Heres an exerpt from what im currently working on.


EDITOR CLASS:

Code: [Select]
namespace HutongGames.PlayMakerEditor
{
    [CustomActionEditor(typeof(BoltEventSend))]
    public class EventSendEditor : CustomActionEditor
    {
        BoltEventSend Action;
        Project proj = BPEditorUtils.OpenProject();
        string[] eventNames = BPEditorUtils.GetEventNames().ToArray();
        int index = 0;

        public override bool OnGUI()
        {
            Action = target as BoltEventSend; // identify the target action
            Action.targetList = eventNames; // update the list
            Action.selectionId = EditorGUILayout.Popup("Event", Action.selectionId, Action.targetList); // update the gui in the editor

            index = Action.selectionId;

            if (index != Action.selectionId)
            {
                UpdateVars();

                return true;
            }

            else { return false; }

        }

PLAYMAKER ACTION CLASS:

Code: [Select]
/*--- __ECO__ __ACTION__ ---*/

using UnityEngine;
using BoltPlayMakerUtils;
using Bolt;
using System;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Bolt Networking")]
    [Tooltip("Send a Bolt Event on the Network.")]
    public class BoltEventSend : FsmStateAction
    {
        public string[] targetList;

        public int selectionId = 0;

        [CompoundArray("Properties", "name", "fsm variable")]
        public string[] propNames;
        public FsmVar[] propVariables;

        public string test;

        public bool debugInfo;

        public override void Reset()
        {

        }

        public override void OnEnter()
        {
            Main();
        }

        public void Main()
        {

        }
    }
}



What these do together are pull data from a list and throw it over to the action in a string array. Compound array isnt doing anything yet, but will be where the returned variables are stored.

The Int is actually the popup target, which is what you'll use to reference back to your list and grab the appropriate data to display. If you have static data, this is super easy with a switch case but gets more complex with dynamic data. I'm hoping to have this sorted out this week.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Jonnte

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Dynamic Action Attributes
« Reply #11 on: March 19, 2015, 02:43:39 AM »
Ok, Thanks problem solved.  :)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Dynamic Action Attributes
« Reply #12 on: March 19, 2015, 06:30:39 AM »
Great! Can you reference some code here for other users finding this thread?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D