private static void RefreshLeftRight(GameObject leftButton, GameObject rightButton, CSharpFun action, IList datas, int curKey) { leftButton.GetComponent <Collider>().enabled = true; leftButton.GetComponent <UISprite>().color = Color.white; rightButton.GetComponent <Collider>().enabled = true; rightButton.GetComponent <UISprite>().color = Color.white; if (curKey <= 0) { leftButton.GetComponent <Collider>().enabled = false; leftButton.GetComponent <UISprite>().color = Color.gray; curKey = 0; } if (curKey >= datas.Count - 1) { rightButton.GetComponent <Collider>().enabled = false; rightButton.GetComponent <UISprite>().color = Color.gray; curKey = datas.Count - 1; } if (datas.Count != 0) { action(new object[] { datas[curKey] }); } else { action(null); } }
/// <summary> /// 注册左右切换模型数据显示的按钮控件,具体可以参照PetView的写法 /// </summary> /// <param name="leftButton">向左的按钮</param> /// <param name="rightButton">向右的按钮</param> /// <param name="datas">显示内容的逻辑数据数组</param> /// <param name="action">刷新界面的函数</param> public static void RegistUILeftRightButton(GameObject leftButton, GameObject rightButton, IList datas, int curKey, CSharpFun action) { // 初始化 RefreshLeftRight(leftButton, rightButton, action, datas, curKey); RegistUIButton(leftButton, (sender) => { curKey--; curKey = Mathf.Max(0, curKey); RefreshLeftRight(leftButton, rightButton, action, datas, curKey); }); RegistUIButton(rightButton, (sender) => { curKey++; curKey = Mathf.Min(curKey, datas.Count - 1); RefreshLeftRight(leftButton, rightButton, action, datas, curKey); }); }