簡體   English   中英

定義組件時組合架構屬性類型

[英]Combine schema property types when defining a component

我正在編寫一個可以接受vec3和數組作為架構屬性的組件:

AFRAME.registerComponent('control-arrows', {
    schema: {
        'directions': {
            'type': 'array',
            'default': [
                {'x':  1, 'y': 0, 'z':  0},
                {'x': -1, 'y': 0, 'z':  0},
                {'x':  0, 'y': 0, 'z':  1},
                {'x':  0, 'y': 0, 'z': -1}
            ]
        }
    },
    /* init and stuff */
}

如示例所示,我使用了array類型。 但是,此類型的限制不夠,因為它應該是vec3array 請注意, vec3的數量可以變化,因此我不能在vec3類型中使用4個屬性。

如何執行這樣的限制? 更具體地說,如何正確解析HTML部分,可能是:

<a-entity
    control-arrows: "positions: 1 0 1, -1 0 -1">
</a-entity>

您可以創建自定義屬性類型: https : //aframe.io/docs/0.5.0/core/component.html#custom-property-type

schema: {
    'directions': {
        'parse': function (val) {
           return val.split(',').map(AFRAME.utils.coordinates.parse);
        },
        'default': [
            {'x':  1, 'y': 0, 'z':  0},
            {'x': -1, 'y': 0, 'z':  0},
            {'x':  0, 'y': 0, 'z':  1},
            {'x':  0, 'y': 0, 'z': -1}
        ]
    }
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM