PlayMaker Updates & Downloads > Pre-release Discussion

"Collections" Actions[SOLVED]

<< < (2/2)

jeanfabre:
Hi,

 If you are ok with scripting, no it's totally fine, you create the proper custom actions to access this list either per item, or direclty saving the content into an FsmArray.

The actions references link is simply a pending task, I am not sure when this is going to be adressed, I would not wait on this, and use either ArrayMaker or make your own custom actions to access your scripts. If you need a kick start let me know, send me one of your component and I'll show you how to create related custom actions, it's very easy.

 Bye,

 Jean

Duffer:
Hi Jean,

I'll be honest.  I could do with some help for the script for the custom action to grab values from say a public array of strings and, for the sake of simplicity a List of strings too, in a monobehaviour class linked to a GO.

Pretend the following mono class is sitting as a component on the same GO:-


--- Code: ---using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class RPGBaseInfo : MonoBehaviour {

    public bool template = false;
    public bool hidden = false;

    public string title = "default name";

    public string[] descriptors;

    public List<string> knicknames = new List<string>();
}

--- End code ---

What would the Custom Action scripts look like to access both values in the Array and then in the List?

[edit] ignore bit about Arrays... can now see how to do that with Get Property action.  More interested in Lists...

jeanfabre:
Hi,

 here we go:



and the action is :


--- Code: ---using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("RPG")]
public class GetRPGInfoItem : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(RPGBaseInfo))]
[Tooltip("The GameObject with the RPGBaseInfo component")]
public FsmOwnerDefault gameObject;

public FsmInt index;

public FsmString name;

public bool everyFrame;

RPGBaseInfo _info;

public override void Reset()
{
index = 0;
name = null;
everyFrame = false;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

_info = go.GetComponent<RPGBaseInfo> ();

DoGetRPGInfoItem();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoGetRPGInfoItem();
}

void DoGetRPGInfoItem()
{

if (_info == null) {
return;
}

name.Value = _info.knicknames [index.Value];

}
}
}

--- End code ---

 so, once you understand how to declare Fsm Variables and work with them within an action, the rest is regular c#

Bye,

 Jean

Duffer:
@Jean,

Excellent.  Thanks.

MauriceZaiss:
List of strings too, in a monobehaviour class linked to a GO!

Navigation

[0] Message Index

[*] Previous page

Go to full version