Ejemplo n.º 1
0
 public override void Reset()
 {
     base.Reset();
     if (_nowUseList != null && _nowUseList.Count > 0)
     {
         tweenState     = new Dictionary <CButtonToggle, bool>();
         tweenTargetPos = new Dictionary <CButtonToggle, int>();
         foreach (var tog in _nowUseList)
         {
             if (moveOnOver)
             {
                 EventUtil.AddHover(tog.gameObject, OnTogHover, tog);
             }
             tweenState[tog]     = false;
             tweenTargetPos[tog] = 0;
         }
         if (side == TabBarTweenSide.UP || side == TabBarTweenSide.DOWN)
         {
             startPos = _nowUseList[0].transform.localPosition.y;
         }
         else
         {
             startPos = _nowUseList[0].transform.localPosition.x;
         }
     }
 }
Ejemplo n.º 2
0
        private void ResetItems()
        {
            CItemRender item;

            for (int i = 0; i < _allItem.Count; i++)
            {
                item      = _allItem[i];
                item.name = "Item" + i;
                CItemRender w = item;
                if (_dataCondition != null)
                {
                    w.SetCondition(_dataCondition);
                }
                w.Data = _dataProvider[i];

                float itemX, itemY;
                //一列一列的顺序?
                itemY = content.baseClipRegion.w / 2 + content.baseClipRegion.y + offY;
                itemX = i * itemWidth;
                item.tran.localPosition = new Vector3(itemX, itemY, 0);
                List <BoxCollider> boxList = DisplayUtil.GetComponentByType <BoxCollider>(item.go);
                for (int n = 0, len = boxList.Count; n < len; n++)
                {
                    EventUtil.AddHover(boxList[n].gameObject, OnHover, item);
                }
            }
        }
Ejemplo n.º 3
0
 new public void AddItem(CButtonToggle tog)
 {
     base.AddItem(tog);
     tweenState[tog]     = false;
     tweenTargetPos[tog] = 0;
     if (moveOnOver)
     {
         EventUtil.AddHover(tog.gameObject, OnTogHover, tog.gameObject);
     }
 }
Ejemplo n.º 4
0
    void LoadGameOBject(int level, GameObject parent)
    {
        string name       = "LiujieXiangYaoCailiao/level/level" + level.ToString();
        Object gameobject = Resources.Load(name);

        this.gamelevel = GameObject.Instantiate(gameobject) as GameObject;



        this.levelsprite = gamelevel.GetComponentInChildren <UISprite>();
        levelsprite.transform.SetParent(parent.transform);

        UISprite[] spritelist = gamelevel.GetComponentsInChildren <UISprite>();
        foreach (UISprite s in spritelist)
        {
            if (s.name == "block")
            {
                this.myblock = s;
            }
        }


        CButton button = gamelevel.GetComponentInChildren <CButton>();

        button.AddMouseDown(ChangeSize);
        button.AddRollOver(ChangeSize);
        EventUtil.AddHover(button.gameObject, delegate(object obj, bool isHover){
            GameObject tobj = obj as GameObject;


            if (isHover)
            {
                tobj.transform.localScale = new Vector3(1.2F, 1.2F, 0);
                this.myblock.gameObject.SetActive(false);
            }
            else
            {
                tobj.transform.localScale = new Vector3(1F, 1F, 0);
                this.myblock.gameObject.SetActive(true);
            }
        });
    }
