Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: ch1ky3n on February 28, 2021, 01:12:45 AM

Title: List to Array
Post by: ch1ky3n on February 28, 2021, 01:12:45 AM
Can anyone help me inspect whether this is the right way to convert from a list to
FSM array. This is a 3rd party store called "BTagged" it works really fast.

Code: [Select]
//Created by Ch1ky3n

using BOC.BTagged;
using UnityEngine;
using System.Collections.Generic;


namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("BTagged")]
[Tooltip("Find all game objects with specific tag and store it in Fsm Array")]
public class TaggedFindManyGameObjectsByTag: FsmStateAction
{

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Array Variable to use.")]
[ArrayEditor(VariableType.GameObject)]
public FsmArray array;

[Tooltip("the tag")]
public Tag tag;

private List<GameObject> List;

public override void Reset()
{
array = null;
tag = null;

}

public override void OnEnter()
{
var query = BTagged.Find(tag);
List = query.GetGameObjects();

for (int i = 0; i < List.Count; i++)
{
array.Resize(array.Length + 1);
array.Set(array.Length - 1, List[i]);
}

Finish();
}

}
}
?

It works, but I'm not sure if this is the right way to do it. Especially when performing against many objects.

also, is it better to do it with The Array List Proxy? if so can anyone help me on how to do it?

Thank you in advance!