Com.Notask.Custom Button
Custom-Button-Unity
Unity Project
Download the source from GitHub
README
Custom Button Unity Package
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.
Features
- 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.
Requirements
- 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).
Installation
Clone and Open
- Clone or download this repository.
- In Unity Hub, click Add, then select the project folder.
As a standalone package
Copy the
Assets/Packagefolder into your project'sPackagesdirectory.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.
Usage
- Create or select a UI element with an Image component (e.g., a Button).
- Add the
CustomButton.CustomButtonClasscomponent. - 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.
Code Example
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!");
}
}
Samples
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.
Extending with Custom Presets
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.
Contributing
Contributions are welcome. Please open issues and submit pull requests.
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In