Ejemplo n.º 5
0
        public virtual void ResetItems()
        {
            CTreeNode branchItem;

            TotalHeight = 0;
            if (_branchUsedList == null)
            {
                return;
            }
            for (int i = 0; i < _dataProvider.Count; i++)
            {
                branchItem      = _branchUsedList[i];
                branchItem.name = "Item" + i;
                branchItem.data = _dataProvider[i];

                float itemY;
                itemY = -TotalHeight;
                branchItem.tran.localPosition = new Vector3(0, itemY, 0);
                EventUtil.AddHover(branchItem.go, OnItemHover);
                EventUtil.AddPress(branchItem.go, OnItemHover);
                UIEventListener listener = UIEventListener.Get(branchItem.go);
                listener.onHover = OnItemHover;
                listener.onPress = OnItemPress;
                TotalHeight     += branchHeight + branchGapU;
                CheckOpenAndResetChilde(branchItem);
            }

            //spSelected.gameObject.SetActive(!clearAllLeaf);

            CalculateHeight(TotalHeight);
            int barWidth = 0;

            if (Bar.gameObject.activeSelf == true)
            {
                barWidth = Bar.width;
            }
            Overlay.width          = this.width - barWidth;
            spSelected.width       = this.width - barWidth;
            Content.baseClipRegion = new Vector4((this.width - barWidth) / 2, -this.height / 2, this.width - barWidth, this.height);
        }
Ejemplo n.º 6
0
        protected virtual void ResetItems()
        {
            CTreeNode branchItem;

            TotalHeight = 0;
            bool clearAllLeaf = true;
            int  chlidLen     = 0;

            if (_branchUsedList == null)
            {
                return;
            }
            for (int i = 0; i < _branchUsedList.Count; i++)
            {
                branchItem      = _branchUsedList[i];
                branchItem.name = "Item" + i;
                branchItem.data = _dataProvider[i];

                float itemY;
                itemY = -TotalHeight;
                branchItem.tran.localPosition = new Vector3(0, itemY, 0);
                EventUtil.AddHover(branchItem.go, OnItemHover);
                EventUtil.AddPress(branchItem.go, OnItemHover);
                UIEventListener listener = UIEventListener.Get(branchItem.go);
                listener.onHover = OnItemHover;
                listener.onPress = OnItemPress;
                TotalHeight     += branchHeight + branchGapU;
                if (branchItem.isOpen)
                {
                    int startIndex = chlidLen;
                    if (branchItem.data.child != null)
                    {
                        chlidLen += branchItem.data.child.Count;
                    }
                    if (chlidLen > 0)
                    {
                        clearAllLeaf = false;
                    }
                    for (int n = 0; (n + startIndex) < chlidLen; n++)
                    {
                        CTreeNode child;
                        if ((n + startIndex) < _leafUsedList.Count)
                        {
                            child = _leafUsedList[n + startIndex];
                        }
                        else
                        {
                            child = GetLeaf();
                        }
                        child.name = "Item" + i;
                        child.SetParent(Content.transform);
                        child.SetActive(true);
                        child.data = branchItem.data.child[n];

                        float childY;
                        childY = -TotalHeight;
                        child.tran.localPosition = new Vector3(0, childY, 0);

                        UIEventListener childListener = UIEventListener.Get(child.go);
                        childListener.onHover = OnItemHover;
                        childListener.onPress = OnItemPress;
                        TotalHeight          += _leafHeight + leafGapU;
                    }
                }
            }

            if (chlidLen < _leafUsedList.Count)
            {
                for (int j = _leafUsedList.Count - 1; j >= chlidLen; j--)
                {
                    CTreeNode temp = _leafUsedList[j];
                    temp.SetParent(Recycle);
                    _leafPool.Add(temp);
                    _leafUsedList.Remove(temp);
                }
            }
            if (clearAllLeaf)
            {
                for (int j = _leafUsedList.Count - 1; j >= 0; j--)
                {
                    CTreeNode temp = _leafUsedList[j];
                    temp.SetParent(Recycle);
                    _leafPool.Add(temp);
                    _leafUsedList.Remove(temp);
                }
            }
            spSelected.gameObject.SetActive(!clearAllLeaf);
            //if (_dataProvider == null) {
            //    TotalHeight = 0;
            //} else {
            //    float itemH = _branchHeight * _dataProvider.Count / float.Parse(ColNum.ToString());
            //        TotalHeight = PaddingTop + Mathf.CeilToInt(itemH) + PaddingBottom;
            //}

            //Bar.gameObject.SetActive(TotalHeight > height);
            //if (Bar.gameObject.activeSelf == true) {
            //    Bar.BarSize = (float)this.height / TotalHeight;
            //}
            CalculateHeight(TotalHeight);
            int barWidth = 0;

            if (Bar.gameObject.activeSelf == true)
            {
                barWidth = Bar.width;
            }
            Overlay.width          = this.width - barWidth;
            spSelected.width       = this.width - barWidth;
            Content.baseClipRegion = new Vector4((this.width - barWidth) / 2, -this.height / 2, this.width - barWidth, this.height);
        }
