示例#1
0
    public void UpdateDataByIntValue(string attr, int value, LuaTable data)
    {
        if (this.m_Datas == null)
        {
            return;
        }
        int length = this.m_Datas.Count;
        int i      = 0;

        for (i = 0; i < length; i++)
        {
            LuaTable tp = this.m_Datas[i] as LuaTable;
            int      v;
            tp.Get <string, int>(attr, out v);
            if (v == value)
            {
                this.m_Datas[i] = data;
                break;
            }
        }
        for (int j = 0; j < m_InstantiateItems.Count; j++)
        {
            UILoopItem item = m_InstantiateItems[j].GetComponent <UILoopItem>();
            if (item.itemIndex == i)
            {
                item.Data(data);
            }
        }
    }
示例#2
0
 private void updateItem(int index, GameObject item)
 {
     item.SetActive(index < m_Datas.Count);
     if (item.activeSelf)
     {
         UILoopItem lit = item.GetComponent <UILoopItem>();
         lit.UpdateItem(index, item);
         lit.Data(m_Datas[index]);
         if (selectedObject == m_Datas[index])
         {
             lit.SetSelected(true);
         }
         else
         {
             lit.SetSelected(false);
         }
         if (lit.GetComponent <Button>() != null && addClickEventList.IndexOf(lit.GetComponent <Button>()) < 0)
         {
             addClickEventList.Add(lit.GetComponent <Button>());
             lit.GetComponent <Button>().onClick.AddListener(
                 delegate(){
                 if (selectedItem != null && selectedItem != item.GetComponent <UILoopItem>())
                 {
                     selectedItem.SetSelected(false);
                 }
                 selectedItem   = item.GetComponent <UILoopItem>();
                 selectedObject = selectedItem.GetData();
                 selectedItem.SetSelected(true);
                 selectedItem.OnSelectedEventHandler();
             }
                 );
         }
     }
 }
示例#3
0
 public void refreshWithoutPosChange()
 {
     for (int i = 0; i < m_InstantiateItems.Count; i++)
     {
         UILoopItem item = m_InstantiateItems[i].GetComponent <UILoopItem>();
         item.Data(item.GetData());
     }
 }
示例#4
0
    private void updateItem(int index, GameObject item)
    {
        item.SetActive(index < m_Datas.Count);

        if (item.activeSelf)
        {
            UILoopItem lit = item.GetComponent <UILoopItem>();
            lit.UpdateItem(index, item);
            lit.Data(m_Datas[index]);
        }
    }
示例#5
0
 /// <summary>
 /// 设置选中对象
 /// </summary>
 /// <param name="selectedIndex"></param>
 public void SetSelectedIndex(int selectedIndex)
 {
     if (m_Datas.Count > 0 && m_Datas.Count > selectedIndex)
     {
         selectedObject = m_Datas[selectedIndex];
         if (selectedItem != null)
         {
             selectedItem.SetSelected(false);
         }
         for (int i = 0; i < m_InstantiateItems.Count; i++)
         {
             if (selectedObject == m_InstantiateItems[i].GetComponent <UILoopItem>().GetData())
             {
                 m_InstantiateItems[i].GetComponent <UILoopItem>().SetSelected(true);
                 selectedItem = m_InstantiateItems[i].GetComponent <UILoopItem>();
             }
         }
     }
 }
示例#6
0
 private void OnSelectedEventHandler(UILoopItem item)
 {
     Debug.LogError("选择的单元数据为:" + item.GetData().ToString());
 }
