# CustomToggle

## What for

There is two implementations of CustomToggle -> SpriteToggle and ImageToggle.\
SpriteToggle is used to toggle between two sprites\
ImageToggle is used to toggle between two images\
\
Any CustomToggle <mark style="color:red;">**requires**</mark>**&#x20;Button** component (you can use [**VibroBtn** ](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/ready-to-use-scipts/vibro-button)as Button too).

## How to use

For ImageToggle -> add it to object with Image component. If there was no Button -> Button component will be added. If you want to use VibroBtn -> remove ImageToggle and Button components and add VibroBtn and then ImageToggle.\
\
References will be setuped automaticaly, but you can change it too.

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FpLLrsIFiqjFn7ncMBw9F%2Fimage.png?alt=media&#x26;token=b4afa229-022c-4443-b87a-df7f367cfafb" alt=""><figcaption><p>How setup looks in the inspector</p></figcaption></figure>

Now set default IsOn value and On/Off sprites.\
If you need to use null Off Sprite -> use prefab ToggleWithEmptySprite (unprefab to not override template)

## API

```csharp
/// <summary>
/// arg1 - changed isOn bool value
/// </summary>
public UnityEvent<bool> OnStateChanged = new UnityEvent<bool>();

/// <summary>
/// You can change toggle state IsOn = true/false
/// </summary>
public bool IsOn;

/// <summary>
/// Sets opposite state
/// </summary>
public void Toggle();
```
