创建颜色和组件的调色板,以在特定的可视元素上指定特定的颜色。对于 UI 非常有用。
Create palettes of colors and components to change specific colors on a specific visual element. Very useful for UI.
Image, SpriteRenderer, TextMeshPro, etc| Unity Version | Editor test | Player test | Build test |
|---|---|---|---|
| 2022.3.62f3 | |||
| 6000.3.9f1 |
- You may use double click on the file - Unity will open it
- OR: You may open Unity Editor first, then click on
Assets/Import Package/Custom Package, then choose the file
openupm add extensions.unity.themeWindow/Unity-ThemeColorBinder components to a target GameObjectA component that binds a color to a specific target, such as Image, SpriteRenderer, TextMeshPro, or anything else.
There is a list of built-in color binders:
Modify palettes, instant response with all connected GameObjects.
using Unity.Theme;
Theme.Instance.AddColor("Primary", "#6750A4");
Theme.Instance.AddColor("Primary", Color.white);
Theme.Instance.SetColor("Primary", "#6750A4");
Theme.Instance.SetColor("Primary", Color.white);
Theme.Instance.SetOrAddColor("Primary", "#6750A4");
Theme.Instance.SetOrAddColor("Primary", Color.white);
Theme.Instance.RemoveColorByName("Primary");
Theme.Instance.RemoveColor(colorData);
Theme.Instance.RemoveAllColors();using Unity.Theme;
Theme.Instance.AddTheme("Light");
Theme.Instance.SetOrAddTheme("Light");
Theme.Instance.CurrentThemeName = "Light";
Theme.Instance.CurrentThemeIndex = 0;
Theme.Instance.RemoveTheme("Light");
Theme.Instance.RemoveAllThemes();ColorBinderIf you need to bind color to something else, you may extend from BaseColorBinder as listed below.
using UnityEngine;
using TMPro;
namespace Unity.Theme.Binders
{
[AddComponentMenu("Theme/TextMeshPro Color Binder")]
public class TextMeshProColorBinder : GenericColorBinder
{
protected override void SetColor(TextMeshProUGUI target, Color color)
=> target.color = color;
protected override Color? GetColor(TextMeshProUGUI target)
=> target.color;
}
}2.x.x versionThe version 3.x.x or newer has a different database structure, so you need to migrate your data manually if you want to keep existed binders to still be connected to a right color. The binders are using GUIDs to connect to colors.
❗❗❗Please follow the exact steps order
Close Unity project to avoid any data loss.
Assets/Resources/Unity-Theme Database.asset, put it outside of a project.Assets/Resources/Unity-Theme-Database.json.You need to copy GUIDs from Assets/Resources/Unity-Theme Database.asset to Assets/Resources/Unity-Theme-Database.json. To do that, please take a look at the samples below. You may see what is data format of old and new databases, and how to copy GUIDs. You may ignore color for now, it is easier to change color values later using color picker tool and the screenshot of old color palette.
Assets/Resources/Unity-Theme Database.asset - old file (source)Take a look at the guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c, the file contains it 3 times, depends on your setup. You would need to copy the guid to the Unity-Theme-Database.json file.
…Assets/Resources/Unity-Theme-Database.json - new file (destination)That is the file that you need to make in the end of the migration process. When you done, you may need to close & open Unity project to let Unity-Theme to reload the data.
…2.x.x from the project while Unity is closedopenupm remove extensions.unity.themeopenupm add extensions.unity.themeAssets/Resources/Unity-Theme Database.asset file (original and copy).暂无开放 Issues,或尚未同步最近议题。