So I have a great number of characters from different stories, and I want my Character Selection screen to automatically separate them by “story”. These “stories” are simply folders to which new characters are added.
For example, if somebody makes a new character for my game, I want it to be as easy to placing the new character in my “assets/characters/stories/Peter Pan” folder or what-have-you.
My selection screen would then display folders and sub-folders automatically, listing every character inside.
I plan to use Resources.FindObjectsOfTypeAll(typeof(Character));, which should in theory find any prefab with my “Character” script attached.
Will this work?
After that, all that I really need to do is figure out how to read the folders and list them in my Selection screen. How can I figure out the location folder for each of these characters I’m loading?
Once you’ve got the path, you can String.Split() it up by slashes and dots and anything your heart desires.
(In this case, you’d split by slash, and then look at second-to-last index of the resulting array)
//the direction of the slash is environment specific... or you can use some sort of environment variable
string[] pathSplit = path.Split('\');
Debug.Log("Character is in story: " + pathSplit[pathSplit.Length-1]);
Ah, fancy! Perhaps if I get at least a main menu/character selection going, I’ll have more flexibility in my workflow. At the moment I’m spending way too much time stuck on figuring one thing out that the rest of my game is suffering. xP