Ejemplo n.º 7
0
        protected override void ResetItems()
        {
            CItemRender item;
            bool        isSameHeight    = true;
            float       realTotalHeight = 0;

            for (int i = 0; i < _allItem.Count; i++)
            {
                item      = _allItem[i];
                item.name = "Item" + i;
                CItemRender w = item;
                if (_dataCondition != null)
                {
                    w.SetCondition(_dataCondition);
                }
                w.Data = _dataProvider[i];
                //默认为itemHeight(等高情况)
                //不等高情况,请自行设置CItemRender的height属性
                float realItemHeight = 0;
                if (w.height == 0)
                {
                    realItemHeight = _itemHeight;
                }
                else
                {
                    realItemHeight = w.height;
                    isSameHeight   = false;
                }
                int   offX = i / RowNum;
                int   offY = i / ColNum;
                float itemX, itemY;
                if (horizon)
                {
                    itemY = -(itemHeight + 5) * (i % RowNum);  //一列一列的顺序?
                    itemX = offX * itemWidth;
                }
                else
                {
                    if (isSameHeight)
                    {
                        itemY = (offY * _itemHeight * -1);
                    }
                    else
                    {
                        itemY = (realTotalHeight * -1);
                    }
                    itemX = (itemWidth + 5) * (i % ColNum);
                }
                item.tran.localPosition = new Vector3(PaddingLeft + itemX, -PaddingTop + itemY, 0);

                realTotalHeight += realItemHeight;

                UIEventListener listener = UIEventListener.Get(item.go);
                //listener.onHover = OnItemHover;
                EventUtil.AddHover(item.go, OnItemHover, item.go);
                listener.onClick = OnItemPress;
            }
            if (_dataProvider == null)
            {
                TotalWidth  = 0;
                TotalHeight = 0;
            }
            else
            {
                if (horizon)
                {
                    var itemW = _itemWidth * _dataProvider.Count / (float)RowNum;
                    TotalWidth = PaddingLeft * 2 + Mathf.CeilToInt(itemW);
                }
                else
                {
                    float itemH = 0;
                    if (isSameHeight)
                    {
                        itemH = _itemHeight * _dataProvider.Count / float.Parse(ColNum.ToString());
                    }
                    else
                    {
                        itemH = realTotalHeight;
                    }
                    TotalHeight = PaddingTop + Mathf.CeilToInt(itemH) + PaddingBottom;
                }
            }
            if (keepCurPos == false)
            {
                UpdateScrollBar();
            }
            else
            {
                if (ShowBar)
                {
                    bool needShowBar = TotalHeight > height || TotalWidth > width;
                    Bar.gameObject.SetActive(needShowBar);
                }
                else
                {
                    Bar.gameObject.SetActive(false);
                }
            }
        }
