GithubHelp home page GithubHelp logo

ivanmurzak / unity-theme Goto Github PK

View Code? Open in Web Editor NEW
94.0 1.0 6.0 2.46 MB

Create palettes of colors and components for change specific color on a specific visual element. Very useful to UI.

License: MIT License

C# 36.14% Batchfile 1.29% ShaderLab 53.31% HLSL 9.27%
unity unity-plugin ugui ui

unity-theme's Introduction

Unity-Theme

npm openupm License Stand With Ukraine

Create palettes of colors and components to change specific colors on a specific visual element. Very useful for UI.

Unity-Theme-1

Features

  • ✔️ Name colors
  • ✔️ Create custom themes with names
  • ✔️ Add as many colors as you need
  • ✔️ Name a theme as you want
  • ✔️ Change theme any moment by name
  • ✔️ Bind color to: Image, SpriteRenderer, TextMeshPro, etc
  • ✔️ Easy way to add custom color binder by new C# class with just a few lines of code
  • ✔️ Rename color even after binding to a component, with no broken links

Installation

openupm add extensions.unity.theme

Usage

  • Go to Window/Unity-Theme
  • Customize color palettes as you want
  • Add ColorBinder components to a target GameObject

Color Binder

A 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:

  • ImageColorBinder
  • SpriteRendererColorBinder
  • TextMeshProColorBinder

Unity-Theme-Binder

Color palettes

Modify palettes, instant response with all connected GameObjects.

Unity-Theme-Palettes

C# Api

Colors

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();

Themes

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();

Create a custom ColorBinder

If 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 : BaseColorBinder
    {
        [SerializeField] TextMeshProUGUI textMeshPro;

        protected override void Awake()
        {
            if (textMeshPro == null) textMeshPro = GetComponent<TextMeshProUGUI>();
            base.Awake();
        }
        protected override void SetColor(Color color)
        {
            textMeshPro.color = color;
        }
    }
}

Other


Migration from 2.x.x version

❗❗❗WARNING Before you start the migration, please close Unity project to avoid any data loss. When you finished, you need to delete the Assets/Resources/Unity-Theme Database.asset file.

The version 3.x.x 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.

To do

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.

Sample of 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.

  colors:
  - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c
    name: Primary
  - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8
    name: Primary Text
  - guid: 465741bc-25d8-4722-a981-7e4a18074d83
    name: Primary Container
  themes:
  - guid: 6d1fce4e-1938-4d6d-93b0-b4b9f6497293
    expanded: 1
    themeName: Light
    colors:
    - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c
      color: {r: 0.40392157, g: 0.3137255, b: 0.6431373, a: 1}
    - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8
      color: {r: 1, g: 1, b: 1, a: 1}
    - guid: 465741bc-25d8-4722-a981-7e4a18074d83
      color: {r: 0.91764706, g: 0.8666667, b: 1, a: 1}
  - guid: 54c71f36-6023-4d84-bce7-c8192cf7ba40
    expanded: 1
    themeName: Dark
    colors:
    - guid: 6b934efb-0b9b-42fd-82fd-7a0dbd1de53c
      color: {r: 0, g: 0.4784314, b: 1, a: 1}
    - guid: 520b0288-c5e4-4106-95ae-095ad2dcceb8
      color: {r: 1, g: 1, b: 1, a: 1}
    - guid: 465741bc-25d8-4722-a981-7e4a18074d83
      color: {r: 0.15294118, g: 0.15294118, b: 0.15686275, a: 1}

Sample of 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.

