cc.Class({ extends: cc.Component, properties: { m_WeaveParent:[cc.Node], m_WeavePrefab:cc.Prefab, m_WeaveItem:cc.Prefab, }, ctor:function(){ this.m_WeaveArray = new Array(); this.m_wCardCount = 0; }, Init: function(state) { var buildCardCount = 0; // 初始化计数器 for (var i = 0; i < 5; i++) { // 如果当前位置的WeaveArray为空,则实例化一个新的WeavePrefab对象 if (this.m_WeaveArray[i] == null) { var Weave = cc.instantiate(this.m_WeavePrefab); // 实例化预制体 Weave.active = false; // 初始化时设置为不活跃状态 this.m_WeaveArray[i] = Weave.getComponent('WeaveItem'); // 获取WeaveItem组件并存入数组 this.m_WeaveParent[i].addChild(Weave); // 将新实例添加到对应位置的父节点 // 调用WeaveItem组件的BuildCard方法,构建牌 this.m_WeaveArray[i].BuildCard(state, this.m_WeaveItem); buildCardCount++; // 计数器加1 } } }, SetWeaveData:function(index,cbCardData,wCardCount){ this.m_WeaveArray[index].node.active = true; this.m_WeaveArray[index].SetWeaveData(cbCardData,wCardCount); }, SetWeaveState:function(index,State, bEnd){ this.m_WeaveArray[index].SetWeaveState(State, bEnd); }, ResetData:function(){ for (var i = 0; i < this.m_WeaveArray.length; i++) { this.m_WeaveArray[i].node.active = false; } }, // update (dt) {}, });