扩展Inspector的时候想定义一个a:[{x,y,z}]这样的数组,然后在Vue中用target.a.value.0.x这种方式来访问数据并展现,但是下面这样的定义无法做到,试来试去Vue中的target.a都是cc-null-prop或者type-error:
properties: {
a: []
},
onLoad() {
this.a.push({x:1,y:1,z:1});
}
后来尝试自己写了一个类去继承cc.ValueType,但是必须写成这样才能在Vue中访问,否则就会各种报错:
export function A(x, y, z) {
this.x = {value: x, type: cc.Integer}; // 而不是this.x = x;
this.y = {value: y, type: cc.Integer};
this.z = {value: z, type: cc.Integer};
}
cc.js.extend(A, cc.ValueType);
fastDefine('cc.A', A, {x: 1, y: 1, z: 1});
A.prototype.clone = function () {
return new A(this.x, this.y, this.z);
};
-------------------------------------------------------------------------------
properties: {
a: [],
type: A
},
onLoad() {
this.a.push(new A(1,1,1));
}
虽然现在这样Hack可以在Vue中拿到数据了,但是我想问,怎样才是正确的做法?为什么cc.Size等自带的ValueType子类的构造函数里赋值不用写成{value: …}的形式?谢谢!
@karasaya