Struct ColorBlock
Structure that stores the state of a color transition on a Selectable.
Implements
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[Serializable]
public struct ColorBlock : IEquatable<ColorBlock>
Fields
defaultColorBlock
Simple getter for a code generated default ColorBlock.
Declaration
public static readonly ColorBlock defaultColorBlock
Field Value
| Type | Description |
|---|---|
| ColorBlock |
Properties
colorMultiplier
Multiplier applied to colors (allows brightening greater then base color).
Declaration
public float colorMultiplier { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
disabledColor
The disabled color for this color block.
Declaration
public Color disabledColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
public Color newColor;
void Start()
{
//Changes the button's Disabled color to the new color.
ColorBlock cb = button.colors;
cb.disabledColor = newColor;
button.colors = cb;
}
}
fadeDuration
How long a color transition between states should take.
Declaration
public float fadeDuration { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
highlightedColor
The highlight color for this color block.
Declaration
public Color highlightedColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
public Color newColor;
void Start()
{
//Changes the button's Highlighted color to the new color.
ColorBlock cb = button.colors;
cb.highlightedColor = newColor;
button.colors = cb;
}
}
normalColor
The normal color for this color block.
Declaration
public Color normalColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
public Color newColor;
void Start()
{
//Changes the button's Normal color to the new color.
ColorBlock cb = button.colors;
cb.normalColor = newColor;
button.colors = cb;
}
}
pressedColor
The pressed color for this color block.
Declaration
public Color pressedColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
public Color newColor;
void Start()
{
//Changes the button's Pressed color to the new color.
ColorBlock cb = button.colors;
cb.pressedColor = newColor;
button.colors = cb;
}
}
selectedColor
The selected color for this color block.
Declaration
public Color selectedColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
public Color newColor;
void Start()
{
//Changes the button's Selected color to the new color.
ColorBlock cb = button.colors;
cb.selectedColor = newColor;
button.colors = cb;
}
}
Methods
Equals(object)
Returns true if the given object is a ColorBlock with identical values to this one.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if equal. |
Overrides
Equals(ColorBlock)
Returns true if the given ColorBlock has identical values to this one.
Declaration
public bool Equals(ColorBlock other)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorBlock | other | The ColorBlock to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if all fields are equal. |
GetHashCode()
Returns a hash code for this ColorBlock.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | An integer hash code. |
Overrides
Operators
operator ==(ColorBlock, ColorBlock)
Returns true if two ColorBlock instances have identical values.
Declaration
public static bool operator ==(ColorBlock point1, ColorBlock point2)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorBlock | point1 | First ColorBlock. |
| ColorBlock | point2 | Second ColorBlock. |
Returns
| Type | Description |
|---|---|
| bool | True if equal. |
operator !=(ColorBlock, ColorBlock)
Returns true if two ColorBlock instances differ in any value.
Declaration
public static bool operator !=(ColorBlock point1, ColorBlock point2)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorBlock | point1 | First ColorBlock. |
| ColorBlock | point2 | Second ColorBlock. |
Returns
| Type | Description |
|---|---|
| bool | True if not equal. |