oliverbooth / X10D

Extension methods on crack.
https://oliverbooth.github.io/X10D/
MIT License
28 stars 2 forks source link

Color.With* #55

Closed oliverbooth closed 2 years ago

oliverbooth commented 2 years ago

Types

System.Drawing.Color
UnityEngine.Color
UnityEngine.Color32

Extension method signatures

Color WithR(byte/int/float);
Color WithG(byte/int/float);
Color WithB(byte/int/float);
Color WithA(byte/int/float);

Color32 WithR(byte/int/float);
Color32 WithG(byte/int/float);
Color32 WithB(byte/int/float);
Color32 WithA(byte/int/float);
Parameters Parameter Type Description
r / g / b / a byte / int / float The new component value.

Description Returns a color whose components are the same as a given color, but with one component specified as a new value.

Benefits Provides an easy way to transform a Color without constructing a new one with .NET's FromArgb.

Drawbacks In Unity, this is already easily achievable using a with expression, since Unity's Color/Color32 structs are mutable.

(Optional) Implementation example n/a