Ilumisoft Docs
  • Products
  • Bundles
    • Ultimate Asset Bundle
  • Tools
    • Visual State Machine
      • Setup
      • Create your first State Machine
      • Open the Graph Editor
      • Create a State
      • Create a Transition
    • Scene Creator
    • Script Templates
      • Create Script from Template
      • Create a Custom Template
      • Add, Edit or Remove Templates
    • Startup Manager
      • Setup
      • How to Add Systems
      • How It Works
    • Volume Control
      • Setup
      • How to create volume sliders & toggles
      • How to create a volume driven AudioSource
      • How to use the Volume Control API
    • Color Control
    • Graphics Control
      • Getting Started
      • Writing Custom Settings
        • Example 1: Writing the Soft Particles Setting
        • Example 2: Writing the Shadow Setting
    • Game Action System
      • Getting Started
      • Components
        • Game Action Trigger
        • Game Action
        • Game Action Task
      • How To's
        • Creating custom tasks
  • Game Templates
    • Connect
    • Hex
    • Defuse
    • Merge Dice
    • Bubble Pop
    • Downhill Ride
  • Support
    • Help
Powered by GitBook
On this page

Was this helpful?

  1. Tools
  2. Graphics Control
  3. Writing Custom Settings

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.

PreviousWriting Custom SettingsNextExample 2: Writing the Shadow Setting

Last updated 2 years ago

Was this helpful?