Open gm3 opened 1 year ago
Here's a breakdown of how the script works:
First, the script defines two classes: JSONData
and Trait
. These are used to model the structure of the JSON data that you provided. Each JSONData
object contains a list of Trait objects.
In the ConvertJSONFiles
function, the script first gets all the file paths of .json
files in the Resources folder.
The script then creates two GameObject
variables, masculineParent
and feminineParent
, which will serve as the top-level parent objects for the masculine and feminine bodies.
For each file path in the list, the script reads the file content and deserializes it into a JSONData
object.
The script then finds the Trait
in the JSONData
object where the trait type is "Body"
and the value is either "Masculine"
or "Feminine"
. If such a trait is found, the script creates the appropriate parent GameObject (if it hasn't been created yet).
For each Trait
in the JSONData
object that is not "Body"
, the script creates a child GameObject under the appropriate parent (masculine or feminine) for the trait type, if it doesn't exist yet, and a child GameObject under the trait type for the trait value, if it doesn't exist yet.
The FindChildByName
function is a helper function that searches for a child GameObject
with a given name under a given parent GameObject. If such a GameObject is found, it is returned; otherwise, null is returned.
Once all the Trait
objects in the JSONData
have been processed, the script moves on to the next file path. When all the file paths have been processed, the function logs "Conversion complete!"
to the console.
In summary, this script goes through each .json file in the Resources folder, deserializes the file content into a JSONData
object, and creates a hierarchy of GameObjects based on the traits in the JSONData
object. The hierarchy is structured such that there are two top-level parent GameObjects, "Masculine" and "Feminine", and under each parent, there are child GameObjects for each trait type, with further child GameObjects under each trait type for each trait value.
This was created for specific project but need to port it to boom-tools importer, this version looks for 2 main classes in the Body trait, specific JSON data, and uses that for specific nesting, so have to make it work more modular, and perhaps have some options to on which triats string names would be the Parent->Trait_type->Value structure