Skip to content

How to Create a new Modifier

James Veugelaers edited this page May 6, 2025 · 4 revisions

A modifier is a step in the build process that is run after retrieving all sources. Modifiers will change the files in a cached directory - avoiding changing original files.

The Build Uploader uses reflection to find all classes inheriting ABuildConfigModifer to display them in the dropdown. BuildModifierAttribute is used to define static data about the modifier such as the the text shown in the dropdown.

using System.Collections.Generic;
using System.Threading.Tasks;
using Wireframe;

[BuildModifier("Custom Modifier")]
public class CustomModifier : ABuildConfigModifer
{
    public override bool IsSetup(out string reason)
    {
        // Return false to prevent a build from starting if this is incorrectly setup.
        reason = string.Empty;
        return true;
    }

    public override Task<bool> ModifyBuildAtPath(string cachedDirectory, BuildConfig buildConfig, int buildIndex, BuildTaskReport.StepResult stepResult)
    {
        // Custom logic to modify the build at the specified path
        // For example, you could add custom files or modify them here

        // Return true if the modification was successful
        return Task.FromResult(true);
    }

    public override Dictionary<string, object> Serialize()
    {
        // Serialize the custom modifier's state to a dictionary
        var data = new Dictionary<string, object>
        {
            { "CustomProperty", "CustomValue" } // Example property
        };

        return data;
    }

    public override void Deserialize(Dictionary<string, object> data)
    {
        // Deserialize the custom modifier's state from a dictionary
        if (data.TryGetValue("CustomProperty", out var customValue))
        {
            // Use the deserialized value
            // For example, you could set a property or perform some action based on the value
        }
    }

    protected override void OnGUIExpanded(ref bool isDirty)
    {
        // Custom GUI logic for the modifier
        // For example, you could add custom fields or controls here

        // Example of a custom field
        // EditorGUILayout.TextField("Custom Field", customValue);
        
        // Mark as dirty if any changes are made
        if (isDirty)
        {
            // Perform any necessary actions when the state changes
        }
    }
}

Clone this wiki locally