基础类型 / LinearColor
LinearColor Class
r, g, b 颜色值的有效范围是 0.0 <= value <= 1.0
Table of contents
Accessors
a(): number |
|---|
| 获取当前 LinearColor 的 a 值 |
b(): num[b](mw.LinearColor.md#b)er |
| 获取当前 LinearColor 的 b 值 |
g(): number |
| 获取当前 LinearColor 的 g 值 |
r(): numbe[r](mw.LinearColor.md#r) |
| 获取当前 LinearColor 的 r 值 |
black(): LinearColor |
| 黑色 (0, 0, 0, 1) |
blue(): LinearColor |
| 蓝色 (0, 0, 1, 1) |
gray(): LinearColor |
| 灰色 (0.5, 0.5, 0.5, 1) |
green(): LinearColor |
| 绿色 (0, 1, 0, 1) |
red(): LinearColor |
| 红色 (1, 0, 0, 1) |
white(): LinearColor |
| 白色 (1, 1, 1, 1) |
yellow(): LinearColor |
| 黄色 (1, 1, 0, 1) |
Methods
addition(linearColorB: LinearColor, outer?: LinearColor): LinearColor |
|---|
| 颜色值相加 |
clone(): LinearColor |
| 克隆当前线性颜色 |
division(linearColorB: LinearColor, outer?: LinearColor): LinearColor |
| 颜色值相除 |
equality(linearColorB: LinearColor, epsilon?: number): boolean |
| 判断两个颜色值是否相等 |
fromString(jsonStr: string): LinearColor |
| 用数据生成一个新的对象 |
inequality(linearColorB: LinearColor, epsilon?: number): boolean |
| 颜色值相乘 |
| multiply |
| :----- |
subtraction(linearColorB: LinearColor, outer?: LinearColor): LinearColor |
| 颜色值相减 |
toString(): string |
| 以字符串的形式输出对象属性 |
colorHexToLinearColor(inColorHex: string, outer?: LinearColor): LinearColor |
| 将 HexColor 转化为 LinearColor |
colorHsvToLinearColor(h: number, s: number, v: number, outer?: LinearColor): LinearColor |
| 将 HsvColor 转化为 LinearColor |
colorToLinearColor(r: number, g: number, b: number, a?: number, outer?: LinearColor): LinearColor |
| 转换当前颜色 |
fromString(jsonStr: string): LinearColor |
| 用数据生成一个新的对象 |
makeFromHSV(h: number, s: number, v: number, outer?: LinearColor): LinearColor |
| 将字节色调饱和度亮度转换为 LinearColor |
random(outer?: LinearColor): LinearColor |
| 返回具有随机 RGB 值和 Alpha 为 1.0 的新颜色 |
用给定的 r, g, b 值构建一个新的 Color
Parameters
r number | r range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
|---|---|
g number | g range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
b number | b range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
• new LinearColor(r, g, b, a)
用给定的 r, g, b, a 值构建一个新的 Color
Parameters
r number | r range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
|---|---|
g number | g range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
b number | b range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
a number | a range:颜色值的有效范围是 0.0 <= value <= 1.0 type: 浮点数 |
• new LinearColor(v)
用给定的 Vector 对象构建一个新的 LinearColor
Parameters
v Vector | Vector 对象 |
|---|
• new LinearColor(c)
用给定的 LinearColor 构建一个新的 LinearColor
Parameters
c LinearColor | Vector 对象 |
|---|
Accessors
a
• | • | ||||
|---|---|---|---|---|---|
获取当前 LinearColor 的 a 值 Returns
| 设置当前 LinearColor 的 a 值 Parameters
|
b
• | • | ||||
|---|---|---|---|---|---|
获取当前 LinearColor 的 b 值 Returns
| 设置当前 LinearColor 的 b 值 Parameters
|
g
• | • | ||||
|---|---|---|---|---|---|
获取当前 LinearColor 的 g 值 Returns
| 设置当前 LinearColor 的 g 值 颜色值的有效范围是 Parameters
|
r
• | • | ||||
|---|---|---|---|---|---|
获取当前 LinearColor 的 r 值 Returns
| 设置当前 LinearColor 的 r 值 Parameters
|
black
• | ||
|---|---|---|
黑色 (0, 0, 0, 1) Returns
|
blue
• | ||
|---|---|---|
蓝色 (0, 0, 1, 1) Returns
|
gray
• | ||
|---|---|---|
灰色 (0.5, 0.5, 0.5, 1) Returns
|
green
• | ||
|---|---|---|
绿色 (0, 1, 0, 1) Returns
|
red
• | ||
|---|---|---|
红色 (1, 0, 0, 1) Returns
|
white
• | ||
|---|---|---|
白色 (1, 1, 1, 1) Returns
|
yellow
• |
|---|
黄色 (1, 1, 0, 1) Returns |
LinearColor |
|---|
Methods
addition
• addition(linearColorB, outer?): LinearColor
颜色值相加
Parameters
linearColorB LinearColor | 相加的颜色B |
|---|---|
outer? LinearColor | 接收结果的 LinearColor 对象 default:null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|
clone
• clone(): LinearColor
克隆当前线性颜色
Returns
LinearColor | 返回一个新的线性颜色 |
|---|
division
• division(linearColorB, outer?): LinearColor
颜色值相除
Parameters
linearColorB LinearColor | 相除的颜色B |
|---|---|
outer? LinearColor | 接收结果的 LinearColor 对象 default:null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|
equality
• equality(linearColorB, epsilon?): boolean
判断两个颜色值是否相等
Parameters
linearColorB LinearColor | 对比的颜色B |
|---|---|
epsilon? number | 最小误差数 default: mw.MathUtil.EPSILON range: 建议为小于 1 的值。 type: 浮点数 |
Returns
boolean | 是否相等。相等返回true,不相等返回false |
|---|
fromString
• fromString(str): void
用数据填充对象。
Parameters
jsonStr string | 数据字符串 range:"R=0.000000,G=1.000000,B=0.000000,A=-1.000000" |
|---|
Returns
LinearColor | 新的 LinearColor 类型对象。 |
|---|
与另一个 fromString 函数的区别为:此函数为普通函数,另一个为静态函数。
调用方式不相同。
使用示例: 调用方式的区别ts
// 此函数
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;
// 静态 fromString 函数
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);// 此函数
let color :LinearColor;
color.fromString("R=0.000000,G=1.000000,B=0.000000,A=-1.000000");
this.button.pressedImagColor = color;
// 静态 fromString 函数
const str = "R=0.000000,G=1.000000,B=0.000000,A=-1.000000";
this.button.pressedImagColor = LinearColor.fromString(str);Parameters
str string | 数据字符串 range: "R=0.000000,G=1.000000,B=0.000000,A=-1.000000" |
|---|
inequality
• inequality(linearColorB, epsilon?): boolean
Returns
boolean | 是否相等。不相等返回 true,相等返回 false |
|---|
颜色值相乘
Parameters
linearColorB LinearColor | 相乘的颜色B |
|---|---|
outer? LinearColor | 接收结果的 LinearColor 对象 default:null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|
Parameters
linearColorB LinearColor | 对比的颜色B |
|---|---|
epsilon? number | 最小误差数 default: mw.MathUtil.EPSILON range: 建议为小于 1 的值。 type: 浮点数 |
Returns
boolean | 是否相等。不相等返回 true,相等返回 false |
|---|
subtraction
• subtraction(linearColorB, outer?): LinearColor
颜色值相减
Parameters
linearColorB LinearColor | 相减的颜色B |
|---|---|
outer? LinearColor | 接收结果的 LinearColor 对象 default:null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|
toString
• toString(): string
以字符串的形式输出对象属性
Returns
string | 对象属性字符串 |
|---|
colorHexToLinearColor
• Static colorHexToLinearColor(inColorHex, outer?): LinearColor
将 HexColor 转化为 LinearColor
Parameters
inColorHex string | HexColor 字符串 range: HexColor 字符串长度 |
|---|---|
outer? LinearColor | 接收转化后的 LinearColor 的对象 default:null |
Returns
LinearColor | LinerColor 对象 |
|---|
colorHsvToLinearColor
• Static colorHsvToLinearColor(h, s, v, outer?): LinearColor
将 HsvColor 转化为 LinearColor
Parameters
h number | 色调。 range:[0, 1] type:浮点数 |
|---|---|
s number | 饱和度。 range:[0, 1] type:浮点数 |
v number | 亮度。 range:[0, 1] 0.0(黑色)~1.0(白色) type:浮点数 |
outer? LinearColor | 接收转换结果的 LinearColor 对象 default: null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer,否则返回一个新的 LinearColor 对象 |
|---|
colorToLinearColor
• Static colorToLinearColor(r, g, b, a?, outer?): LinearColor
转换当前颜色
Parameters
r number | 颜色 R 值。default:null range:[0, 255] type:整数 |
|---|---|
g number | 颜色 G 值。default:null range:[0, 255] type:整数 |
b number | 颜色 B 值。 default:null range:[0, 255] type:整数 |
a? number | 颜色 透明度。default:255 range:[0, 255] type:整数 |
outer? LinearColor | 接收转换结果的 LinearColor 对象 default: null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象。 |
|---|
fromString
• Static fromString(jsonStr): LinearColor
用数据生成一个新的对象
传入格式为:"R=0.000000,G=1.000000,B=0.000000,A=-1.000000"(绿色)
使用示例: 创建一个名为 NewScript 的脚本,放置在对象栏中,打开脚本,将原本内容修改为如下内容,保存并运行游戏,会在场景中生成一个屏幕 UI - 按钮。ts
@Component
export default class NewScript extends Script {
protected onStart(): void {
if(SystemUtil.isClient()){
UIService.show(NewUIScript);
}
}
}
class NewUIScript extends UIScript {
button:StaleButton;
protected onStart() {
//设置能否每帧触发onUpdate
this.canUpdate = false;
this.layer = UILayerMiddle;
this.button = StaleButton.newObject(this.rootCanvas);
this.button.text = "按下变绿";
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() {
//设置能否每帧触发onUpdate
this.canUpdate = false;
this.layer = UILayerMiddle;
this.button = StaleButton.newObject(this.rootCanvas);
this.button.text = "按下变绿";
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 | 数据字符串 range:"R=0.000000,G=1.000000,B=0.000000,A=-1.000000" |
|---|
Returns
LinearColor | 新的 LinearColor 类型对象。 |
|---|
makeFromHSV
• Static makeFromHSV(h, s, v, outer?): LinearColor
将字节色调饱和度亮度转换为 LinearColor
Parameters
h number | 色调。 range:[0, 1] type:浮点数 |
|---|---|
s number | 饱和度。 range:[0, 1] type:浮点数 |
v number | 亮度。 range:[0, 1] 0.0(黑色)~1.0(白色) type:浮点数 |
outer? LinearColor | 接收转换结果的 LinearColor 对象 default:null |
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|
random
• Static random(outer?): LinearColor
返回具有随机 RGB 值和 Alpha 为 1.0 的新颜色
Parameters
outer? LinearColor | 接收结果的 LinearColor 对象 default:null |
|---|
Returns
LinearColor | 如果 outer 不为空, 返回 outer, 否则返回一个新的 LinearColor 对象 |
|---|