Example 2: Writing the Shadow Setting
For the second example, we will write a setting allowing the user to control the shadow settings. When opening the Quality tab in the Project Settings, there are three options that can be set for the shadow setting: Disable Shadows, Hard Shadows Only, Hard and Soft Shadows.
To reflect these three options for our setting, we cannot use the ToggleGraphicSetting from the first example. Instead we use the MultiOptionGraphicSetting.
MultiOptionGraphicSetting is a very flexible base class. It allows you to define the value type of the setting and can be used for any setting which does not has a binary state, e.g. resolution, AA level, etc.
To get strated create a new script, name it ShadowSetting.cs and add the following content:
As you can see the script is a lot larger than the one from the previous example. MultiOptionGraphicSetting is much more powerful than ToggleGraphicSetting, but therefore we need to write a bit more code as a tradeoff. In the Initialize method, we create the options we have, where the first option is represented by a value of 0, the second by 1 and the last by 2.Then we set the initial index by the current shadow quality setting.
With LoadSetting and SaveSetting we can restore the stored value or save it respectively.
Again we also need to write an applier, therefore create a new script called ShadowSettingApplier.cs with the following content:
Here we get the selected option ( which is an integer) and convert it to the ShadowQuality to apply it.
In the last step, open the Graphic Settings Manager Prefab again, click AddComponent and add the ShadowSetting and the ShadowSettingApplier to the prefab. Now when running the sample scene you can change the shadow settings!
Last updated