Exemple #1
0
 public override void OnSelect(BaseEventData eventData)
 {
     base.OnSelect(eventData);
     OnSelectEvent?.Invoke(eventData);
     if (scrollRect != null)
     {
         // FIXME This is for automatically scrolling the scroll view up and down, need to make sure it's working as intended.
         // TODO Adding left and right scrolling might also be nice.
         float         contentHeight  = scrollRect.content.rect.height;
         float         viewportHeight = scrollRect.viewport.rect.height;
         float         centerLineY    = eventData.selectedObject.transform.localPosition.y;
         RectTransform rectTransform  = eventData.selectedObject.GetComponent <RectTransform>();
         float         rectHeight     = rectTransform.rect.height;
         float         lowerBound     = centerLineY - (rectHeight * 1.0f);
         float         upperBound     = centerLineY + (rectHeight * 1.0f);
         float         lowerVisible   = (contentHeight - viewportHeight) * scrollRect.normalizedPosition.y - contentHeight;
         float         upperVisible   = lowerVisible + viewportHeight;
         float         desiredBoundY;
         if (upperBound > upperVisible)
         {
             desiredBoundY = upperBound - viewportHeight + (rectHeight * 1.0f);
         }
         else if (lowerBound < lowerVisible)
         {
             desiredBoundY = lowerBound - (rectHeight * 1.0f);
         }
         else
         {
             return;
         }
         float normalizedDesiredY = (desiredBoundY + contentHeight) / (contentHeight - viewportHeight);
         scrollRect.normalizedPosition = new Vector2(0.0f, Mathf.Clamp01(normalizedDesiredY));
     }
 }
        /// <summary>
        /// 入口(构造函数)
        /// </summary>
        public CustomBar(OnSelectEvent onSelect = null)
        {
            this.m_onSelectEvent = onSelect;
            List <Setting_CustomBarCellData> settingList = UserSetting.Instance.GetCustomBarCellList();
            int count = settingList.Count;

            if (count > 0)
            {
                //恢复上次保存的状态
                for (int i = 0; i < count; i++)
                {
                    AddElement(settingList[i]);
                }
            }
            else
            {
                //默认创建一个页签
                AddElement();
            }
            ShowEditButton(true);

            int curSelectIndex = UserSetting.Instance.curSelectTabIndex < m_cellList.Count ? UserSetting.Instance.curSelectTabIndex : 0;

            m_cellList[curSelectIndex].UI_Button.Select();
            if (m_onSelectEvent != null)
            {
                m_onSelectEvent.Invoke(curSelectIndex);
            }
            UserSetting.Instance.curSelectTabIndex = curSelectIndex;
        }
Exemple #3
0
        public override void OnSelect(BaseEventData eventData)
        {
            base.OnSelect(eventData);

            OnSelect_Event?.Invoke();

            //Debug.Log($"{name}: OnSelect", gameObject);
        }
 private void OnBtnClick_Tab(int btnIndex)
 {
     UserSetting.Instance.curSelectTabIndex = btnIndex;
     if (m_onSelectEvent != null)
     {
         m_onSelectEvent.Invoke(btnIndex);
     }
 }
 public void OnSelect()
 {
     if (displayed != null && selectable)
     {
         if (Selected)
         {
             Deselect();
         }
         else
         {
             selected = true;
             OnSelectEvent?.Invoke(this);
             selectionBorder?.SetActive(true);
         }
     }
 }
Exemple #6
0
 public void SelectedAnswer()
 {
     OnSelectEvent?.Invoke(IsCorrect);
 }
 /// <summary>
 /// On select.
 /// </summary>
 /// <param name="eventData">Pointer event data.</param>
 public void OnSelect(BaseEventData eventData)
 {
     OnSelectEvent?.Invoke(eventData);
 }