public override void OnLoadedUI(bool close3dTouch, object args) { base.OnLoadedUI(close3dTouch, args); _closeButton = transform.Find("chat_forward/botton_close").gameObject; _toggleSound = transform.Find("chat_forward/sound_swith").GetComponent <UIToggle>(); _chatTemplate = transform.Find("chat_forward/chat_scroll/chat_template").gameObject; _tableChatPanel = transform.Find("chat_forward/chat_scroll/Table").GetComponent <UITable>(); _chatScrollView = transform.Find("chat_forward/chat_scroll").GetComponent <UIScrollView>(); _chatPanel = transform.Find("chat_forward/chat_scroll").GetComponent <UIPanel>(); _gridChanel = transform.Find("chat_forward/grid_chanel").GetComponent <UIGrid>(); _chanelTemplate = transform.Find("chat_forward/chanel_button_template").gameObject; _sendButton = transform.Find("chat_forward/send_group/botton_send").gameObject; _recordButton = transform.Find("chat_forward/send_group/botton_v").gameObject; _inputBox = transform.Find("chat_forward/send_group").GetComponent <UIInput>(); _playTweeen = transform.Find("chat_forward/send_group/botton_menu").GetComponent <UIPlayTween>(); _popMenu = transform.Find("Panel/Pop"); _lockMessage = transform.Find("Panel/Message").gameObject; _labelLock = transform.Find("Panel/Message/Label").GetComponent <UILabel>(); chatDataList = ChatDataManager.GetInstance().chatDataList; _tablePosition = _tableChatPanel.transform.localPosition; _scrollPosition = _chatScrollView.transform.localPosition; _panelOffset = _chatPanel.clipOffset; needIgnoreList = new List <Transform> { _popMenu, _playTweeen.transform }; _chatInfoItems = new TableItemList <ChatDetailItem>(null, this); chatType = enumChatType.CHANEL_CURRENT; HideLockMessage(); _popMenu.gameObject.SetActive(false); _chanelTemplate.SetActive(false); _chatTemplate.SetActive(false); EventDelegate.Add(_inputBox.onChange, InputTextChange); EventDelegate.Add(_toggleSound.onChange, () => { _isAutoAudioList[(int)chatType] = _toggleSound.value; }); _chatScrollView.onMomentumMove = () => { if (CheckChatPanelBottom() && _lockMessgeNum > 0) { RefreshChangeTap(); } }; _gridChanel.CreateScrollView(_chanelTemplate, GameConst.ChanelList, FillChanelItem); RegistUIBase <ChatUIPopMenu>(_popMenu); RegistUIButton(_closeButton, CloseClick); RegistUIButton(_sendButton, SendClick); RegistUIButton(_recordButton, RecordClick); RegistUIButton(_lockMessage, LockClick); }
public override void OnLoadedUI(bool close3dTouch, object args) { base.OnLoadedUI(close3dTouch, args); _chatPanel = transform.Find("all_bf").gameObject; _chatWidget = transform.Find("all_bf/xinxikuang/Container").GetComponent <UIWidget>(); _btnTextInput = transform.Find("all_bf/text_button").gameObject; _btnVoiceInput = transform.Find("all_bf/voice_button ").gameObject; _chatScrollPanel = transform.Find("all_bf/xinxikuang/Container/Scroll View").GetComponent <UIPanel>(); _chatScrollView = transform.Find("all_bf/xinxikuang/Container/Scroll View").GetComponent <UIScrollView>(); _tableChatPanel = transform.Find("all_bf/xinxikuang/Container/Scroll View/Table").GetComponent <UITable>(); _lockMessage = transform.Find("all_bf/xinxikuang/Container/Panel/Message").gameObject; _labelLock = transform.Find("all_bf/xinxikuang/Container/Panel/Message/Label").GetComponent <UILabel>(); _textTemplate = transform.Find("all_bf/xinxikuang/Container/Scroll View/text_template").gameObject; _microPhoneInput = _chatPanel.GetComponent <MicroPhoneInput>(); _voiceOn = transform.Find("all_bf/voice_button /buttom_on").gameObject; _textTemplate.SetActive(false); _chatInfoItems = new TableItemList <ChatInfoItem>(null, this); _playName = "王五"; _tablePosition = _tableChatPanel.transform.localPosition; _scrollPosition = _chatScrollView.transform.localPosition; _panelOffset = _chatScrollPanel.clipOffset; _chatDataList = ChatDataManager.GetInstance().chatDataList; HideLockMessage(); _chatScrollView.onMomentumMove = () => { if (CheckChatPanelBottom() && _lockMessgeNum > 0) { RefreshChatPanel(); HideLockMessage(); } }; #region 注册点击函数 RegistOnPress(_btnVoiceInput, VoiceInputPress); RegistUIButton(_lockMessage, LockClick); RegistUIButton(_btnTextInput, (go) => { GetParentUI <ChatView>().chatDetailView.RefreshOpen(); }); #endregion }
public void DeleteItem <T>(TableItemList <T> items) where T : TableBaseItem { if (_datas == null) { return; } if (_datas.Count <= 0) { return; } //没满就重写构造这个grid if (_datas.Count < itemCount) { _table.CreateScrollView <T>(gameObject, _datas, items, parentUI); } else { UpdateItem(); } }
/// <summary> /// 注意:能不用这个接口,尽量不用这个接口(聊天之类的可能用到,其他的尽量不用) /// 支持大量item滑动显示的 table创建,左右 上下箭头有效,有对象池 /// FillItem的时候要重置item,(注销点击,一些图片显示的重置) /// 每一次调用这个函数都会把所有的子节入池,然后出池使用 /// 获取item使用TableItemList,直接用数据索引scrollItemList[index]可以范围到对应的item,为空说明没被绘制 /// </summary> /// <returns></returns> static public void CreateScrollView <T>(this UITable table, GameObject templateItem, IList datas, TableItemList <T> scrollItemList, MonoBehaviour parentUI) where T : TableBaseItem, new() { if (scrollItemList == null) { scrollItemList = new TableItemList <T>(null, parentUI); } UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(table.gameObject); //scrollView.StopDragMove(); UIScrollView.Movement moveType = table.columns == 0 ? UIScrollView.Movement.Horizontal : UIScrollView.Movement.Vertical; UITable.Direction direction = table.direction; int itemCount = datas.Count;//grid的行(列)数量 Bounds b = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, true); Vector2 padding = table.padding; int cellHeight = (int)b.size.y + (int)padding.y; int cellWidth = (int)b.size.x; int fillCount = 0; //当前scrollView被填满的格子数 int cacheNum = 3; //多出来的缓存格子 Vector3 lastPos = Vector3.zero; UIPanel panel = scrollView.GetComponent <UIPanel>(); panel.onClipMove = null; if (moveType == UIScrollView.Movement.Vertical) { fillCount = Mathf.CeilToInt(panel.height / cellHeight); } else if (moveType == UIScrollView.Movement.Horizontal) { fillCount = Mathf.CeilToInt(panel.width / cellWidth); } scrollItemList.ResetPos(); scrollItemList.table = table; scrollItemList.panel = panel; scrollItemList.scrollView = scrollView; scrollItemList.CreateItemPool(templateItem, fillCount + cacheNum); List <T> scrollItems = scrollItemList.items; if (scrollItems == null) { scrollItems = new List <T>(); scrollItemList.items = scrollItems; } else { scrollItemList.StoreAllItem(); } // 如果item数量大于填满显示面板的数量做优化 if (itemCount >= fillCount + cacheNum) { itemCount = fillCount + cacheNum; scrollItemList.lastIndex = 0; //上次显示出来的第一个格子,在grid数据中的index int maxIndex = itemCount - 1; int minIndex = 0; int forwardCacheNum = 0; //用于缓存向指定方向滑动,预加载的格子数 // 拖拽刷新面板 panel.onClipMove = (uiPanel) => { Vector3 delata = lastPos - panel.transform.localPosition; float distance = -1; int index = 0;//当前显示出来的第一个格子,在grid数据中的index float curItemDistance = 0; distance = delata.y != 0 ? delata.y : delata.x; // 满的时候向上滑不管它 if (distance > 0 && direction == UITable.Direction.Down) { return; } if (distance < 0 && direction == UITable.Direction.Up) { return; } distance = Mathf.Abs(distance); curItemDistance = CalItemDistance(moveType, scrollItems[scrollItems.Count - 1].transform.localPosition); if (curItemDistance < distance) { index = Mathf.Min(scrollItems[scrollItems.Count - 1].index + 1, datas.Count - 1); } else { for (int i = 0; i < scrollItems.Count; i++) { Vector3 tmpVec = scrollItems[i].transform.localPosition; curItemDistance = CalItemDistance(moveType, tmpVec); if (curItemDistance >= distance) { index = Mathf.Max(scrollItems[i].index - 1, 0); break; } } } // 拖拽不满一个单元格 if (index == scrollItemList.lastIndex) { return; } // 拉到底了 if (index + itemCount > datas.Count) { if (scrollItemList.lastIndex + itemCount == datas.Count) { return; } else { index = datas.Count - itemCount; } } // 重刷 int offset = Math.Abs(index - scrollItemList.lastIndex); // 判断要把最上(左)的item移动到最下(右),还是相反 if (scrollItemList.lastIndex < index) { //如果有上一次的缓存数量,就清掉 if (forwardCacheNum > 0) { while (forwardCacheNum > 1) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction, padding); } } // 滑到底的时候,把上部缓存的那一个item移动到下部 if ((forwardCacheNum > 0 && index + itemCount == datas.Count)) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction, padding); } for (int i = 1; i <= offset; i++) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, false, direction, padding); } } else { forwardCacheNum = forwardCacheNum - offset; //缓存数量 int targetNum = direction == UITable.Direction.Down ? cacheNum - 1 : cacheNum - 2; while ((forwardCacheNum < targetNum && index >= targetNum) || (forwardCacheNum < 0 && index < targetNum)) { // 下(右)移动到上(左) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, false, true, direction, padding); } } scrollItemList.lastIndex = index; }; } // 添加能填满UI数量的button for (int i = 0; i < itemCount; i++) { T item = scrollItemList.GetGridItem(); item.transform.parent = table.transform; item.gameObject.SetActive(true); item.table = table; item.itemCount = itemCount; item.parentUI = parentUI; scrollItems.Add(item); item.FillItem(datas, i); } scrollItemList.datas = datas; scrollItemList.itemCount = fillCount + cacheNum; lastPos = panel.transform.localPosition; if (scrollView != null && !scrollView.disableDragIfFits) { Bounds tableBound; Bounds itemBound; moveType = scrollView.movement; scrollView.onMomentumMove = null; scrollView.onDragFinished = null; Vector3 lastPosX = panel.transform.localPosition; scrollView.onMomentumMove += () => { if (moveType == UIScrollView.Movement.Vertical) { tableBound = NGUIMath.CalculateRelativeWidgetBounds(table.transform, false); itemBound = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, false); if (tableBound.size.y + itemBound.size.y * 0.5f < panel.height) { SpringPanel.Begin(panel.gameObject, lastPosX, 13f).strength = 8f; } } }; scrollView.onDragFinished += () => { if (moveType == UIScrollView.Movement.Vertical) { tableBound = NGUIMath.CalculateRelativeWidgetBounds(table.transform, false); itemBound = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, false); if (tableBound.size.y + itemBound.size.y * 0.5f < panel.height) { SpringPanel.Begin(panel.gameObject, lastPosX, 13f).strength = 8f; } } }; } scrollItemList.StoreQueuePoolItem(); table.Reposition(); }
static public void CreateScrollView <T>(this UITable table, GameObject templateItem, IList datas, TableItemList <T> scrollItemList, UIBase parentUI) where T : TableBaseItem { if (scrollItemList == null) { scrollItemList = new TableItemList <T>(null, parentUI); } if (scrollItemList.items == null) { scrollItemList.items = new List <T>(); } List <T> scrollItems = scrollItemList.items; scrollItems.Clear(); UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(table.gameObject); UIScrollView.Movement moveType = table.columns == 0 ? UIScrollView.Movement.Horizontal : UIScrollView.Movement.Vertical; UITable.Direction direction = table.direction; int itemCount = datas.Count; //grid的行(列)数量 UIWidget tmpWidget = templateItem.GetComponent <UIWidget>(); int cellHeight = tmpWidget.GetComponent <UIWidget>().height; int cellWidth = tmpWidget.GetComponent <UIWidget>().width; int fillCount = 0; //当前scrollView被填满的格子数 int cacheNum = 3; //多出来的缓存格子 Vector3 lastPos = Vector3.zero; UIPanel panel = scrollView.GetComponent <UIPanel>(); panel.onClipMove = null; // 删除UI项目 table.transform.DestroyChildren(); if (moveType == UIScrollView.Movement.Vertical) { fillCount = Mathf.CeilToInt(panel.height / cellHeight); } else if (moveType == UIScrollView.Movement.Horizontal) { fillCount = Mathf.CeilToInt(panel.width / cellWidth); } // 如果item数量大于填满显示面板的数量做优化 if (itemCount >= fillCount + cacheNum) { itemCount = fillCount + cacheNum; int lastIndex = 0; //上次显示出来的第一个格子,在grid数据中的index int maxIndex = itemCount - 1; int minIndex = 0; int forwardCacheNum = 0; //用于缓存向指定方向滑动,预加载的格子数 // 拖拽刷新面板 panel.onClipMove = (uiPanel) => { Vector3 delata = lastPos - panel.transform.localPosition; float distance = -1; int index = 0; //当前显示出来的第一个格子,在grid数据中的index float curItemDistance = 0; distance = delata.y != 0 ? delata.y : delata.x; // 满的时候向上滑不管它 if (distance > 0 && direction == UITable.Direction.Down) { return; } if (distance < 0 && direction == UITable.Direction.Up) { return; } distance = Mathf.Abs(distance); curItemDistance = CalItemDistance(moveType, scrollItems[scrollItems.Count - 1].transform.localPosition); if (curItemDistance < distance) { index = Mathf.Min(scrollItems[scrollItems.Count - 1].index + 1, datas.Count - 1); } else { for (int i = 0; i < scrollItems.Count; i++) { curItemDistance = CalItemDistance(moveType, scrollItems[i].transform.localPosition); if (curItemDistance >= distance) { index = Mathf.Max(scrollItems[i].index - 1, 0); break; } } } // 拖拽不满一个单元格 if (index == lastIndex) { return; } // 拉到底了 if (index + itemCount > datas.Count) { if (lastIndex + itemCount == datas.Count) { return; } else { index = datas.Count - itemCount; } } // 重刷 int offset = Math.Abs(index - lastIndex); // 判断要把最上(左)的item移动到最下(右),还是相反 if (lastIndex < index) { //如果有上一次的缓存数量,就清掉 if (forwardCacheNum > 0) { while (forwardCacheNum > 1) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction); } } // 滑到底的时候,把上部缓存的那一个item移动到下部 if ((forwardCacheNum > 0 && index + itemCount == datas.Count)) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction); } for (int i = 1; i <= offset; i++) { //上(左)移动到下(右) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, false, direction); } } else { forwardCacheNum = forwardCacheNum - offset; //缓存数量 int targetNum = direction == UITable.Direction.Down ? cacheNum - 1 : cacheNum - 2; while ((forwardCacheNum < targetNum && index >= cacheNum - 1) || (forwardCacheNum < 0 && index < cacheNum - 1)) { // 下(右)移动到上(左) MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, false, true, direction); } } lastIndex = index; }; } // 添加能填满UI数量的button for (int i = 0; i < itemCount; i++) { GameObject go = NGUITools.AddChild(table.gameObject, templateItem); go.SetActive(true); T item = go.AddComponent <T>(); item.table = table; item.itemCount = itemCount; item.parentUI = parentUI; scrollItems.Add(item); item.FindItem(); scrollItems[i].FillItem(datas, i); } scrollItemList.itemCount = fillCount + cacheNum; scrollItemList.table = table; scrollItemList.itemTemplate = templateItem; scrollItemList.datas = datas; lastPos = panel.transform.localPosition; table.Reposition(); }
public override void OnLoadedUI(bool close3dTouch, object args) { base.OnLoadedUI(close3dTouch, args); _chatPanel = transform.Find("all_bf").gameObject; _chatWidget = transform.Find("all_bf/xinxikuang/Container").GetComponent<UIWidget>(); _btnTextInput = transform.Find("all_bf/text_button").gameObject; _btnVoiceInput = transform.Find("all_bf/voice_button ").gameObject; _chatScrollPanel = transform.Find("all_bf/xinxikuang/Container/Scroll View").GetComponent<UIPanel>(); _chatScrollView = transform.Find("all_bf/xinxikuang/Container/Scroll View").GetComponent<UIScrollView>(); _tableChatPanel = transform.Find("all_bf/xinxikuang/Container/Scroll View/Table").GetComponent<UITable>(); _lockMessage = transform.Find("all_bf/xinxikuang/Container/Panel/Message").gameObject; _labelLock = transform.Find("all_bf/xinxikuang/Container/Panel/Message/Label").GetComponent<UILabel>(); _textTemplate = transform.Find("all_bf/xinxikuang/Container/Scroll View/text_template").gameObject; _microPhoneInput = _chatPanel.GetComponent<MicroPhoneInput>(); _voiceOn = transform.Find("all_bf/voice_button /buttom_on").gameObject; _textTemplate.SetActive(false); _chatInfoItems = new TableItemList<ChatInfoItem>(null, this); _playName = "王五"; _tablePosition = _tableChatPanel.transform.localPosition; _scrollPosition = _chatScrollView.transform.localPosition; _panelOffset = _chatScrollPanel.clipOffset; _chatDataList = ChatDataManager.GetInstance().chatDataList; HideLockMessage(); _chatScrollView.onMomentumMove = () => { if (CheckChatPanelBottom() && _lockMessgeNum > 0) { RefreshChatPanel(); HideLockMessage(); } }; #region 注册点击函数 RegistOnPress(_btnVoiceInput, VoiceInputPress); RegistUIButton(_lockMessage, LockClick); RegistUIButton(_btnTextInput, (go) => { GetParentUI<ChatView>().chatDetailView.RefreshOpen(); }); #endregion }
public override void OnLoadedUI(bool close3dTouch, object args) { base.OnLoadedUI(close3dTouch, args); _closeButton = transform.Find("chat_forward/botton_close").gameObject; _toggleSound = transform.Find("chat_forward/sound_swith").GetComponent<UIToggle>(); _chatTemplate = transform.Find("chat_forward/chat_scroll/chat_template").gameObject; _tableChatPanel = transform.Find("chat_forward/chat_scroll/Table").GetComponent<UITable>(); _chatScrollView = transform.Find("chat_forward/chat_scroll").GetComponent<UIScrollView>(); _chatPanel = transform.Find("chat_forward/chat_scroll").GetComponent<UIPanel>(); _gridChanel = transform.Find("chat_forward/grid_chanel").GetComponent<UIGrid>(); _chanelTemplate = transform.Find("chat_forward/chanel_button_template").gameObject; _sendButton = transform.Find("chat_forward/send_group/botton_send").gameObject; _recordButton = transform.Find("chat_forward/send_group/botton_v").gameObject; _inputBox = transform.Find("chat_forward/send_group").GetComponent<UIInput>(); _playTweeen = transform.Find("chat_forward/send_group/botton_menu").GetComponent<UIPlayTween>(); _popMenu = transform.Find("Panel/Pop"); _lockMessage = transform.Find("Panel/Message").gameObject; _labelLock = transform.Find("Panel/Message/Label").GetComponent<UILabel>(); chatDataList = ChatDataManager.GetInstance().chatDataList; _tablePosition = _tableChatPanel.transform.localPosition; _scrollPosition = _chatScrollView.transform.localPosition; _panelOffset = _chatPanel.clipOffset; needIgnoreList = new List<Transform> { _popMenu, _playTweeen.transform }; _chatInfoItems = new TableItemList<ChatDetailItem>(null, this); chatType = enumChatType.CHANEL_CURRENT; HideLockMessage(); _popMenu.gameObject.SetActive(false); _chanelTemplate.SetActive(false); _chatTemplate.SetActive(false); EventDelegate.Add(_inputBox.onChange, InputTextChange); EventDelegate.Add(_toggleSound.onChange, () => { _isAutoAudioList[(int)chatType] = _toggleSound.value; }); _chatScrollView.onMomentumMove = () => { if (CheckChatPanelBottom() && _lockMessgeNum > 0) { RefreshChangeTap(); } }; _gridChanel.CreateScrollView(_chanelTemplate, GameConst.ChanelList, FillChanelItem); RegistUIBase<ChatUIPopMenu>(_popMenu); RegistUIButton(_closeButton, CloseClick); RegistUIButton(_sendButton, SendClick); RegistUIButton(_recordButton, RecordClick); RegistUIButton(_lockMessage, LockClick); }