Ejemplo n.º 8
0
        public void SetDataProvider <T>(IEnumerable <T> value)
        {
            if (_itemRender == null)
            {
                Debug.LogError("set itemRender first!");
                return;
            }
            if (_itemPool == null)
            {
                _itemPool = new List <CItemRender>();
            }
            if (_allItem == null)
            {
                _allItem = new List <CItemRender>();
                btnLeft.AddClick(ScrollPre);
                btnRight.AddClick(ScrollNext);
            }
            SetData <T>(value);
            //_dataProvider = (value ?? new List<T>()) as List<object>;

            bool        isEnough = _allItem.Count >= _dataProvider.Count;
            int         n        = Mathf.Abs(_allItem.Count - _dataProvider.Count);
            CItemRender item;

            while (n > 0)
            {
                if (isEnough == true)
                {
                    item = _allItem[_allItem.Count - 1];
                    _itemPool.Add(item);
                    _allItem.RemoveAt(_allItem.Count - 1);
                    item.SetParent(recycle);
                    item.tran.localPosition = Vector3.zero;
                    item.SetActive(false);
                }
                else
                {
                    if (_itemPool.Count > 0)
                    {
                        item = _itemPool[0];
                        _itemPool.RemoveAt(0);
                        item.SetActive(true);
                    }
                    else
                    {
                        item = (CItemRender)Activator.CreateInstance(_itemRender);
                        EventUtil.AddHover(item, OnHover);
                        //item.width = itemWidth;
                    }
                    item.SetParent(_content.transform);
                    _allItem.Add(item);
                }
                n--;
            }
            ResetItems();
            lastDataProvider = value;
            lastMainItem     = _allItem[mainIndex];
            oriSizeX         = _allItem[mainIndex].width;
            oriSizeY         = _allItem[mainIndex].height;
            SetMainItemRender(lastMainItem, false);
        }
Ejemplo n.º 9
0
        protected virtual void ResetItems()
        {
            CItemRender item;

            for (int i = 0; i < _allItem.Count; i++)
            {
                item      = _allItem[i];
                item.name = "Item" + i;
                CItemRender w = item;
                if (item.IsActive() == false)
                {
                    item.SetActive(true);
                }
                w.SetAlpha(1);
                if (_dataCondition != null)
                {
                    w.SetCondition(_dataCondition);
                }
                w.index = i + preIndex;
                w.Data  = _dataProvider[i];
                int   offX = i / RowNum;
                int   offY = i / ColNum;
                float itemX, itemY;
                if (_horizon)
                {
                    itemY = -(itemHeight + gapV) * (i % RowNum); //一列一列的顺序?
                    itemX = offX * (itemWidth + gapU);
                }
                else
                {
                    itemY = (offY * (_itemHeight * item.localScale.y + gapV) * -1);
                    itemX = (itemWidth + gapU) * (i % ColNum);
                }
                item.tran.localPosition = new Vector3(PaddingLeft + itemX, -PaddingTop + itemY, 0);

                //                UIEventListener listener = UIEventListener.Get(item.go);
                UIEventListener.Get(item.go);
                //listener.onHover = OnItemHover;
                if (IsAddItemEvent == true)
                {
                    EventUtil.AddHover(item.go, OnItemHover, item.go);
                    EventUtil.AddDoubleClick(item.go, OnDoubleClickItem, item);
                    EventUtil.AddClick(item.go, OnItemPress, item.go);
                }
                else
                {
                    EventUtil.RemoveHover(item.go, OnItemHover);
                    EventUtil.RemoveDoubleClick(item.go, OnDoubleClickItem);
                    EventUtil.RemoveClick(item.go, OnItemPress);
                }
            }
            if (_dataProvider == null)
            {
                TotalWidth  = 0;
                TotalHeight = 0;
            }
            else
            {
                if (_horizon)
                {
                    var itemW = (_itemWidth + gapU) * Mathf.CeilToInt(_dataProvider.Count / (float)RowNum) - gapU;
                    TotalWidth = PaddingLeft * 2 + itemW;
                }
                else
                {
                    var itemH = (_itemHeight + gapV) * Mathf.CeilToInt(_dataProvider.Count / (float)ColNum) - gapV;
                    TotalHeight = PaddingTop + itemH + PaddingBottom;
                }
            }
            UpdateScrollBar();
        }