Playmaker Forum

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

Title: Get File Count
Post by: amaranth on February 12, 2013, 11:49:53 PM
This script returns the number of files in a Resource Folder. Fields are:


Resources
-file 1
-file 2
-Folder 1
--file 1
--file 2
--Subfolder 1
---file 1

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 number of files in a resource directory.")]
public class GetFileCount : FsmStateAction
{

[Tooltip("The name of the folder.")]
public FsmString folderName;

[Tooltip("The number of files in the folder")]
[UIHint(UIHint.Variable)]
public FsmInt fileCount;


public override void Reset()
{
folderName = null;
fileCount = 0;
}

public override void OnEnter()
{
DoGetFileCount();

Finish();
}


void DoGetFileCount()
{
Object[] resourceDir = Resources.LoadAll(folderName.Value);
fileCount.Value = resourceDir.Length;
}

}
}
Title: Re: Get File Count
Post by: jeanfabre on February 26, 2014, 01:11:44 PM
Hi,

 Warning with this action, it does indeed LOAD all your resources, sot it can be quite demanding for the memory especially if on mobile.

bye,

 Jean
Title: Re: Get File Count
Post by: MS80 on September 21, 2015, 08:45:52 AM
How could I get the file count of a folder outside the resoures?? I need to get the file count and file names from a specific directory (f.e. C:/Game/Pictures/)! Then I would like to use this information with www action to load images from that directory...

I searched the ecosystem but it seems there is no action which could this right now?!
Title: Re: Get File Count
Post by: jeanfabre on September 25, 2015, 08:07:18 AM
Hi,

 I made an action to do this, it's on the [img=http://j.mp/1Esn1mF]http://Ecosystem[/img]:

GetFileCount (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Files/GetFileCount.cs)

I also put the action originally coming from this thread.

ResourcesCount (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Resources/ResourcesCount.cs)

Bye,

 Jean
Title: Re: Get File Count
Post by: MS80 on September 26, 2015, 04:27:37 PM
Thank you Jean!

As you mentioned somewhere before, using "Resources" is a faster and more comfortable. I want to use both, load external (www object) and internal (resources load) files (sprites). Did not know about "ResourcesCount", this was one I was searching, too! :) I would like to count images in folders - internal or external - and after that store those images in a array!

I have a few problems so far, maybe you have a idea or maybe there already exists a action for it...

- "ResourcesCount" counts a sprite as 2 assets (image and its sprite)
- "Get File Name by Index" is a great action, unfortunatly it has the same issue like "ResourcesCount" as it gets 2 filenames per sprite!
- Is there a similar action like "Get File Name by Index" for external folders (not resources)?

Thanks for you help!!!
Title: Re: Get File Count
Post by: jeanfabre on September 28, 2015, 07:26:43 AM
Hi,

 ok, I made two new actions:

GetFileInfoByIndex (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Files/GetFileInfoByIndex.cs)
ConvertBytesLengthToReadableSize (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Convert/ConvertBytesLengthToReadableSize.cs) ( to get nice file sizes :) )

Bye,

 Jean
Title: Re: Get File Count
Post by: MS80 on September 28, 2015, 05:13:31 PM
These are great Jean, thank you so much!
With these and the other actions you posted before everything is working.

Only one small issue with loading sprites from resources is left: "Get File Name by Index" work perfectly but give me the double count of sprites names in a existing resource directory. Using textures works like expected, but if I go through the sprite names per index every sprite name exists two times?!?

Is there a workaround for this issue or is it my mistake??

PS: it works if I add "typeof (Sprite)"

      void DoGetFileName()
      {
         Object[] resourceDir = Resources.LoadAll(folderName.Value, typeof(Sprite));
         fileName.Value = resourceDir[fileIndex.Value].name;
      }
Title: Re: Get File Count
Post by: jeanfabre on September 29, 2015, 02:07:56 AM
Hi,

 I am not sure there is a fix unless we make this action defining the type you want to get the number of items from.

 Would that do?

 We could make a getResourceCount given a list of types.

 I would however stress at this point that loading resources to get their type is really something you should be careful of and aware this is creating issues with memory consumption. It's only manageable up to a certain number of resources.

 I would strongly suggest you maintain a text based list and use xml or a arrayMaker to parse that list and get an abstract representation of what's available. Yes you loose the automated process, but if you publish on mobile, you may find yourself cornered as your project grows.


Bye,

 Jean
Title: Re: Get File Count
Post by: MS80 on September 29, 2015, 04:44:27 AM
I am not sure there is a fix unless we make this action defining the type you want to get the number of items from.

 Would that do?

Yeah, this would do the job! I tried it but failed to define a list of types variable...

I would however stress at this point that loading resources to get their type is really something you should be careful of and aware this is creating issues with memory consumption. It's only manageable up to a certain number of resources.

 I would strongly suggest you maintain a text based list and use xml or a arrayMaker to parse that list and get an abstract representation of what's available. Yes you loose the automated process, but if you publish on mobile, you may find yourself cornered as your project grows.
Thanks for pointing this out in detail. Yes, I just go this way because of the automation, beeing lazy has its price. I used DataMaker with great success in other projects, just wanted to try some kind of automation  :)
Luckily I do not need it for mobile, anyway I will use it with care.