Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: amaranth on February 12, 2013, 11:55:19 PM

Title: Get File Name By Index
Post by: amaranth on February 12, 2013, 11:55:19 PM
This script returns the name of a file at a specific index in a Resource Folder. Fields are:


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Files")]
[Tooltip("Get the name of a file, using its index, in a specified resource folder.")]
public class GetFileNameByIndex : FsmStateAction
{
[Tooltip("The name of the folder where the file is located. If no folder name is entered, all Resource files are returned.")]
public FsmString folderName;

[Tooltip("The index of the file inside the folder. Index starts at 0.")]
public FsmInt fileIndex;

[Tooltip("The name of the file.")]
[UIHint(UIHint.Variable)]
public FsmString fileName;


public override void Reset()
{
folderName = null;
fileIndex = 0;
fileName = null;

}

public override void OnEnter()
{
DoGetFileName();
Finish();
}


void DoGetFileName()
{
Object[] resourceDir = Resources.LoadAll(folderName.Value);
fileName.Value = resourceDir[fileIndex.Value].name;
}

}
}