Wearable Set Data

A pre-configured set of Wearables, Materials and Morphs.

The Wearable Set Data class holds strings and arrays containing references to the wearables, materials and cosmetics for a Wearable Set. Its’ purpose is to easily convert JSON data to and from Wearable Sets, which can be equipped to the Character.

The Modular Character Manager can export the currently equipped set to Wearable Set Data. It can also convert Wearable Set Data to a Wearable Set to be applied to the character. In this way, you can save and load a Wearable Set during Runtime.

Creating a JSON file with Wearable Set Data

The demo scenes capture the current Wearable Set configuration from a character and save it as a JSON file. You can do so using the SaveCurrentSetAsData function in the Modular Character Manager.

Include the following block of code in your script (remember to include the using Stellar; statement at the top of the code).

Calling the function will generate Wearable Set Data directly from the current character configuration. You will need to pass the Modular Character Manager, a new set name, and a save location to the function.

The saved data can be captured and loaded during Runtime using the persistent path or your own save tools.

This code will convert the current Wearable Set to Wearable Save Data and then convert it to JSON data. Finally, it will write all of the JSON data to a file and save it to the specified location.


public void SaveDataAsJSON(ModularCharacterManager _manager, string _newSetName, string _setSavePath)
{
    WearableSetData saveData = _manager.SaveCurrentSetAsData(_newSetName);
   
    string dataToSave = JsonUtility.ToJson(saveData);
    System.IO.File.WriteAllText(_setSavePath + "/" + _newSetName + ".json", dataToSave);
    
}

Loading and Equipping a Wearable Set from a JSON file

You can load a JSON file containing Wearable Set Data and convert it to a Wearable Set to be equipped using the ConvertWearableSetData function in the Modular Character Manager.

Include the following block of code in your script (remember to include the using Stellar; statement at the top of the code).

Calling the function will load a JSON file, convert the Wearable Set Data to a Wearable Set, and then equip that set to the Character. You will need to pass the Modular Character Manager, a new set name, and a save location to the function.

       
public void LoadCharacterFromJSON(ModularCharacterManager _manager, string _fileName, string _setLoadPath)
{
    string fileName = _setLoadPath + _fileName + ".json";
    
    // Check if the file exists
    if (System.IO.File.Exists(fileName))
    {
        WearableSetData setData = JsonUtility.FromJson<WearableSetData>(System.IO.File.ReadAllText(fileName));
        WearableSet newSet = _manager.ConvertWearableSetData(setData);
        _manager.EquipWearableSet(newSet, true);
    }
    else
    {
        Debug.Log("The specified file does not exist.");
    }
}

Last updated