private void HandleCellClickEvent(UGUICell cell) { if (onCellClick != null) { onCellClick(cell); } }
void HandleSetCellEvent(UGUICell cell) { Debug.Log("HandleSetCellEvent :" + cell.mIndex); }
public void SetCount(int count) { mCnt = count; // 首先清理数据; for (int i = 0; i < mGridLayoutGroup.transform.childCount; i++) { GameObject obj = mGridLayoutGroup.transform.GetChild(i).gameObject; if (obj != null) { obj.GetComponent <UGUICell>().onCellClick -= HandleCellClickEvent; GameObject.Destroy(obj); } } // 清理缓存; mCellList.Clear(); // 填充数据; for (int i = 0; i < mCnt; i++) { UGUICell baseCell = null; GameObject baseCellObj = GameObject.Instantiate(mCellPrefab) as GameObject; if (baseCellObj != null) { baseCellObj.transform.parent = mGridLayoutGroup.transform; baseCellObj.transform.localPosition = Vector3.zero; baseCellObj.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); baseCell = baseCellObj.GetComponent <UGUICell>(); if (baseCell != null) { baseCell.onCellClick -= HandleCellClickEvent; baseCell.onCellClick += HandleCellClickEvent; baseCell.mIndex = i; mCellList.Add(baseCell); } } if (onSetCell != null) { onSetCell(baseCell); } } if (onSetCellFinish != null) { onSetCellFinish(); } // 设置List可拖动范围; RectTransform rectTransform = mGridLayoutGroup.GetComponent <RectTransform>(); int iRow = mCnt; if (mCol > 1) { iRow = mCnt / mCol; int iTemp = mCnt % mCol; if (iTemp > 0) { iRow = iRow + 1; } } rectTransform.sizeDelta = new Vector2(0, iRow * mCell_H); }