Selecting JSON file to use in game

I am creating a quiz game. The trivia used for each game is stored in a JSON file in my StreamingAssets folder.
Path example: Assets/StreamingAssets/Games/MusicGame1.json

There are multiple games available to play and I want the user to be able to select which JSON file to use on the start menu. Is there a way that they can view all of these JSON files and select the one they want to use?

My current solution is to use an input field to type in the game name, this gets plugged into the string for the path such aspathString = "StreamingAssets/Games/" + value + ".json"
This works fine if you know the game you want to use and the path, but not super user friendly.

Thanks for the help!
Ed

I think I’d consider this solved if the game was able to see how many files there are in Assets/StreamingAssets/Games, then create a List of the file names.

You might try this if you want the OS’s Open File dialog: When I Want to use OpenFileDialog in unity ,the Script can't Compile - Questions & Answers - Unity Discussions

1 Like

If you want to roll your own, try Get Files from Directory [C#]

1 Like

Easy enough. You can use Application.streamingAssetsPath to grab that path and use something like Directory.GetFiles to grab the file names at your path. Then just make a dropdown populated with your data.

1 Like

Thank you for your replies!!

I was able to grab what I needed with the following code:

string[] s = Directory.GetFiles(Application.streamingAssetsPath + "/Games/", "*.json");

        foreach (var x in s)
            print(x);

Worked just fine!!!

Now onto the dropdown!