12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const dataItemInfo = require('../data/item');
- cc.Class({
- extends: cc.Component,
- properties: {
- packItemPrefab: cc.Prefab,
- pageLayout: cc.Layout,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- },
- init(array,page) {
- for (var i = 0; i < 20; i++) {
- let item = cc.instantiate(this.packItemPrefab);
- item = item.getComponent('UserPackItem');
- if (i < array.length) {
- let itemInfo = array[i];
- let count = itemInfo.count;
- dataItemInfo.forEach(info => {
- if (info.id == itemInfo.itemId) {
- itemInfo = info;
- }
- });
- itemInfo.count = count;
- item.init(i,page,itemInfo);
- } else {
- item.init(i,page);
- }
- this.pageLayout.node.addChild(item.node);
- }
- },
- onDisable () {
- for (let child of this.pageLayout.node.children) {
- if (cc.isValid(child)) {
- child.destroy();
- }
- }
- },
- start () {
- },
- // update (dt) {},
- });
|