Search Unity

Is it possible to dynamically find folders that use a naming convention?

Discussion in 'Scripting' started by firejerm, Apr 28, 2018.

  1. firejerm

    firejerm

    Joined:
    Dec 28, 2012
    Posts:
    43
    Like if I have a set of "level" folders in Resources.
    Level 1, Level 2, Level 3.

    Is it possible to make a C# script that could search for folders with "Level" in the name?

    So if anyone wants to add another level, all they have to do is add a new "Level" folder with the prefabs inside, and the script would automatically find that new folder......without having to add the folder path in inspector.

    I know how to find assets in 1 static folder. just wondering if you can search for folder names too.

    Build target would be Windows PC. So I'm thinking System.IO get directories and enumerate directories would help. But not sure if Unity would allow it though.
     
  2. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    Yes! The folder name is just a string. So you can manipulate and enumerate as needed. There are many examples from c# directly which all work in unity.