Add Event Listener for Preset Loading

  • Views Views: 446
  • Last updated Last updated:
  • This code snippet is used to add an event listener to your script to wait for a preset to be loaded and execute a method to perform tasks.

    In this example, the code will get listen for an Appearance Preset to be loaded and output the message "Preset Loaded" with the preset name in the message window.


    C#:

    public PresetManager pm;

    public override void Init() {
    try {
    JSONStorable presetJS = containingAtom.GetStorableByID("AppearancePresets");
    pm = presetJS.GetComponentInChildren<PresetManager>();
    pm.postLoadEvent.AddListener(OnPresetLoaded);
    }
    catch (Exception e) {
    SuperController.LogError("Exception caught: " + e);
    }
    }

    C#:

    protected void OnPresetLoaded() {
    SuperController.LogMessage("Preset Loaded - " + pm.presetName);
    }

    Some additional properties include:

    presetNameReturns the name of the preset. Includes var name when applicable.
    GetStoreRootPath()Returns root path to the preset. Ex: "Custom\Atom\Person"
    storeFolderNameReturns the folder within "Custom\Atom\Person\" the preset resides in. Example: "Hair" for a Hair preset.
    GetStoreFolderPathReturns full path to the preset. Ex: "Custom\Atom\Person\Appearance"
    IsPresetInPackageReturns true if contained in a var package. Otherwise false.
    customPathReturns preset base path "Person\"
    includePhysicalReturns true/false according to the 'Include Physical' checkbox on General presets.
    includeAppearanceReturns true/false according to the 'Include Appearance' checkbox on General presets.
Back
Top Bottom