Class ButtonClickSoundPlayer
Finds all UnityEngine.UI.Button, UnityEngine.EventSystems.EventTrigger, and UnityEngine.UI.Toggle components and adds a UnityEngine.UI.Button.onClick / UnityEngine.EventSystems.EventTriggerType.PointerUp / UnityEngine.UI.Toggle.onValueChanged event that plays the provided UnityEngine.AudioClip.
The purpose of that is to batch all LlamaSoftware.UI.ButtonClickSoundPlayer.AudioSources for each of these components into a single LlamaSoftware.UI.ButtonClickSoundPlayer.AudioSource. Each AudioSource in the scene has some CPU overhead. Batching controls that will play separately allows a great reduction of AudioSources in the scene, and thsu frees many CPU cycles. This comes at the downside of each control should utilize the same UnityEngine.AudioClip.
If you would like different sounds for a UnityEngine.UI.Button click versus a UnityEngine.UI.Toggle change, you can attach 2 of these components to the root UnityEngine.Canvas and configure one to LlamaSoftware.UI.ButtonClickSoundPlayer.IncludeButtons = true and one to LlamaSoftware.UI.ButtonClickSoundPlayer.IncludeToggles = true.
Inheritance
Namespace: LlamaSoftware.UI
Assembly: LlamaSoftware.UI.dll
Syntax
[RequireComponent(typeof(AudioSource))]
public class ButtonClickSoundPlayer : MonoBehaviour