{
  "debugLevel": 2,
  "currentThemeIndex": 1,
  "colors": [
    { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "name": "Primary" },
    { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "name": "Primary Text" },
    { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "name": "Primary Container" }
  ],
  "themes": [
    {
      "guid": "4cfe4185-bc3e-4247-969f-1da1d3f2bdec",
      "expanded": false,
      "themeName": "Light",
      "colors": [
        { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#6750A4FF" },
        { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" },
        { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#EADDFFFF" }
      ]
    },
    {
      "guid": "dca52c83-4f79-4fee-854e-0defe9ccbe07",
      "expanded": true,
      "themeName": "Dark",
      "colors": [
        { "guid": "6b934efb-0b9b-42fd-82fd-7a0dbd1de53c", "colorHex": "#007AFFFF" },
        { "guid": "520b0288-c5e4-4106-95ae-095ad2dcceb8", "colorHex": "#FFFFFFFF" },
        { "guid": "465741bc-25d8-4722-a981-7e4a18074d83", "colorHex": "#272728FF" }
      ]
    }
  ]
}

unity-theme's People

Contributors

ivanmurzak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

unity-theme's Issues

Current theme in Editor view does not update when changed by script

When in the Unity-Theme Settings page in the editor, the 'Current Theme' dropdown field is not updated if the current game theme is changed in Play mode. Ideally, if this could subscribe to change events for the current theme, this would be useful for debugging scripts, as well as avoiding confusion where the game may be presenting a different theme from what the Settings page is currently indicating.

The behaviour was observed when calling Theme.Instance.SetOrAddTheme("theme name", true);

(Thank you for this project, by the way - it's absolutely what I've needed for a long time, and have finally been able to try for a hobby project with the removal of ODIN.)

The type or namespace BaseColorBinder could not be found

Hi there,

I am unable to extend BaseColorBinder and get a missing assembly reference. I have tried both "using Unity.Theme.Binders" as well as adding my script to the "Unity.Theme.Binders" namespace.

Am I missing something or is there an issue with this?

Cheers,
Cody

Color still changes while component is disbaled

I have to toggle between two color properties. Since I can seem to get it to change colors at runtime with the same component I created two binders one is an active binder and one is a inactive binder for spriterenderers. If I create a prefab and add the components but turn them off they still change the color of the spriterenderer when adding the prefab to my scene even tho they are disabled it still runs on awake.

Themes

I am trying to extend this package to fit what I am trying to do. How can I access themes list in ThemeDatabase? It doesn't recognize theme as a property even though its used in the script.

Also I see no functionality to allow for runtime changes for things like toggles. Changing from a toggle active to toggle inactive. Most functionality is not exposed to account for it.

Also another issue I came across was hidden objects when a theme is changed do not update even when the object become active.

Changes in Theme Window not saving

Hey! I opened a ticket recently mentioning that changes made to the theme window didn't save, it happened 3 more times since last time. It seems to be when color changes are made without any changes in the number of themes or colors. When opening back the project, it just loads the old colors that were saved last time. Let me know if you need any kind of detail I can provide! Thank you!

Unity-Theme version: 2.0.1
Unity version: 202.3.5f1

Change binder's color in runtime

Hey! Is there an actual way to change the color of the binder attached via script? Or any way to access the colors of the current theme? Some situations require to dynamically update component's color in runtime.

Some other comments:

  • in the readme the package name includes a "`" at the end which prevents installation
  • happened only once but when closing Unity and opening back all the changes done in the theme window were reverted (scene was saved before closing)
  • would be great to re-order colors in the theme window

Thanks a bunch for your work, it's a very clean asset to manage themes!

Unity-Theme database was not found

Just after installing the package this issue appears when clicking on "Window/Unity Theme"

Unity version: 2022.3.5f1
New clean project

Changing theme at runtime

Hi there,

Thank you for sharing this wonderful asset. Is it possible to change the theme at runtime? I am hoping to use this to implement a day/night mode on my game.

Cheers,
Cody

Issue when rebuild Library folder when using URP and Unity-Theme

After deleting Unitys library folder (for reasons), there was a problem recreating the folder when using both URP and Theme. After starting Unity again, I got a lot of the following errors and my theming was broken:

Creating Unity-Theme database file at Assets/Resources/Unity-Theme Database.asset UnityEngine.Debug:Log (object) Unity.Theme.Theme:GetOrCreateInstance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Editor.cs:17) Unity.Theme.Theme:get_Instance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Singleton.cs:16) Unity.Theme.Binders.BaseColorBinder:OnValidate () (at ./Library/PackageCache/[email protected]/Scripts/Binders/BaseColorBinder.cs:69)

Calls to "AssetDatabase.CreateAsset" are restricted during asset importing. AssetDatabase.CreateAsset() was called as part of running an import. Please make sure this function is not called from ScriptedImporters or PostProcessors, as it is a source of non-determinism and will be disallowed in a forthcoming release. UnityEngine.StackTraceUtility:ExtractStackTrace () Unity.Theme.Theme:GetOrCreateInstance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Editor.cs:28) Unity.Theme.Theme:get_Instance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Singleton.cs:16) Unity.Theme.Binders.BaseColorBinder:OnValidate () (at ./Library/PackageCache/[email protected]/Scripts/Binders/BaseColorBinder.cs:69)

Calls to "AssetDatabase.SaveAssets" are restricted during asset importing. UnityEngine.StackTraceUtility:ExtractStackTrace () Unity.Theme.Theme:GetOrCreateInstance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Editor.cs:29) Unity.Theme.Theme:get_Instance () (at ./Library/PackageCache/[email protected]/Scripts/Config/Theme.Singleton.cs:16) Unity.Theme.Binders.BaseColorBinder:OnValidate () (at ./Library/PackageCache/[email protected]/Scripts/Binders/BaseColorBinder.cs:69)

If I remove the URP from the manifest before forcing Unity to recreate the library folder and add it back afterward, it works as expected.
Although this workaround is straightforward, it might be worth investigating this problem further.

The type or namespace name 'DropdownField' could not be found

Hi!

Just found your code and wanted to test it out, but right after the installation I am having an issue:

Library\PackageCache\[email protected]\Editor\Scripts\ThemeWindowEditor.cs(19,17): error CS0246: The type or namespace name 'DropdownField' could not be found (are you missing a using directive or an assembly reference?).

Screenshot_1

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.