Skip to content

Commit 9149437

Browse files
authored
Merge pull request #41 from IvanMurzak/feature/material-color-binder
Add theme color binders for various renderers
2 parents c7ddda3 + 773911e commit 9149437

File tree

62 files changed

+5287
-1777
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5287
-1777
lines changed

.claude/settings.local.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(if not exist \"c:\\Projects\\Unity\\Unity-Theme\\docs\" mkdir \"c:\\Projects\\Unity\\Unity-Theme\\docs\")",
5+
"Bash(mkdir:*)"
6+
],
7+
"deny": [],
8+
"ask": []
9+
}
10+
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ There is a list of built-in color binders:
7878
- ✔️ Light
7979
- ✔️ Image
8080
- ✔️ Button
81+
- ✔️ Shadow
8182
- ✔️ Toggle
82-
- ✔️ Material
83+
- ✔️ Outline
84+
- ✔️ Renderer
8385
- ✔️ Selectable
8486
- ✔️ TextMeshPro
87+
- ✔️ LineRenderer
88+
- ✔️ MeshRenderer
8589
- ✔️ SpriteRenderer
90+
- ✔️ SkinnedMeshRenderer
91+
- ✔️ SpriteShapeRenderer
8692

8793
![Unity-Theme-Binder](https://github.com/IvanMurzak/Unity-Theme/assets/9135028/6198af48-9f0e-4cda-b5e9-40508bbd5c45)
8894

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(gh pr list:*)",
5+
"Bash(gh pr view:*)",
6+
"Bash(gh pr diff:*)"
7+
],
8+
"deny": [],
9+
"ask": []
10+
}
11+
}

Unity-Theme/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ crashlytics-build.properties
8282

8383
# Appodeal
8484
/Assets/Appodeal/**
85-
/Assets/Appodeal.meta
85+
/Assets/Appodeal.meta
86+
87+
# MCP Servers
88+
.vscode/mcp.json

Unity-Theme/Assets/Resources/Unity-MCP-ConnectionConfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"EnabledResources": [
1010
"*"
1111
],
12-
"Host": "http://localhost:8080",
12+
"Host": "http://localhost:10088",
1313
"TimeoutMs": 10000,
14-
"KeepConnected": false
14+
"KeepConnected": true
1515
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using UnityEngine;
2+
3+
namespace Unity.Theme.Binders
4+
{
5+
/// <summary>
6+
/// Binds theme colors to a Renderer's material color
7+
/// Supports binding the main material color property or a custom shader property
8+
/// </summary>
9+
public abstract class GenericRendererColorBinder<T> : GenericMultiColorBinder<T> where T : Renderer
10+
{
11+
// Color entry index for material's main color
12+
protected const int MATERIAL_COLOR_INDEX = 0;
13+
14+
[SerializeField]
15+
[Tooltip("Enable to use a custom material property name instead of the default color property")]
16+
protected bool useCustomProperty = false;
17+
18+
[SerializeField]
19+
[Tooltip("Custom shader property name to bind the color to (e.g., '_BaseColor', '_EmissionColor')")]
20+
protected string customMaterialColorProperty = "_Color";
21+
22+
/// <summary>
23+
/// Defines the color entry labels for Renderer's material
24+
/// </summary>
25+
protected override string[] ColorEntries => new string[]
26+
{
27+
"Material Color"
28+
};
29+
30+
protected override void SetColors(T targetComponent, Color[] colors)
31+
{
32+
if (colors == null || colors.Length <= MATERIAL_COLOR_INDEX)
33+
{
34+
LogError("Invalid colors array provided to SetColors.");
35+
return;
36+
}
37+
if (targetComponent.material != null)
38+
{
39+
if (useCustomProperty && !string.IsNullOrEmpty(customMaterialColorProperty))
40+
{
41+
targetComponent.material.SetColor(customMaterialColorProperty, colors[MATERIAL_COLOR_INDEX]);
42+
}
43+
else
44+
{
45+
targetComponent.material.color = colors[MATERIAL_COLOR_INDEX];
46+
}
47+
}
48+
}
49+
50+
protected override Color[] GetColors(T target)
51+
{
52+
if (target.sharedMaterial != null)
53+
{
54+
Color color;
55+
color = (useCustomProperty && !string.IsNullOrEmpty(customMaterialColorProperty))
56+
? (target.sharedMaterial.HasProperty(customMaterialColorProperty)
57+
? target.sharedMaterial.GetColor(customMaterialColorProperty)
58+
: Color.white)
59+
: target.sharedMaterial.color;
60+
61+
return new Color[] { color };
62+
}
63+
64+
return new Color[] { Color.white };
65+
}
66+
}
67+
}

Unity-Theme/Assets/root/Scripts/Binders/Base/LogableMonoBehaviour.cs.meta renamed to Unity-Theme/Assets/root/Scripts/Binders/Base/GenericRendererColorBinder.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unity-Theme/Assets/root/Scripts/Binders/ButtonColorBinder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using UnityEngine;
2-
using UnityEngine.UI;
32

43
namespace Unity.Theme.Binders
54
{
65
/// <summary>
76
/// Binds theme colors to a Unity Button's ColorBlock
87
/// Supports binding all 5 button states: Normal, Highlighted, Pressed, Selected, and Disabled
98
/// </summary>
10-
[RequireComponent(typeof(Button))]
9+
[AddComponentMenu("Theme/Button Color Binder")]
1110
public class ButtonColorBinder : SelectableColorBinder
1211
{
1312
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
4+
namespace Unity.Theme.Binders
5+
{
6+
/// <summary>
7+
/// Binds theme colors to a Unity Button's ColorBlock
8+
/// Supports binding all 5 button states: Normal, Highlighted, Pressed, Selected, and Disabled
9+
/// Requires a Button component to be present
10+
/// </summary>
11+
[RequireComponent(typeof(Button))]
12+
[AddComponentMenu("Theme/Button Color Binder (Required)")]
13+
public class ButtonColorBinderRequired : ButtonColorBinder
14+
{
15+
}
16+
}

Unity-Theme/Assets/root/Scripts/Binders/ButtonColorBinderRequired.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)