Example 1: Writing the Soft Particles Setting

Graphics Control provides you with two types of settings: The very simple Graphic Toggle Setting and the more generic Multi Option Setting. Graphic Toggle Setting only accepts two states (on or off), while Multi Option Setting allows you to create more complex settings.

The first example will be a setting to control the Soft Particle Quality Option (Project Settings->Quality->Soft Particles), allowing you to enable or disable Soft Particles. Since Soft Particles can either be on or off, GraphicToggleSetting will be the perfect choice as a base class.

Create a new script and name it SoftParticlesSetting.cs with the following content:

using Ilumisoft.GraphicsControl;
using UnityEngine;

[DisallowMultipleComponent]
[AddComponentMenu("Graphics Control/Settings/Soft Particles Setting")]
public class SoftParticlesSetting : ToggleGraphicSetting
{
    public override string GetSettingName()
    {
        return "Soft Particles";
    }
}

Great, you have defined your first custom Graphic Setting! Next open the Graphic Settings Manager Prefab, click AddComponent->Graphics Control->Settings and select the Soft Particles Setting component to add it. Save the changes. When you now run the sample scene in Playmode again, you will notice that there is a Soft Particles option now.

Still there is a catch. The setting is available, but it will not be applied yet. That's because we have not defined what should happen when our SoftParticlesSetting is on or off.

To do so we need to write another simple script, a Graphic Settings Applier. They allow you to define how the settings you create should be applied. Most of the default settings coming with GraphicsControl are applied by the GlobalSettingsApplier component, but when creating your own custom settings, the cleanest way is to simply write an additional component instead of modifying our one.

Create a new script and name it SoftParticlesSettingApplier.cs with the following content:

using Ilumisoft.GraphicsControl;
using UnityEngine;

public class SoftParticlesSettingApplier : GraphicSettingsApplier
{
    public override void ApplySettings()
    {
        if (GraphicSettingsManager.Instance.TryGet<SoftParticlesSetting>(out var setting))
        {
            // Get the selected option
            bool selectedOption = setting.GetSelectedOption();

            // Enable/disable soft particles depending on the selected option
            QualitySettings.softParticles = selectedOption;
        }
    }
}

Open the Graphic Settings Manager Prefab again, click AddComponent and add the SoftParticlesSettingApplier. That's it, when changing the setting at runtime, it will now be applied.

Last updated