示例#7
0
    void Update()
    {
        if (isFirst == true)
        {
            isFirst = false;
            return;
        }
        while (scale * DirectionPos - m_PrevPos < -CellScale * 2)
        {
            if (m_PrevPos <= -MaxPrevPos)
            {
                break;
            }
            m_PrevPos -= CellScale;
            List <RectTransform> range = m_InstantiateItems.GetRange(0, PageScale);
            m_InstantiateItems.RemoveRange(0, PageScale);
            m_InstantiateItems.AddRange(range);
            for (int i = 0; i < range.Count; i++)
            {
                moveItemToIndex(m_CurrentIndex * PageScale + m_InstantiateItems.Count + i, range[i]);
            }
            m_CurrentIndex++;
        }
        while (scale * DirectionPos - m_PrevPos > -CellScale)
        {
            if (Mathf.RoundToInt(m_PrevPos) >= 0)
            {
                break;
            }
            m_PrevPos += CellScale;
            m_CurrentIndex--;
            if (m_CurrentIndex < 0)
            {
                break;
            }
            List <RectTransform> range = m_InstantiateItems.GetRange(m_InstantiateItems.Count - PageScale, PageScale);
            m_InstantiateItems.RemoveRange(m_InstantiateItems.Count - PageScale, PageScale);
            m_InstantiateItems.InsertRange(0, range);
            for (int i = 0; i < range.Count; i++)
            {
                moveItemToIndex(m_CurrentIndex * PageScale + i, range[i]);
            }
        }

        if (direction == Direction.Vertical && (offsetY != 0))
        {
            if (scale * DirectionPos != lastPositionY)
            {
                for (int i = 0; i < m_InstantiateItems.Count; i++)
                {
                    UILoopItem item = m_InstantiateItems[i].GetComponent <UILoopItem>();
                    moveItemToIndex(item.itemIndex, m_InstantiateItems[i], true);
                }
                lastPositionY = scale * DirectionPos;
            }
        }

        if (isAutoAlign)
        {
            this.AutoAlign();
        }
    }
示例#8
0
 private void OnSelectedEventHandler(UILoopItem item)
 {
 }
示例#9
0
 private void updateItem(int index, GameObject item)
 {
     item.SetActive(index < m_Datas.Count);
     if(item.activeSelf)
     {
         UILoopItem lit = item.GetComponent<UILoopItem>();
         lit.UpdateItem(index, item);
         lit.Data(m_Datas[index]);
         if (selectedObject == m_Datas[index])
         {
             lit.SetSelected(true);
         }
         else
         {
             lit.SetSelected(false);
         }
         if (lit.GetComponent<Button>() != null && onSelectedEvent != null && addClickEventList.IndexOf(lit.GetComponent<Button>()) < 0)
         {
             addClickEventList.Add(lit.GetComponent<Button>());
             lit.GetComponent<Button>().onClick.AddListener(delegate()
             {
                 if (onSelectedEvent != null)
                 {
                     if (selectedItem != null && selectedItem != item.GetComponent<UILoopItem>())
                     {
                         selectedItem.SetSelected(false);
                     }
                     selectedItem = item.GetComponent<UILoopItem>();
                     selectedObject = selectedItem.GetData();
                     selectedItem.SetSelected(true);
                     onSelectedEvent(selectedItem);
                 }
             });
         }
     }
 }
示例#10
0
 private void Reset()
 {
     for (int i = 0; i < m_InstantiateItems.Count; i++)
     {
         m_InstantiateItems[i].gameObject.SetActive(false);
         m_oldItems.Add(m_InstantiateItems[i]);
     }
     m_InstantiateItems.Clear();
     m_PrevPos = 0;
     m_CurrentIndex = 0;
     selectedObject = null;
     selectedItem = null;
     this.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, 0);
 }
示例#11
0
 /// <summary>
 /// 设置选中对象
 /// </summary>
 /// <param name="selectedIndex"></param>
 public void SetSelectedIndex(int selectedIndex)
 {
     if(m_Datas.Count>0 && m_Datas.Count> selectedIndex)
     {
         selectedObject = m_Datas[selectedIndex];
         if (selectedItem != null)
         {
             selectedItem.SetSelected(false);
         }
         for (int i = 0; i < m_InstantiateItems.Count; i++)
         {
             if (selectedObject == m_InstantiateItems[i].GetComponent<UILoopItem>().GetData())
             {
                 m_InstantiateItems[i].GetComponent<UILoopItem>().SetSelected(true);
                 selectedItem = m_InstantiateItems[i].GetComponent<UILoopItem>();
             }
         }
     }
 }