Пример #1
0
 protected override void OnValidate()
 {
     // hitArea 可在编辑器编辑
     if (m_hitArea == null)
     {
         m_hitArea = LuaHelper.CreateGameObject("HitArea", transform, false);
         Image img = m_hitArea.AddComponent <Image> ();
         img.color = Color.clear;
     }
 }
Пример #2
0
 void OnValidate()
 {
     // hitArea 可在编辑器编辑
     if (m_hitArea == null)
     {
         m_hitArea = LuaHelper.CreateGameObject("HitArea", transform, false);
         Image img = m_hitArea.AddComponent <Image>();
         img.color = Color.clear;
         m_hitArea.AddComponent <PointerEventPasser>();
     }
 }
Пример #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        protected virtual void Initialize()
        {
            if (m_initialized)
            {
                return;
            }
            m_initialized = true;

            m_content               = (RectTransform)LuaHelper.CreateGameObject("Content", transform, false).transform;
            m_content.pivot         = Vector2.up;
            m_content.localPosition = Vector3.zero;
        }
Пример #4
0
 /// <summary>
 /// 清理并销毁所有的 Item
 /// </summary>
 public void Clean()
 {
     if (m_content != null)
     {
         Destroy(m_content.gameObject);
         m_content = (RectTransform)LuaHelper.CreateGameObject("Content", transform, false).transform;
         m_content.SetSiblingIndex(0);
     }
     m_itemPool.Clear();
     m_itemList.Clear();
     m_itemIdxList.Clear();
     m_itemCount = 0;
     m_index     = -1;
 }
Пример #5
0
        /// <summary>
        /// 通过 index 来获取界面
        /// </summary>
        /// <returns>The view.</returns>
        /// <param name="index">Index.</param>
        public override GameObject GetView(int index)
        {
            if (index >= views.Count || index < 0)
            {
                return(null);
            }

            if (views[index] != null)
            {
                return(views[index]);
            }

            // 新创建的 view
            GameObject view = base.GetView(index);

            LuaHelper.CreateGameObject("Content", view.transform, false);// items 容器
            return(view);
        }
Пример #6
0
        protected override void Awake()
        {
            GameObject viewport = LuaHelper.CreateGameObject("Viewport", transform, false);
            Mask       mask     = viewport.gameObject.AddComponent <Mask> ();

            mask.showMaskGraphic = false;
            viewport.gameObject.AddComponent <Image> ();
            m_viewport               = (RectTransform)viewport.transform;
            m_viewport.pivot         = Vector2.up;
            m_viewport.sizeDelta     = m_viewportSize;
            m_viewport.localPosition = Vector3.zero;

            m_content               = (RectTransform)LuaHelper.CreateGameObject("Content", m_viewport, false).transform;
            m_content.pivot         = Vector2.up;
            m_content.localPosition = Vector3.zero;

            m_scrollRect            = gameObject.AddComponent <ScrollRect> ();
            m_scrollRect.content    = m_content;
            m_scrollRect.viewport   = m_viewport;
            m_scrollRect.horizontal = !m_isVertical;
            m_scrollRect.vertical   = m_isVertical;
            m_scrollRect.onValueChanged.AddListener(ScrollRect_ValueChanged);
        }
Пример #7
0
        protected override void Awake()
        {
            m_content = (RectTransform)LuaHelper.CreateGameObject("Content", transform, false).transform;
            m_content.SetSiblingIndex(0);
            ResetItemSize();

            // 响应点击区域相关事件
            EventTrigger trigger = m_hitArea.AddComponent <EventTrigger> ();

            EventTrigger.Entry entry;

            // PointerDown
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerDown;
            entry.callback.AddListener((data) => {
                if (m_contentTweener != null)
                {
                    m_contentTweener.Kill();
                }
            });
            trigger.triggers.Add(entry);

            // PointerUp
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerUp;
            entry.callback.AddListener((data) => {
                if (!m_dragging)
                {
                    ScrollToSelectedItem();
                }
            });
            trigger.triggers.Add(entry);

            // BeginDrag
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.BeginDrag;
            entry.callback.AddListener((data) => {
                m_dragging = true;
                SetDragPosition((PointerEventData)data);
                m_lastDragPos = m_curDragPos;
                StartRecordVelocity();
            });
            trigger.triggers.Add(entry);

            // Dragging
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.Drag;
            entry.callback.AddListener((data) => {
                SetDragPosition((PointerEventData)data);
                RecordVelocity();
            });
            trigger.triggers.Add(entry);

            // EndDrag
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.EndDrag;
            entry.callback.AddListener((data) => {
                SetDragPosition((PointerEventData)data);
                m_dragging = false;
                EndRecordVelocity();
            });
            trigger.triggers.Add(entry);
        }
Пример #8
0
 protected override void Awake()
 {
     m_content               = (RectTransform)LuaHelper.CreateGameObject("Content", transform, false).transform;
     m_content.pivot         = Vector2.up;
     m_content.localPosition = Vector3.zero;
 }