using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; public class TestingCopyBseRootCtr : MonoBehaviour { public static TestingCopyBseRootCtr Instance; private void Awake() { Instance = this; //LoadAllPageObj(); } private void OnDestroy() { Instance = null; } private void OnEnable() { InitTetingCopyPanel(); } //public UIContainerSelect _TestingCopyMenuItemContainer; public GameObject _LeftHighLightIcon; public GameObject _RinghtHighLightIcon; public RectTransform _ViewPortRec; public GridLayoutGroup _GridLayout; public Transform _ContentTrans; public Transform _PageParent; //按照顺序赋值一个ID吧(那么预设添加的时候顺序要按照表中的顺序来 动态赋值简单点) public List _TestingCopyBasePanelList; //初始化按钮 private List _TestingCopyIdList = new List(); public void InitTetingCopyPanel() { _TestingCopyIdList = new List(); foreach (var testingCopy in TableManager.GetTestingCopy()) { if (!_TestingCopyIdList.Contains(testingCopy.Key)) { _TestingCopyIdList.Add(testingCopy.Key); } } InitPrefabFubenId(); //if (_TestingCopyIdList.Count > 0) // _TestingCopyMenuItemContainer.InitSelectContent(_TestingCopyIdList, new List { _TestingCopyIdList[0]}, OnMenuItemClick); //GetAllRecWidth(); //计算整个区域的宽度 用于拖拽的时候显示Left 和 Right icon } public void InitPrefabFubenId() { for(int index = 0; index < _TestingCopyIdList.Count && index < _TestingCopyBasePanelList.Count; index++) { _TestingCopyBasePanelList[index]._FubenId = _TestingCopyIdList[index]; } } //public void RefreshMenuItemRemainTime() //{ // _TestingCopyMenuItemContainer.ForeachActiveItem(item => { // item.RefreshRemainTimeIcon(); // }); //} private int _SelectTestingCopyId = -1; public void OnMenuItemClick(object selectObj) { int _SelectId = (int)selectObj; _SelectTestingCopyId = _SelectId; ShowSelectedPanel(); } public void ShowSelectedPanel() { for(int index = 0; index < _TestingCopyBasePanelList.Count; index++) { _TestingCopyBasePanelList[index].gameObject.SetActive(_TestingCopyBasePanelList[index]._FubenId == _SelectTestingCopyId); } } #region 左右按钮显示控制 private float _AllContentRecWidth = 0.0f; private float _ViewPortSizeDeltaWidth = 0.0f; private void GetAllRecWidth() { _ViewPortSizeDeltaWidth = _ViewPortRec.rect.width; _AllContentRecWidth = _GridLayout.cellSize.x * _TestingCopyIdList.Count + (_TestingCopyIdList.Count - 1) * _GridLayout.spacing.x + _GridLayout.padding.left; } public void OnScrollviewDrag() { if (_AllContentRecWidth < _ViewPortSizeDeltaWidth) { if (_LeftHighLightIcon.activeInHierarchy) { _LeftHighLightIcon.SetActive(false); } if (_RinghtHighLightIcon.activeInHierarchy) { _LeftHighLightIcon.SetActive(false); } return; } //content左移位置大于一个CellSize.x 即显示LeftIcon if (_ContentTrans.localPosition.x < -_GridLayout.cellSize.x) { if (!_LeftHighLightIcon.activeInHierarchy) { _LeftHighLightIcon.SetActive(true); } } else { if (_LeftHighLightIcon.activeInHierarchy) { _LeftHighLightIcon.SetActive(false); } } //rightIcon 1.视野位置大小,这个要ViewPort吧 if (_AllContentRecWidth < _ViewPortSizeDeltaWidth) { if (_RinghtHighLightIcon.activeInHierarchy) { _RinghtHighLightIcon.SetActive(false); } } else { if (_ContentTrans.localPosition.x > -(_AllContentRecWidth - _ViewPortSizeDeltaWidth - _GridLayout.cellSize.x)) { if (!_RinghtHighLightIcon.activeInHierarchy) { _RinghtHighLightIcon.SetActive(true); } } else { if (_RinghtHighLightIcon.activeInHierarchy) { _RinghtHighLightIcon.SetActive(false); } } } } #endregion }