/// <summary> /// 选中某单元格 /// </summary> /// <param name="dataIndex">单元格的dataIndex</param> /// <param name="multip">是否开启多选模式(多选模式下具有反选功能!)</param> public void SelectCell(int dataIndex, bool multip = false) { int index = selectedIndex.FindIndex(delegate(int temp) { return(temp == dataIndex); }); if (index != -1) { //反选 if (multip) { selectedIndex.RemoveAt(index); } } else { if (!multip) { selectedIndex.Clear(); } selectedIndex.Add(dataIndex); } foreach (GameObject cell in cellsInUse) { ScrollViewCell scrollableCell = cell.GetComponent <ScrollViewCell>(); scrollableCell.ChooseCell(selectedIndex.Contains(scrollableCell.DataIndex)); } }
/// <summary> /// 修改某一个格子的值 /// </summary> public void SetCellsData(System.Object data, int index = -1) { if (allCellsData == null) { StartCoroutine(DelaySetCellData(data, index)); } else if (index == -1) { index = allCellsData.IndexOf(data); } if (index < 0) { return; } foreach (GameObject go in cellsInUse) { ScrollViewCell scrollableCell = go.GetComponent <ScrollViewCell>(); if (scrollableCell.DataIndex == index) { scrollableCell.DataObject = data; break; } } }
// Use this for initialization void Start() { // GameObject[] objects = GameObject.FindGameObjectsWithTag("scrollview_cell");//根据tag查找物体,但是必须是激活的 // foreach(GameObject go in objects) { // ScrollViewCell cell = (ScrollViewCell)go.GetComponent (typeof(ScrollViewCell)); // cell.test (); // } header.transform.SetSiblingIndex(orderIndex); orderIndex++; GameObject go = Resources.Load("Prefabs/Cell") as GameObject; if (go) { for (int i = 0; i < 20; i++) { GameObject cell = Instantiate(go); if (cell) { list.Add(cell); cell.transform.SetParent(contentNode.transform, false); //If param2 is false, perphaps change scale cell.transform.SetSiblingIndex(orderIndex); //cell.transform.localScale = new Vector3 (1, 1, 1); orderIndex++; Button button = (Button)cell.GetComponent <Button>(); if (button) { button.onClick.AddListener(delegate { Debug.Log("---------->i: " + i); OnClickedCell(cell); }); } ScrollViewCell cellScript = (ScrollViewCell)cell.GetComponent <ScrollViewCell>(); if (cellScript) { cellScript.test(); } } } } footer.transform.SetSiblingIndex(orderIndex); }
void OnClickedCell(GameObject cell) { Debug.Log("Clicked button with index: " + (cell.transform.GetSiblingIndex() - 1)); RectTransform rt = cell.GetComponent <RectTransform>(); ScrollViewCell cellScript = (ScrollViewCell)cell.GetComponent <ScrollViewCell>(); if (cellScript) { if (cellScript.isAnimating) { return; } cellScript.isAnimating = true; if (cellScript.isExpanded) { //rt.sizeDelta = new Vector2 (rt.sizeDelta.x, rt.sizeDelta.y - 100); var toValue = new Vector2(rt.sizeDelta.x, rt.sizeDelta.y - 100); DOTween.To(() => rt.sizeDelta, size => rt.sizeDelta = size, toValue, 0.3f).OnComplete(delegate { cellScript.isExpanded = false; cellScript.isAnimating = false; }); } else { //rt.sizeDelta = new Vector2 (rt.sizeDelta.x, rt.sizeDelta.y + 100); var toValue = new Vector2(rt.sizeDelta.x, rt.sizeDelta.y + 100); DOTween.To(() => rt.sizeDelta, size => rt.sizeDelta = size, toValue, 0.3f).OnComplete(delegate { cellScript.isExpanded = true; cellScript.isAnimating = false; });; } } // cell.transform.DoRec (new Vector3 (1, 2, 1), 0.3f).OnComplete(delegate { // // //LayoutRebuilder.ForceRebuildLayoutImmediate(this.contentNode.GetComponent<RectTransform>()); // // }); }
/// <summary> /// 更新每一个row的所有单元格 /// </summary> /// <param name="cellIndex">单元格序列</param> /// <param name="scrollingPositive">正反向</param> private void UpdateContent(int cellIndex, bool scrollingPositive) { int index = scrollingPositive ? ((cellIndex - 1) * NUMBER_OF_COLUMNS) + (visibleCellsTotalCount) : (cellIndex * NUMBER_OF_COLUMNS); LinkedListNode <GameObject> tempCell = null; int currentDataIndex = 0; for (int i = 0; i < NUMBER_OF_COLUMNS; i++) { this.FreeCell(scrollingPositive); tempCell = GetCellFromPool(scrollingPositive); currentDataIndex = index + i; PositionCell(tempCell.Value, index + i); ScrollViewCell scrollableCell = tempCell.Value.GetComponent <ScrollViewCell>(); if (currentDataIndex >= 0 && currentDataIndex < allCellsData.Count) { scrollableCell.Init(this, allCellsData[currentDataIndex], currentDataIndex); if (onCellInit != null) { onCellInit(scrollableCell, currentDataIndex); } } else { scrollableCell.Init(this, null, currentDataIndex); //if (onCellInit != null) //{ // onCellInit(null, currentDataIndex); //} } scrollableCell.ConfigureCell(); if (onCellConfig != null) { onCellConfig(currentDataIndex); } scrollableCell.ChooseCell(selectedIndex.Contains(currentDataIndex)); } }
public virtual void Init(ScrollViewLooper controller, System.Object data, int index, float cellHeight = 0.0f, float cellWidth = 0.0f, ScrollViewCell parentCell = null) { this.controller = controller; this.dataObject = data; this.dataIndex = index; this.cellHeight = cellHeight; this.cellWidth = cellWidth; this.parentCell = parentCell; if (deactivateIfNull) { if (data == null) { this.gameObject.SetActive(false); } else { this.gameObject.SetActive(true); } } //if (data != null) //{ // if (controller == BagUISys.Instance.looper) // { // BagItemArgs.scrollCell = this; // BagItemArgs.data = data as BagResEntity; // BagItemArgs.id = index; // CEventSys.Instance.TriggerLuaEvent(ELuaEvent.UI_BagInitItem); // } // else if (controller == EquipUISys.Instance.liantiLooper) // { // BagItemArgs.scrollCell = this; // BagItemArgs.data = data as BagResEntity; // BagItemArgs.id = index; // CEventSys.Instance.TriggerLuaEvent(ELuaEvent.UI_LiantiInitItem); // } //} }
/// <summary> /// 刷新Content /// </summary> void UpdateView(IList cellDataList) { if (cellDataList == null) { return; } if (cellsInUse.Count > 0) { foreach (var cell in cellsInUse) { localCellsPool.AddLast(cell); } cellsInUse.Clear(); } previousInitialIndex = 0; initialIndex = 0; content.gameObject.SetActive(true); LinkedListNode <GameObject> tempCell = null; allCellsData = cellDataList; if (horizontal) { content.sizeDelta = new Vector2((allCellsData.Count + NUMBER_OF_COLUMNS - 1) / NUMBER_OF_COLUMNS * cellWidth, content.sizeDelta.y); } else { content.sizeDelta = new Vector2(cellWidth * NUMBER_OF_COLUMNS, (allCellsData.Count + NUMBER_OF_COLUMNS - 1) / NUMBER_OF_COLUMNS * cellHeight); } int currentDataIndex = 0; for (int i = 0; i < visibleCellsTotalCount; i++) { tempCell = GetCellFromPool(true); if (tempCell == null || tempCell.Value == null) { continue; } currentDataIndex = i + initialIndex * NUMBER_OF_COLUMNS; PositionCell(tempCell.Value, currentDataIndex); tempCell.Value.SetActive(true); ScrollViewCell scrollableCell = tempCell.Value.GetComponent <ScrollViewCell>(); if (currentDataIndex < cellDataList.Count) { scrollableCell.Init(this, cellDataList[i], currentDataIndex); if (onCellInit != null) { onCellInit(scrollableCell, currentDataIndex); } } else { scrollableCell.Init(this, null, currentDataIndex); //if (onCellInit != null) //{ // onCellInit(null, currentDataIndex); //} } scrollableCell.ConfigureCell(); if (onCellConfig != null) { onCellConfig(currentDataIndex); } scrollableCell.ChooseCell(selectedIndex.Contains(currentDataIndex)); } }
public override float CellSize(ScrollViewCell cell) { SimpleImageCell imageCell = (SimpleImageCell)cell; return(imageCell.GetPreferHeight((Sprite)data, LogConsoleSettings.GetTreeViewOffsetByLevel(level))); }
public virtual float CellSize(ScrollViewCell cell) { return(CellSize()); }