Custom Button is a flexible and extensible Unity UI Button replacement that supports color tint, sprite swap, and animation transitions for button states. Built as a Unity Package, it integrates seamlessly with the Unity Package Manager.
- Color tint transition for Normal, Highlighted, Pressed, Selected, and Disabled states.
- Sprite swap transition for UI Image components.
- Animation transitions using customizable ScriptableObject presets.
- Default animation presets included: Move, Scale, Rotate, Shake, Resize, and Multi Animation.
- Support for child graphics and TextMesh Pro text color transitions.
- Easy to extend with custom animation presets.
- Sample scenes demonstrating usage.
- Unity Editor 2023.1 (23f1) or later.
- Unity UI package (
com.unity.ugui
). - TextMesh Pro (
com.unity.textmeshpro
). - (Optional) Universal Render Pipeline (
com.unity.render-pipelines.universal
).
- Clone or download this repository.
- In Unity Hub, click Add, then select the project folder.
-
Copy the
Assets/Package
folder into your project'sPackages
directory. -
Rename the folder to
com.notask.custom-button
. -
In your project's
Packages/manifest.json
, add:"com.notask.custom-button": "file:com.notask.custom-button"
-
Save and return to Unity; the package will appear in the Package Manager.
- Create or select a UI element with an Image component (e.g., a Button).
- Add the
CustomButton.CustomButtonClass
component. - Assign the Target Graphic field (defaults to the Image on the GameObject).
- Enable and configure transitions:
- Color Tint
- Sprite Swap
- Animation (drag preset assets from
Assets/Package/Runtime/Resources/DefaultPresets
).
- (Optional) Add sub-transitions for additional graphics or texts.
using CustomButton;
using UnityEngine;
public class Example : MonoBehaviour
{
public CustomButtonClass customButton;
void Start()
{
customButton.onClick.AddListener(OnButtonClicked);
customButton.onStateChange += state => Debug.Log("State changed to: " + state);
}
private void OnButtonClicked()
{
Debug.Log("Custom Button Clicked!");
}
}
Sample scenes are included:
Assets/Package/Samples/Overview/sample-CustomButton.unity
To import samples:
- Open the Package Manager (
Window > Package Manager
). - Find Custom Button.
- Click Import Samples.
To create a custom animation preset:
- In the Project window, right-click: Create > Custom Button > Presets > [PresetType].
- Configure the preset parameters in the Inspector.
- Assign the preset to your Custom Button component.
Contributions are welcome. Please open issues and submit pull requests.