-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add theme color binders for various renderers #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1685a4f
9aa603c
d704012
5d93adc
a2455d9
5f0ed22
ad91631
d2d9d62
dea395d
b656b91
e88393f
fbd9191
06bb263
499acf6
c59006e
0441e9e
91c5f83
49d23ac
57a2d70
773911e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(if not exist \"c:\\Projects\\Unity\\Unity-Theme\\docs\" mkdir \"c:\\Projects\\Unity\\Unity-Theme\\docs\")", | ||
| "Bash(mkdir:*)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(gh pr list:*)", | ||
| "Bash(gh pr view:*)", | ||
| "Bash(gh pr diff:*)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a Renderer's material color | ||
| /// Supports binding the main material color property or a custom shader property | ||
| /// </summary> | ||
| public abstract class GenericRendererColorBinder<T> : GenericMultiColorBinder<T> where T : Renderer | ||
| { | ||
| // Color entry index for material's main color | ||
| protected const int MATERIAL_COLOR_INDEX = 0; | ||
|
|
||
| [SerializeField] | ||
| [Tooltip("Enable to use a custom material property name instead of the default color property")] | ||
| protected bool useCustomProperty = false; | ||
|
|
||
| [SerializeField] | ||
| [Tooltip("Custom shader property name to bind the color to (e.g., '_BaseColor', '_EmissionColor')")] | ||
| protected string customMaterialColorProperty = "_Color"; | ||
|
|
||
| /// <summary> | ||
| /// Defines the color entry labels for Renderer's material | ||
| /// </summary> | ||
| protected override string[] ColorEntries => new string[] | ||
| { | ||
| "Material Color" | ||
| }; | ||
|
|
||
| protected override void SetColors(T targetComponent, Color[] colors) | ||
| { | ||
| if (colors == null || colors.Length <= MATERIAL_COLOR_INDEX) | ||
| { | ||
| LogError("Invalid colors array provided to SetColors."); | ||
| return; | ||
| } | ||
| if (targetComponent.material != null) | ||
| { | ||
| if (useCustomProperty && !string.IsNullOrEmpty(customMaterialColorProperty)) | ||
| { | ||
| targetComponent.material.SetColor(customMaterialColorProperty, colors[MATERIAL_COLOR_INDEX]); | ||
| } | ||
| else | ||
| { | ||
| targetComponent.material.color = colors[MATERIAL_COLOR_INDEX]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override Color[] GetColors(T target) | ||
| { | ||
| if (target.sharedMaterial != null) | ||
| { | ||
| Color color; | ||
| color = (useCustomProperty && !string.IsNullOrEmpty(customMaterialColorProperty)) | ||
| ? (target.sharedMaterial.HasProperty(customMaterialColorProperty) | ||
| ? target.sharedMaterial.GetColor(customMaterialColorProperty) | ||
| : Color.white) | ||
| : target.sharedMaterial.color; | ||
|
|
||
| return new Color[] { color }; | ||
| } | ||
|
|
||
| return new Color[] { Color.white }; | ||
IvanMurzak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a Unity Button's ColorBlock | ||
| /// Supports binding all 5 button states: Normal, Highlighted, Pressed, Selected, and Disabled | ||
| /// Requires a Button component to be present | ||
| /// </summary> | ||
| [RequireComponent(typeof(Button))] | ||
| [AddComponentMenu("Theme/Button Color Binder (Required)")] | ||
| public class ButtonColorBinderRequired : ButtonColorBinder | ||
| { | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds a theme color to the Image component's color property. | ||
| /// Requires an Image component to be attached to the GameObject. | ||
| /// </summary> | ||
| [RequireComponent(typeof(Image))] | ||
| [AddComponentMenu("Theme/Image Color Binder (Required)")] | ||
| public class ImageColorBinderRequired : ImageColorBinder | ||
| { | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a Light's color. | ||
| /// </summary> | ||
| [AddComponentMenu("Theme/Light Color Binder")] | ||
| public class LightColorBinder : GenericColorBinder<Light> | ||
| { | ||
| protected override void SetColor(Light target, Color color) | ||
| => target.color = color; | ||
|
|
||
| protected override Color? GetColor(Light target) | ||
| => target.color; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds a theme color to the Light component's color property. | ||
| /// This "Required" variant enforces the presence of a Light component. | ||
| /// </summary> | ||
| [RequireComponent(typeof(Light))] | ||
| [AddComponentMenu("Theme/Light Color Binder (Required)")] | ||
| public class LightColorBinderRequired : LightColorBinder | ||
| { | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a LineRenderer's color. | ||
| /// Supports binding separate start and end colors. | ||
| /// </summary> | ||
| [AddComponentMenu("Theme/LineRenderer Color Binder")] | ||
| public class LineRendererColorBinder : GenericMultiColorBinder<LineRenderer> | ||
| { | ||
| // Color entry indices for LineRenderer | ||
| private const int START_INDEX = 0; | ||
| private const int END_INDEX = 1; | ||
|
|
||
| /// <summary> | ||
| /// Defines the color entry labels for LineRenderer's color properties | ||
| /// </summary> | ||
| protected override string[] ColorEntries => new string[] | ||
| { | ||
| "Start", | ||
| "End" | ||
| }; | ||
|
|
||
| protected override void SetColors(LineRenderer targetComponent, Color[] colors) | ||
| { | ||
| targetComponent.startColor = colors[START_INDEX]; | ||
| targetComponent.endColor = colors[END_INDEX]; | ||
| } | ||
|
|
||
| protected override Color[] GetColors(LineRenderer targetComponent) | ||
| { | ||
| return new Color[] | ||
| { | ||
| targetComponent.startColor, | ||
| targetComponent.endColor | ||
| }; | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a LineRenderer's color. | ||
| /// Supports binding separate start and end colors. | ||
| /// Requires a LineRenderer component to be present | ||
| /// </summary> | ||
| [RequireComponent(typeof(LineRenderer))] | ||
| [AddComponentMenu("Theme/LineRenderer Color Binder (Required)")] | ||
| public class LineRendererColorBinderRequired : LineRendererColorBinder | ||
| { | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Unity.Theme.Binders | ||
| { | ||
| /// <summary> | ||
| /// Binds theme colors to a MeshRenderer's material color | ||
| /// Supports binding the main material color property or a custom shader property | ||
| /// </summary> | ||
| [AddComponentMenu("Theme/MeshRenderer Color Binder")] | ||
| public class MeshRendererColorBinder : GenericRendererColorBinder<MeshRenderer> | ||
| { | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.