求解:当我get/set一个array类型的时候一直有警告,不知道该 如何去掉?

如题:ccc1.6.1b2 使用typescript开发,代码如下:
@property({default:[],type:[cc.Float]})
_items=[];
@property({type:[cc.Float]})
get items (){
return this._items;
}
@property({type:[cc.Float]})
set items (value) {
this._items = value;
}
倒是能使用,没发现有什么问题,就是编辑器总是警告:The ‘default’ attribute of ‘TweenAnimation.items’ must be an array,不知道这个警告该如何去掉,尝试了半天没找到办法。

抱歉这个应该是警告的 bug
不过可以肯定的是,数组不能也不应该实现为 get set

其实我的需求是这样的,

@ccclass("Item")
export class Item
{
    @property({visible:false})
    type=false;
    @property(visible(){return this.type})
    a;
    @property
    b;
    @property(visible(){return this.type})
    c;
}
@ccclass
class Animation extends cc.Component {
    @property({default:[],type:[Item]})
    _items=[];
    @property({type:[Item]"})
    get items (){
        return this._items;
    }
    @property({type:[Item]})
    set items (value) {
        this._items = value;
        for(let i:number=0;i<value.length;i++)
        {
            value[i].type=this.setVisible;
        }
    }
}

在Animation 中有属性是item数组,但是item中的部分属性显示需要根据Animatin中的状态来设置,所以我想到的办法是通过set 方法中遍历数组的方式,如果数组不能使用get/set 这种需求改如果解决呢?其实就是如何从Animation传递参数给Item呢?

试一下:type用Item而不是[Item],然后装饰器写一遍在get items上就行了。

:innocent:不好意思,没太明白~

property(visible(){return this.type})
不支持这种用法,应该是property({ visible(){return this.type} })
如果要和 Animation 联动,考虑用

property({ 
  visible () {
    return this.animation.setVisible;
  }
})

再不行就只能做一个 inspector 插件了

@ccclass
class Animation extends cc.Component {
    @property({default:[],type:Item})
    _items=[];
    @property({type:Item})
    get items (){
        return this._items;
    }
    set items (value) {
        this._items = value;
        for(let i:number=0;i<value.length;i++)
        {
            value[i].type=this.setVisible;
        }
    }
}

多谢各位了~~