[Basic Type](../groups/Basic Type.Basic Type.md) / LinearColor
LinearColor Class
r, g, b The effective range of color values is 0.0<=value<=1.0
Table of contents
Accessors
a(): number |
|---|
| Get the a value of the current LinearColor |
b(): num[b](mw.LinearColor.md#b)er |
| Get the b-value of the current LinearColor |
g(): number |
| Get the g value of the current LinearColor |
r(): numbe[r](mw.LinearColor.md#r) |
| Get the r value of the current LinearColor |
black(): LinearColor |
| Black (0,0,0,1) |
blue(): LinearColor |
| Blue (0,0,1,1) |
gray(): LinearColor |
| Grey (0.5, 0.5, 0.5, 1) |
green(): LinearColor |
| Green (0,1,0,1) |
red(): LinearColor |
| Red (1,0,0,1) |
white(): LinearColor |
| White (1, 1, 1, 1) |
yellow(): LinearColor |
| Yellow (1, 1, 0, 1) |
Methods
addition(linearColorB: LinearColor, outer?: LinearColor): LinearColor other |
|---|
| Addition of color values |
clone(): LinearColor other |
| Clone the current linear color |
division(linearColorB: LinearColor, outer?: LinearColor): LinearColor other |
| Color value division |
equality(linearColorB: LinearColor, epsilon?: number): boolean other |
| Determine if two color values are equal |
fromString(jsonStr: string): LinearColor other |
| Generate a new object with data |
inequality(linearColorB: LinearColor, epsilon?: number): boolean other |
| Multiplying color values |
| multiply |
| :----- |
subtraction(linearColorB: LinearColor, outer?: LinearColor): LinearColor other |
| Subtract color values |
toString(): string other |
| Output object properties in string form |
colorHexToLinearColor(inColorHex: string, outer?: LinearColor): LinearColor other |
| Convert HexColor to LinearColor |
colorHsvToLinearColor(h: number, s: number, v: number, outer?: LinearColor): LinearColor other |
| Convert HsvColor to LinearColor |
colorToLinearColor(r: number, g: number, b: number, a?: number, outer?: LinearColor): LinearColor other |
| Convert current color |
fromString(jsonStr: string): LinearColor other |
| Generate a new object with data |
makeFromHSV(h: number, s: number, v: number, outer?: LinearColor): LinearColor other |
| Convert byte tone saturation brightness to LinearColor |
random(outer?: LinearColor): LinearColor other |
| Return a new color with random RGB values and an Alpha of 1.0 |
Construct a new Color using the given values of r, g, and b
Parameters
r number | r Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
|---|---|
g number | g Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
b number | b Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
• new LinearColor(r, g, b, a)
Construct a new Color using the given values of r, g, b, and a
Parameters
r number | r Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
|---|---|
g number | g Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
b number | b Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
a number | a Range: The valid range for color values is 0.0<=value<=1.0 type: floating-point number |
• new LinearColor(v)
Build a new LinearColor using the given Vector object
Parameters
v Vector | Vector object |
|---|
• new LinearColor(c)
Build a new LinearColor using the given LinearColor
Parameters
c LinearColor | Vector object |
|---|
Accessors
a
• | • | ||||
|---|---|---|---|---|---|
Get the a value of the current LinearColor Returns
| Set the value of a for the current LinearColor Parameters
|
b
• | • | ||||
|---|---|---|---|---|---|
Get the b-value of the current LinearColor Returns
| Set the b-value of the current LinearColor Parameters
|
g
• | • | ||||
|---|---|---|---|---|---|
Get the g value of the current LinearColor Returns
| What is the valid range for setting the g-value of the current LinearColor color value Parameters
|
r
• | • | ||||
|---|---|---|---|---|---|
Get the r value of the current LinearColor Returns
| Set the r value of the current LinearColor Parameters
|
black
• | ||
|---|---|---|
Black (0,0,0,1) Returns
|
blue
• | ||
|---|---|---|
Blue (0,0,1,1) Returns
|
gray
• | ||
|---|---|---|
Grey (0.5, 0.5, 0.5, 1) Returns
|
green
• | ||
|---|---|---|
Green (0,1,0,1) Returns
|
red
• | ||
|---|---|---|
Red (1,0,0,1) Returns
|
white
• | ||
|---|---|---|
White (1, 1, 1, 1) Returns
|
yellow
• |
|---|
Yellow (1, 1, 0, 1) Returns |
LinearColor |
|---|
Methods
addition
• addition(linearColorB, outer?): LinearColor other
Addition of color values
Parameters
linearColorB LinearColor | Usage: Color B added together |
|---|---|
outer? LinearColor | Usage: LinearColor object receiving result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
clone
• clone(): LinearColor other
Clone the current linear color
Returns
LinearColor | Return a new linear color |
|---|
division
• division(linearColorB, outer?): LinearColor other
Color value division
Parameters
linearColorB LinearColor | Usage: Dividing Color B |
|---|---|
outer? LinearColor | Usage: LinearColor object receiving result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
equality
• equality(linearColorB, epsilon?): boolean other
Determine if two color values are equal
Parameters
linearColorB LinearColor | Usage: Color B for comparison |
|---|---|
epsilon? number | Usage: Minimum error count default: mw.MathUtil EPSILON range: It is recommended to have a value less than 1< Br>Type: Floating point number |
Returns
boolean | Is it equal. Equal returns true, unequal returns false |
|---|
fromString
• fromString(str): void other
Fill objects with data.
Parameters
jsonStr string | Usage: data string range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000" |
|---|
Returns
LinearColor | New LinearColor type object. |
|---|
The difference between this function and another from String function is that this function is a regular function, while the other is a static function.
The calling methods are different.
Usage example: difference of call mode
// This function
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;
// Static fromString function
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);// This function
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;
// Static fromString function
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);Parameters
str string | Usage: data string range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000" |
|---|
inequality
• inequality(linearColorB, epsilon?): boolean other
Returns
boolean | Is it equal. Unequal returns true, equal returns false |
|---|
Multiplying color values
Parameters
linearColorB LinearColor | Usage: Multiplying Color B |
|---|---|
outer? LinearColor | Usage: LinearColor object receiving result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
Parameters
linearColorB LinearColor | Usage: Color B for comparison |
|---|---|
epsilon? number | Usage: Minimum error count default: mw.MathUtil EPSILON range: It is recommended to have a value less than 1< Br>Type: Floating point number |
Returns
boolean | Is it equal. Unequal returns true, equal returns false |
|---|
subtraction
• subtraction(linearColorB, outer?): LinearColor other
Subtract color values
Parameters
linearColorB LinearColor | Usage: Subtracting color B |
|---|---|
outer? LinearColor | Usage: LinearColor object receiving result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
toString
• toString(): string other
Output object properties in string form
Returns
string | Object attribute string |
|---|
colorHexToLinearColor
• Static colorHexToLinearColor(inColorHex, outer?): LinearColor other
Convert HexColor to LinearColor
Parameters
inColorHex string | HexColor String range: HexColor string length |
|---|---|
outer? LinearColor | Usage: Receive converted LinearColor object default: null |
Returns
LinearColor | LinerColor object |
|---|
colorHsvToLinearColor
• Static colorHsvToLinearColor(h, s, v, outer?): LinearColor other
Convert HsvColor to LinearColor
Parameters
h number | Usage: Color tone< Range: [0,1] type: floating point number |
|---|---|
s number | Usage: saturation< Range: [0,1] type: floating point number |
v number | Usage: Brightness< Range: [0,1] 0.0 (black) to 1.0 (white) Type: Floating point number |
outer? LinearColor | Usage: LinearColor object receiving conversion result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
colorToLinearColor
• Static colorToLinearColor(r, g, b, a?, outer?): LinearColor other
Convert current color
Parameters
r number | Usage: Color R value. Default: null range: [0, 255] type: integer |
|---|---|
g number | Usage: Color G value. Default: null range: [0, 255] type: integer |
b number | Usage: Color B value. Default: null range: [0, 255] type: integer |
a? number | Usage: Color transparency. Default: 255 range: [0, 255] type: integer |
outer? LinearColor | Usage: LinearColor object receiving conversion result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object. |
|---|
fromString
• Static fromString(jsonStr): LinearColor other
Generate a new object with data
The incoming format is: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000" (green)
Example usage: Create a script called NewScript, place it in the object bar, open the script, modify the original content to the following, save and run the game, and a screen UI button will be generated in the scene.
@Component
export default class NewScript extends Script {
protected onStart(): void {
if(SystemUtil.isClient()){
UIService.show(NewUIScript);
}
}
}
class NewUIScript extends UIScript {
button:StaleButton;
protected onStart() {
//Set whether onUpdate can be triggered every frame
this.canUpdate = false;
this.layer = UILayerMiddle;
this.button = StaleButton.newObject(this.rootCanvas);
this.button.text = "Press to turn green";
this.button.transitionEnable = true;
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);
this.button.visibility = SlateVisibility.Visible;
this.button.onClicked.add(() => {
console.log("click");
})
}
}@Component
export default class NewScript extends Script {
protected onStart(): void {
if(SystemUtil.isClient()){
UIService.show(NewUIScript);
}
}
}
class NewUIScript extends UIScript {
button:StaleButton;
protected onStart() {
//Set whether onUpdate can be triggered every frame
this.canUpdate = false;
this.layer = UILayerMiddle;
this.button = StaleButton.newObject(this.rootCanvas);
this.button.text = "Press to turn green";
this.button.transitionEnable = true;
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);
this.button.visibility = SlateVisibility.Visible;
this.button.onClicked.add(() => {
console.log("click");
})
}
}Parameters
jsonStr string | Usage: data string range: "R=0.000000, G=1.000000, B=0.000000, A=-1.000000" |
|---|
Returns
LinearColor | New LinearColor type object. |
|---|
makeFromHSV
• Static makeFromHSV(h, s, v, outer?): LinearColor other
Convert byte tone saturation brightness to LinearColor
Parameters
h number | Usage: Color tone< Range: [0,1] type: floating point number |
|---|---|
s number | Usage: saturation< Range: [0,1] type: floating point number |
v number | Usage: Brightness< Range: [0,1] 0.0 (black) to 1.0 (white) Type: Floating point number |
outer? LinearColor | Usage: LinearColor object receiving conversion result default: null |
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
random
• Static random(outer?): LinearColor other
Return a new color with random RGB values and an Alpha of 1.0
Parameters
outer? LinearColor | Usage: LinearColor object receiving result default: null |
|---|
Returns
LinearColor | If outer is not empty, return outer; otherwise, return a new LinearColor object |
|---|
Editor API