Skip to content

C.Color

yenmoc edited this page Jun 21, 2023 · 1 revision

What

Support method for color

ChangeAlpha

Color ChangeAlpha(this Color, float)

Makes a copy of the color with a changed alpha value.

Example

private SpriteRenderer _renderer;

_renderer.color = _renderer.color.ChangeAlpha(0);

SetAlpha

void SetAlpha(this SpriteRenderer, float)
void SetAlpha(this Graphic, float)

Change alpha value of color sprite renderer, graphic

Example

private SpriteRenderer _renderer;

spriteRenderer.SetAlpha(value)

SetRed

void SetRed(this SpriteRenderer, float)
void SetRed(this Graphic, float)

Change red value of color sprite renderer, graphic

Example

private SpriteRenderer _renderer;

spriteRenderer.SetRed(value)

SetGreen

void SetGreen(this SpriteRenderer, float)
void SetGreen(this Graphic, float)

Change green value of color sprite renderer, graphic

Example

private SpriteRenderer _renderer;

spriteRenderer.SetGreen(value)

SetBlue

void SetBlue(this SpriteRenderer, float)
void SetBlue(this Graphic, float)

Change blue value of color sprite renderer, graphic

Example

private SpriteRenderer _renderer;

spriteRenderer.SetBlue(value)

SetRGB

void SetRGB(this SpriteRenderer spriteRenderer, float r, float g, float b)
void SetRGB(this Graphic graphic, float r, float g, float b)

Change red, green ,blue value of color sprite renderer, graphic

Example

private SpriteRenderer _renderer;

spriteRenderer.SetRGB(value)

ToHtmlStringRGBA

string ToHtmlStringRGBA(this Color)

Returns the color as a hexadecimal string in the format "#RRGGBBAA".

Example

private SpriteRenderer _renderer;

var htmlColor = spriteRenderer.color.ToHtmlStringRGBA();

TryParseHtmlString

bool TryParseHtmlString(this string, out Color)

Returns the color parse from a hexadecimal string in the format "#RRGGBBAA".

Example

var htmlColor = "#FFFFFFF";
htmlColor.TryParseHtmlString(out var color);

TextColor

string TextColor(this string text, string color)
string TextColor(this string text, Color color)

Returns the string content with color mark style html

Example

var str = "this is demo string";
var result = str.TextColor(Color.Red);
Clone this wiki locally