예제 #1
0
        public static UGUIClickHandler Get(GameObject go, string sound)
        {
            UGUIClickHandler listener = Get(go);

            //listener.m_sound = sound;
            return(listener);
        }
예제 #2
0
        public static UGUIClickHandler Get(Transform tran, string sound)
        {
            UGUIClickHandler listener = Get(tran);

            //listener.m_sound = sound;
            return(listener);
        }
예제 #3
0
        public static UGUIClickHandler Get(GameObject go)
        {
            UGUIClickHandler listener = go.GetComponent <UGUIClickHandler>();

            if (listener == null)
            {
                listener = go.AddComponent <UGUIClickHandler>();
            }
            return(listener);
        }
예제 #4
0
 /// <summary>
 /// 开启或关闭某一项的响应
 /// </summary>
 /// <param name="index"></param>
 public void Enable(int index, bool isEnable = true)
 {
     if (index < m_items.Count)
     {
         var toggle = m_items[index].GetComponent <Toggle>();
         if (toggle)
         {
             toggle.isOn    = isEnable;
             toggle.enabled = isEnable;
             if (isEnable)
             {
                 UGUIClickHandler.Get(toggle.gameObject, m_itemClickSound).onPointerClick += OnItemClick;
             }
             else
             {
                 UGUIClickHandler.Get(toggle.gameObject, m_itemClickSound).RemoveAllHandler();
             }
         }
     }
 }
예제 #5
0
        //    private void Update()
        //    {
        //        //只在可滚动的情况下执行
        //        if (m_canvas != null)
        //        {
        //            if (m_content.anchoredPosition == m_lastContentPos)
        //            {
        //                if (!m_canvas.pixelPerfect)
        //                    m_canvas.pixelPerfect = true;
        //            }
        //            else
        //                m_lastContentPos = m_content.anchoredPosition;
        //        }
        //    }

        /// <summary>
        /// 更新视图
        /// </summary>
        public void UpdateView()
        {
            if (useLoopItems)
            {
                if (m_data != null)
                {
                    m_startIndex = Mathf.Max(0, Mathf.Min(m_startIndex / ConstraintCount, DataUnitCount - m_viewItemCount - CacheUnitCount)) * ConstraintCount;
                }
                var frontSpace  = m_startIndex / ConstraintCount * m_itemSpace;
                var behindSpace = Mathf.Max(0, m_itemSpace * (DataUnitCount - CacheUnitCount) - frontSpace - (m_itemSpace * m_viewItemCount));
                if (m_isVertical)
                {
                    m_LayoutGroup.padding = new RectOffset(m_oldPadding.left, m_oldPadding.right, frontSpace, behindSpace);
                }
                else
                {
                    m_LayoutGroup.padding = new RectOffset(frontSpace, behindSpace, m_oldPadding.top, m_oldPadding.bottom);
                }
            }
            else
            {
                m_startIndex = 0;
            }

            if (m_goItemRender == null || m_itemRenderType == null || m_data == null || m_content == null)
            {
                return;
            }

            int itemLength = useLoopItems ? m_viewItemCount * ConstraintCount + CacheCount : m_data.Length;

            itemLength = Mathf.Min(itemLength, m_data.Length);
            //LoggerHelper.Error("len: "+itemLength);
            for (int i = itemLength; i < m_items.Count; i++)
            {
                Destroy(m_items[i].gameObject);
                m_items[i] = null;
            }
            for (int i = m_items.Count - 1; i >= 0; i--)
            {
                if (m_items[i] == null)
                {
                    m_items.RemoveAt(i);
                }
            }

            for (int i = 0; i < itemLength; i++)
            {
                var index = m_startIndex + i;
                if (index >= m_data.Length || index < 0)
                {
                    continue;
                }
                if (i < m_items.Count)
                {
                    m_items[i].SetData(m_data[index]);

                    if (useClickEvent || autoSelectFirst)
                    {
                        SetToggle(i, m_selectedData == m_data[index]);
                    }
                }
                else
                {
                    var go = Instantiate(m_goItemRender) as GameObject;
                    go.name = m_goItemRender.name;
                    go.transform.SetParent(m_content, false);
                    go.SetActive(true);
                    var script = go.AddComponent(m_itemRenderType) as ItemRender;
                    if (!go.activeInHierarchy)
                    {
                        script.Awake();
                    }
                    script.SetData(m_data[index]);
                    script.m_owner = this;
                    if (useClickEvent)
                    {
                        UGUIClickHandler.Get(go, m_itemClickSound).onPointerClick += OnItemClick;
                    }
                    if (m_toggleGroup != null)
                    {
                        var toggle = go.GetComponent <Toggle>();
                        if (toggle != null)
                        {
                            toggle.group = m_toggleGroup;

                            //使用循环模式的话不能用渐变效果,否则视觉上会出现破绽
                            if (useLoopItems)
                            {
                                toggle.toggleTransition = Toggle.ToggleTransition.None;
                            }
                        }
                    }
                    m_items.Add(script);
                }
            }
        }