//*****************************-》 可收展 循环列表 《-**************************** //初始化: // InitData(CallBack) //不需要 回调Cell点击函数时用此 InitData() // InitData(CallBack, OnClickCallBack) //需要回调 Cell点击函数时用此 InitData() //刷新列表: // ShowList(数量格式: string = "5|5|6") //回调: //Func(GameObject = 收展按钮, GameObject = Cell, int = 收展按钮索引 Index, int = 子cell索引) //OnClickCell(GameObject = Cell, int = Index) //点击Cell using System; using System.Collections.Generic; namespace UnityEngine.UI { public class ExpandableViewSingle : RecycleView { public GameObject m_ExpandButton; public float m_BackgroundMargin; public bool m_IsExpand = false; private float m_ExpandButtonX; private float m_ExpandButtonY; private float m_ExpandButtonWidth; private float m_ExpandButtonHeight; private Vector2 m_BackgroundOriginSize; //展开信息 struct ExpandInfo { public GameObject button; public bool isExpand; public CellInfo[] cellInfos; public float size; public int cellCount; } private ExpandInfo[] m_ExpandInfos = null; GameObject lastButton = null; private Dictionary m_IsAddedListener = new Dictionary(); //用于 判断是否重复添加 点击事件 private new Action m_FuncCallBackFunc; protected new Action m_FuncOnClickCallBack; public void Init(Action callBack) { Init(callBack, null); } public void Init_Click(Action onButtonClickCallBack) { FuncOnButtonClickCallBack = onButtonClickCallBack; } public void Init(Action callBack, Action onClickCallBack, Action onButtonClickCallBack) { FuncOnButtonClickCallBack = onButtonClickCallBack; Init(callBack, onClickCallBack); } public void Init(Action callBack, Action onClickC0allBack) { base.Init(null, null); m_FuncCallBackFunc = callBack; /* Button 处理 */ if (m_ExpandButton == null) { if (content.transform.Find("Button") != null) { m_ExpandButton = content.transform.Find("Button").gameObject; } } if (m_ExpandButton != null) { RectTransform rectTrans = m_ExpandButton.transform.GetComponent(); m_ExpandButtonX = rectTrans.anchoredPosition.x; m_ExpandButtonY = rectTrans.anchoredPosition.y; SetPoolsButtonObj(m_ExpandButton); m_ExpandButtonWidth = rectTrans.rect.width; m_ExpandButtonHeight = rectTrans.rect.height; var background = m_ExpandButton.transform.Find("background"); if (background != null) { m_BackgroundOriginSize = background.GetComponent().sizeDelta; } } } public override void ShowList(string numStr) { ClearCell(); //清除所有Cell (非首次调Showlist时执行) int totalCount = 0; int beforeCellCount = 0; string[] numArray = numStr.Split('|'); int buttonCount = numArray.Length; bool isReset; if (isInited && m_ExpandInfos.Length == buttonCount) { isReset = false; } else { m_ExpandInfos = new ExpandInfo[buttonCount]; isReset = true; } for (int k = 0; k < buttonCount; k++) { //-> Button 物体处理 GameObject button = GetPoolsButtonObj(); button.name = k.ToString(); Button buttonComponent = button.GetComponent