public void Init() { m_unuseCell.Clear(); Transform trans = gameObject.transform; int count = 0; for (int i = 0; i < trans.childCount; ++i) { NListCell cell = trans.GetChild(i).GetComponent <NListCell>(); if (cell != null) { m_unuseCell.Add(cell); cell.gameObject.SetActive(false); //init dynamic object m_dynamicObject = cell.gameObject; count++; } } //NListCell数量不足时自动补充 int needCount = VisibleCellCount() + 4 - count; if (needCount > 0) { StartCoroutine(CoroutineDynamicObject(needCount)); } ScrollResetPosition(); WrapContent(); }
void _ToggleSubView(NListCell cell, bool isShow, bool play = false) { if (cell != null) { if (isShow) { TableChangeVerticalImpl(); //cell.ShowSubView(play); } else { if (cell.Index >= 0 && cell.Index < m_cellHeightMap.Length) { m_cellHeightMap[cell.Index] = 0; } TableChangeVerticalImpl(); //cell.HideSubView(false); //关闭禁用动画 } if (!play) { WrapContentVerticalImpl(); } } }
/// <summary> /// 重置状态 /// </summary> public void ResetState() { if (m_isTween) { foreach (int index in m_useCellMap.Keys) { NListCell cell = m_useCellMap[index]; if (m_isTween && cell != null) { //cell.HideSubView(false); if (index == cell.Index) { DrawCell(cell, cell.Index); } } } } }
void DrawCell(NListCell cell, int index) { int count = 0; // if (m_tableData.ItemsCount > 0) // { // int begin = m_tableData.ItemsCount * index; // int end = m_tableData.ItemsCount * (index + 1); // int dataCount = m_tableData.DataCount(); // count = end > dataCount ? (dataCount - begin) : (end - begin); // } // object data = m_tableData.CellData(index, ref count); if (ItemCount > 0) { int begin = ItemCount * index; int end = ItemCount * (index + 1); count = end > DataCount ? (DataCount - begin) : (end - begin); } //object data = m_tableData.CellData(index, ref count); cell.DrawCell(index, count); }
void ClearUnuseCell() { //NOTE: 这里考虑old data m_useCellMap, var ids = new List <int>(); foreach (int index in m_useCellMap.Keys) { ids.Add(index); } for (int i = 0; i < ids.Count; ++i) { int index = ids[i]; if (index >= m_totalSize) { NListCell cell = m_useCellMap[index]; cell.gameObject.SetActive(false); m_unuseCell.Add(cell); m_useCellMap.Remove(index); } } }
public void DeleteCell(GameObject cellObj) { NListCell cell = cellObj.GetComponent <NListCell>(); if (cell != null) { if (cell.Index >= 0 && cell.Index < m_totalSize) { //cell.HideSubView(false); m_totalSize = m_totalSize - 1; float[] temp = new float[m_totalSize]; for (int i = 0; i <= m_totalSize; i++) { if (i < cell.Index) { temp[i] = m_cellHeightMap[i]; } else if (i > cell.Index) { temp[i - 1] = m_cellHeightMap[i]; } } m_cellHeightMap = temp; TableChangeVerticalImpl(); WrapContentVerticalImpl(true); //考虑count变化的情况 ClearUnuseCell(); //update draw cell if (m_isNeedUpdate) { UpdateDrawCell(); } } } }
public void InitTableView() { Transform trans = gameObject.transform; int count = 0; for (int i = 0; i < trans.childCount; ++i) { NListCell cell = trans.GetChild(i).GetComponent <NListCell>(); if (cell != null) { cell.gameObject.SetActive(true); //init dynamic object m_dynamicObject = cell.gameObject; count++; } } //NListCell数量不足时自动补充 int needCount = VisibleCellCount() + 4 - count; while (needCount > 0) { var go = Instantiate(m_dynamicObject) as GameObject; var goTransform = go.transform; goTransform.parent = m_dynamicObject.transform.parent; go.name = "Cell"; var cloneTransform = m_dynamicObject.transform; goTransform.localScale = cloneTransform.localScale; goTransform.localPosition = cloneTransform.localPosition; goTransform.localRotation = cloneTransform.localRotation; // 动态创建的OBJ需要先隐掉,再通过逻辑判断是否开启,否则会出现重叠问题 go.SetActive(true); needCount--; } }
/// <summary> /// 收缩控件子菜单切换显示 /// </summary> /// <param name="cellObj"></param> /// <param name="isShow"></param> public void ToggleSubView(GameObject cellObj, bool isShow, bool play = false) { NListCell cell = cellObj.GetComponent <NListCell>(); _ToggleSubView(cell, isShow, play); }
/// <summary> /// 垂直的实现 /// </summary> void WrapContentVerticalImpl(bool toggle = false) { Vector3 firstPos = Vector3.zero; m_visibleIndex.Clear(); for (int i = 0; i < m_totalSize; ++i) { Vector3 pos = firstPos + new Vector3(0, -m_height * i, 0); Vector3 pos1 = pos + new Vector3(0, -m_height - m_cellHeightMap[i], 0); Vector3 pos2 = pos + new Vector3(0, m_height, 0); pos1 = m_panel.transform.TransformPoint(pos1); pos2 = m_panel.transform.TransformPoint(pos2); //处理cell很大,view很小的特殊情况 Vector3 center = m_panel.transform.TransformPoint(pos); if (m_panel.IsVisible(pos1) || m_panel.IsVisible(pos2) || m_panel.IsVisible(center)) { m_visibleIndex.Add(i); } else { if (m_useCellMap.ContainsKey(i) && m_useCellMap[i].CanDisable()) { NListCell cell = m_useCellMap[i]; if (m_isTween) { //cell.HideSubView(false); } cell.gameObject.SetActive(false); m_unuseCell.Add(cell); m_useCellMap.Remove(i); } } firstPos = firstPos + new Vector3(0, -m_cellHeightMap[i], 0); } firstPos = Vector3.zero; if (m_isTween && m_visibleIndex.Count > 0) { for (int i = 0; i < m_visibleIndex[0]; i++) { firstPos += new Vector3(0, -m_cellHeightMap[i], 0); } } for (int index = 0; index < m_visibleIndex.Count; ++index) { int i = m_visibleIndex[index]; Vector3 pos = firstPos + new Vector3(0, -m_height * i, 0); if (!m_useCellMap.ContainsKey(i)) { if (m_unuseCell.Count > 0) { NListCell cell = m_unuseCell[0]; cell.gameObject.transform.localPosition = pos; cell.gameObject.SetActive(true); if (m_isTween) { if (m_cellHeightMap[i] > 0) { //cell.ShowSubView(false); } else { //cell.HideSubView(false); } } DrawCell(cell, i); m_useCellMap.Add(i, cell); m_unuseCell.RemoveAt(0); } } else if (m_isTween) { NListCell cell = m_useCellMap[i]; cell.gameObject.transform.localPosition = pos; if (toggle) { if (m_cellHeightMap[i] > 0) { //cell.ShowSubView(false); } else { //cell.HideSubView(false); } } } firstPos += new Vector3(0, -m_cellHeightMap[i], 0); } }
/// <summary> /// 水平的实现 /// </summary> void WrapContentHorizontalImpl() { Vector3 firstPos = Vector3.zero; m_visibleIndex.Clear(); //这里存在一个逻辑问题, //若table放在最底部,然后重新打开table,且位置在第一个位置, //就会出现不够用的情况 //所以需要这里先处理unuse的情况 for (int i = 0; i < m_totalSize; ++i) { Vector3 pos = firstPos + new Vector3(m_height * i, 0, 0); Vector3 pos1 = pos + new Vector3(-m_height, 0, 0); Vector3 pos2 = pos + new Vector3(m_height, 0, 0); pos1 = m_panel.transform.TransformPoint(pos1); pos2 = m_panel.transform.TransformPoint(pos2); //处理cell很大,view很小的特殊情况 Vector3 center = m_panel.transform.TransformPoint(pos); if (m_panel.IsVisible(pos1) || m_panel.IsVisible(pos2) || m_panel.IsVisible(center)) { m_visibleIndex.Add(i); } else { if (m_useCellMap.ContainsKey(i) && m_useCellMap[i].CanDisable()) { NListCell cell = m_useCellMap[i]; cell.gameObject.SetActive(false); m_unuseCell.Add(cell); m_useCellMap.Remove(i); } } } for (int index = 0; index < m_visibleIndex.Count; ++index) { int i = m_visibleIndex[index]; Vector3 pos = firstPos + new Vector3(m_height * i, 0, 0); if (!m_useCellMap.ContainsKey(i)) { if (m_unuseCell.Count > 0) { NListCell cell = m_unuseCell[0]; cell.gameObject.transform.localPosition = pos; cell.gameObject.SetActive(true); DrawCell(cell, i); m_useCellMap.Add(i, cell); m_unuseCell.RemoveAt(0); } } } }