The idea is to replace the implementation of the old SettingsHUD
with a new
architecture based on 4 independent concepts: Panel, Sections,
Widgets and Controls.
PANEL
and will contain one or more
SECTIONS
.
SECTION
will contain one or more WIDGETS
.WIDGET
will contain one or more CONTROLS
.This new philosophy would lead to the following advantages:
The new Settings ecosystem is divided into the modules defined in the next example image:
There will be only one PANEL
module (it will be the own
SettingsPanelHUD
) and will represent the container for all the
SECTIONS
that will exist as children.
SECTION
associated with each menu button.SECTIONS
.
There could be several SECTION
modules and will represent the container for all
the WIDGETS
that will exist as children.
WIDGETS
(as a vertical layout) into each
SECTION
.
There could be several WIDGET
modules and will represent the container for all
the CONTROLS
modules that will exist as children.
CONTROLS
(in several vertical layouts) into
each WIDGET
.
There could be several CONTROL
modules and will represent the implementations of
each specific setting (for example: a slider for a volume, a checkbox for activate/deactivate
some option, etc.).
Finally the whole configuration of the SettingsPanelHUD
involves the next
Scriptable Objects:
It includes a list of SECTIONS
(represented by the “SettingsSectionModel” model)
that will be part of the settings main panel. These SECTIONS
will be
automatically instantiated into the HUD at the beginning of its life-cycle.
It includes all the needed information for a SECTION
and a list of
WIDGETS
(represented by the “SettingsWidgetModel” model) that will be part of
this SECTION
. These widgets will be automatically instantiated into the HUD at
the beginning of its life-cycle.
It includes all the needed information for a WIDGET
and a list of
CONTROLS
(represented by the “SettingsControlModel” model) that will be part of
this WIDGET
. These CONTROLS
will be automatically instantiated into
the HUD at the beginning of its life-cycle.
It includes all the needed information for a CONTROL
.
The main benefits of this architecture are:
CONTROLS
faster.Assets\Scripts\MainScripts\DCL\Controllers\Settings\SettingsControllers\SpecificControllers
and create a new controller class called {control name}ControlController
.
SettingsControlController
.[CreateAssetMenu(menuName = "Settings/Controllers/Controls/{control name}",
fileName = "{control name}ControlController")]
.
SettingsControlController
:
object GetStoredValue()
: It should return the stored value of the control.
The return value should be a bool (for toggle controls), a float (for slider controls)
or an int (for spin-box controls).
void UpdateSetting(object newValue)
: It should contain the specific logic
for the settings control that will be triggered when the its state changes. The received
newValue
is the new state and can be a bool (for toggle controls), a float
(for slider controls) or an int (for spin-box controls).
SettingsControlController
:
void Initialize(ISettingsControlView settingsControlView)
: This is the
place where you will be able to initialize anything you need for the control behaviour.
void OnDestroy()
: The logic put here will be triggered when the control is
destroyed.
SettingsControlController
:
currentGeneralSettings
: This field will access to the general settings
currently stored in the Setting
singleton class.
currentQualitySetting
: This field will access to the quality settings
currently stored in the Setting
singleton class.
using DCL.SettingsController;
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace DCL.SettingsControls
{
[CreateAssetMenu(menuName = "Settings/Controllers/Controls/Bloom", fileName = "BloomControlController")]
public class BloomControlController : ToggleSettingsControlController
{
public override object GetStoredValue()
{
return currentQualitySetting.bloom;
}
public override void UpdateSetting(object newValue)
{
// Code related to store the setting value in our Settings class
currentQualitySetting.bloom = (bool)newValue;
// Code related to apply the setting
if (QualitySettingsReferences.i.postProcessVolume)
{
if (QualitySettingsReferences.i.postProcessVolume.profile.TryGet<Bloom>(out Bloom bloom))
{
bloom.active = currentQualitySetting.bloom;
}
}
}
}
}
SettingsPanelHUD\Resources\Controls
.Assets -> Create -> Settings -> Controllers -> Controls
and choose
your new controller created.
{control name}ControlController
.SettingsPanelHUD\Configuration\Controls
.Assets -> Create -> Settings -> Configuration -> Controls
and
choose one of the available type of controls: Toggle, Slider or Spin-Box.
{control name}ControlConfiguration
.
SettingsPanelHUD\Configuration\Widgets
.WIDGET
where you want to put the new control.
And it is all! When you run the application, you will notice that the
SettingsPanelHUD
will have created your new control in the correct place.
NOTE: For more examples of controls, you can take a look to all the controllers that we
currently have in the folder
Assets\Scripts\MainScripts\DCL\Controllers\Settings\SettingsControllers\SpecificControllers
.