-
Creator 版本:3.11
-
目标平台: Chrome浏览器
-
之前哪个版本是正常的:2.4.3
我做了一个《健康游戏忠告》的Prefab 设置了两个property:row和size
之前用2.4.3版本的的时候可以在编辑器中调整row和size的值来动态改变样式,现在换到3.11的版本发现调整值之后仅在编辑器中有效,保存之后在浏览器中运行还是原来的样式 查看scene文件发现对应的key:value还是初始化的值,也就是说只在编辑器中发生了变化,实际并没有保存。
Prefab绑定的ts文件代码:
import {_decorator, Enum, Component, CCInteger, Label} from ‘cc’;
const {ccclass, property, executeInEditMode} = _decorator;
let tipsRow = Enum({
两行: 2,
四行: 4
})
@ccclass('GameTips')
@executeInEditMode(true)
export default class GameTips extends Component {
private _row: number = tipsRow.两行;
private _size: number = 30;
@property({
type: Enum(tipsRow),
displayName: '行'
})
public set row(value) {
this.updateLineNum(value);
this._row = value
}
public get row() {
return this._row
}
@property({
type: CCInteger,
displayName: '缩放',
slide: true, min: 10, max: 100
})
public set size(value) {
this._size = value
this.updateFontSize(value);
}
public get size() {
return this._size
}
updateLineNum(num: number) {
let tipsInstance: Label | null = this.node.getComponent(Label);
if (num == 2) {
!!tipsInstance && (tipsInstance.string = '抵制不良游戏,拒绝盗版游戏。注意自我保护,谨防受骗上当。\n' +
'适度游戏益脑,沉迷游戏伤身。合理安排时间,享受健康生活。')
} else {
!!tipsInstance && (tipsInstance.string = '抵制不良游戏,拒绝盗版游戏。\n' +
'注意自我保护,谨防受骗上当。\n' +
'适度游戏益脑,沉迷游戏伤身。\n' +
'合理安排时间,享受健康生活。')
}
}
updateFontSize(size: number) {
let tipsInstance: Label | null = this.node.getComponent(Label);
!!tipsInstance && (tipsInstance.fontSize = size);
!!tipsInstance && (tipsInstance.lineHeight = size + 10);
}
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
}
// update (dt) {}
}
