The Global Applier allows you to set certain callbacks or size modifiers globally for all occurrences of the specified thing.


You can edit it by clicking Tools -> Better UI -> Settings -> Select Global Applier or by navigating to TheraBytes/Resources/GlobalApplier.



Global Events

You can specify here custom methods you want to invoke whenever a certain control is triggered. This is especially useful for UI-Sounds.


To do that, create a MonoBehviour with your custom public methods and attach it to a prefab. Use that prefab as reference object in the global event.


Here is an example class:


using TheraBytes.BetterUi;

using UnityEngine;

using UnityEngine.Scripting;


public class GlobalCallbackMethods : MonoBehaviour

{

    [Preserve] // Global Applier Event

    public void OnClick(BetterButton button)

    {

        Debug.Log($"{button.name} was clicked.");

    }


    [Preserve] // Global Applier Event

    public void OnToggleChanged(BetterToggle toggle, bool isOn)

    {

        Debug.Log($"{toggle.name}.isOn changed to {isOn}");

    }

}


On Button Clicked

Whenever a Better Button is being clicked, this event is invoked. The Better Button is passed to the method.
Note that "normal" Buttons will not trigger this event.


On Toggle Changed

Whenever a Better Toggle is changing, this event is invoked. The Better Toggle as well as the new isOn state is passed to the method.
Note that "normal" Buttons will not trigger this event.

Note that the event is also not called when changed silently (MyToggle.Set(isOn, sendCallback: false);).



Global Sizer Overrides

There is a list of overrides for every supported sizer type (float, Vector2Int, Vector2, Vector3, Vector4, Margin, Padding - it is like this because of unity's serialization system and performance considerations). 


You can override a certain property of a certain component of one of the supported sizer-types.


When the game starts or the resolution changes, the sizes for every entry will be calculated. This means that nothing will change when the sizer is modified during runtime automatically.

If you want to update the calculated values manually from code, call GlobalApplier.Instance.UpdateCachedValues.

Example: Scroll Sensitivity

A common example is the Scroll Sensitivity of a Better Scroll Rect. In most projects, this should be the same for all Scroll Rects in the application.


To set it once and for all, do the following:

  1. Create a Game Object in the Hierarchy of any scene, add a Better Scroll Rect to it and adjust the "Scroll Sensitivity" sizer down in the "Better UI" Section (not the default "Scroll Sensitivity" field)
  2. Drag the Game Object into any folder in the project window to create a prefab.
  3. Select the Global Applier (Tools -> Better UI -> Settings -> Select Global Applier)
  4. Expand "Global Sizer Overrides" and add an entry to "Float Overrides" (+ button)
  5. Drag and drop the created Prefab into the "Prefab" field of the created entry
  6. Use the dropdown for "Component Type Name" and select "BetterScrollRect"
  7. Use the dropdown for "Sizer Property Name" and select "ScrollSensitivitySizer"
  8. You may set a certain "Screen Config Name". The override will only be applied to the specified screen config name. If left empty, it will only be applied to the fallback config.


After doing so, every Better Scroll Rect in the game will use the "Last Calculated Size" of the created entry for their ScrollSensitivitySizer.