Exemplo n.º 1
0
 public void AddClick(Action <object> value)
 {
     if (_clickFun != null)
     {
         Debug.LogError("C3DTexture only support one function");
         return;
     }
     EventUtil.AddClick(gameObject, OnClickTexture, "");
     _clickFun = value;
 }
Exemplo n.º 2
0
 public virtual void Reset()
 {
     //            int group = gameObject.GetInstanceID();
     _nowUseList = new List <CButtonToggle>();
     _unUseList  = new List <CButtonToggle>();
     _dic        = new Dictionary <int, CButtonToggle>();
     for (int i = 0; i < transform.childCount; i++)
     {
         CButtonToggle toggle = transform.GetChild(i).GetComponent <CButtonToggle>();
         if (toggle != null)
         {
             //保证回调的index都是初始的时候的index 省的模块那边蛋疼要去动态改变index的判断
             toggle.gameObject.SetData(i);
             EventUtil.AddClick(toggle.gameObject, OnClick, i);
             _nowUseList.Add(toggle);
             _dic[i] = toggle;
         }
     }
     normalSp = _nowUseList.Count != 0 ? _nowUseList[0].normalSprite : "";
 }
Exemplo n.º 3
0
 protected override void OnStart()
 {
     base.OnStart();
     if (Value == -1)
     {
         Value = DefaultValue;
     }
     if (UpBtn != null)
     {
         UpBtn.AddClick(OnClickUpBtn);
         UpBtn.AddMouseDown(OnUpBtnDown);
         UpBtn.AddMouseUp(OnBtnMouseUp);
     }
     if (DownBtn != null)
     {
         DownBtn.AddClick(OnClickDownBtn);
         DownBtn.AddMouseDown(OnDownBtnDown);
         DownBtn.AddMouseUp(OnBtnMouseUp);
     }
     if (btnMax != null)
     {
         btnMax.AddClick(OnClickMaxBtn);
     }
     if (btnMin != null)
     {
         btnMin.AddClick(OnClickMinBtn);
     }
     if (Input != null)
     {
         Input.onChange.Add(new EventDelegate(OnTextChange));
         Input.numOnly = true;
     }
     if (lblMax != null)
     {
         EventUtil.AddClick(lblMax.gameObject, OnLabelMax);
     }
     UIEventListener.Get(Input.gameObject).onSubmit = OnTextSubmit;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 需要改变选项卡的值及其响应时使用
        /// </summary>
        /// <param name="labelStrs">选项卡的字符串列表</param>
        /// <param name="datas">选项卡携带的值,changeIndex时,优先响应携带值,否则响应index</param>
        /// <param name="isHorizon">排布水平,否则垂直排列</param>
        public void UpdateLabels(List <string> labelStrs, List <int> datas = null, bool isHorizon = true)
        {
            this.isHorizon = isHorizon;
            this.datas     = datas;
            this.labelStrs = labelStrs;
            if (!isInit)
            {
                return;
            }
            var           needLen  = labelStrs.Count;
            var           len      = _nowUseList.Count;
            var           count    = Math.Min(needLen, len);
            var           needData = datas != null && datas.Count == labelStrs.Count;
            CButtonToggle box      = null;

            if (len > 1)
            {
                if (isHorizon)
                {
                    dist = (int)(_nowUseList[1].transform.localPosition.x - _nowUseList[0].transform.localPosition.x);
                }
                else
                {
                    dist = (int)(_nowUseList[1].transform.localPosition.y - _nowUseList[0].transform.localPosition.y);
                }
            }
            else if (dist == 0)
            {
                dist = isHorizon ? _nowUseList[0].width : -_nowUseList[0].height;
            }
            for (var i = 0; i < count; i++)
            {
                _nowUseList[i].Text = labelStrs[i];
                if (needData)
                {
                    _nowUseList[i].gameObject.SetData(datas[i]);
                    EventUtil.RemoveClick(_nowUseList[i].gameObject, OnClick);
                    EventUtil.AddClick(_nowUseList[i].gameObject, OnClick, (datas[i]));
                }
            }
            if (len < needLen)
            {
                for (var i = len; i < needLen; i++)
                {
                    if (_unUseList.Count > 0)
                    {
                        box = _unUseList[0];
                        _unUseList.RemoveAt(0);
                        box.Text = labelStrs[i];
                    }
                    else
                    {
                        var boxObj = Instantiate(_nowUseList[0].gameObject) as GameObject;
                        if (boxObj != null)
                        {
                            boxObj.name      = "Tab" + i;
                            box              = boxObj.GetComponent <CButtonToggle>();
                            box.normalSprite = normalSp;
                            box.Text         = labelStrs[i];
                        }
                    }
                    if (box != null)
                    {
                        if (needData)
                        {
                            box.gameObject.SetData(datas[i]);
                        }
                        box.transform.parent = transform;
                        if (_nowUseList.Count > 0)
                        {
                            if (isHorizon)
                            {
                                box.transform.localPosition = new Vector2(_nowUseList[0].transform.localPosition.x + dist * i,
                                                                          _nowUseList[0].transform.localPosition.y);
                            }
                            else
                            {
                                box.transform.localPosition = new Vector2(_nowUseList[0].transform.localPosition.x,
                                                                          _nowUseList[0].transform.localPosition.y + dist * i);
                            }
                        }
                        else
                        {
                            box.transform.localPosition = Vector2.zero;
                        }
                        box.transform.localScale = Vector2.one;
                        box.gameObject.SetActive(true);
                        if (needData)
                        {
                            EventUtil.RemoveClick(box.gameObject, OnClick);
                            EventUtil.AddClick(box.gameObject, OnClick, (datas[i]));
                        }
                        _nowUseList.Add(box);
                    }
                }
            }
            else
            {
                for (var i = 0; i < len; i++)
                {
                    box = _nowUseList[i];
                    box.gameObject.SetActive(true);
                }
                for (var i = len - 1; i >= needLen; i--)
                {
                    box = _nowUseList[i];
                    box.gameObject.SetActive(false);
                    _nowUseList.RemoveAt(i);
                    //_unUseList.Add(box);
                    _unUseList.Insert(0, box);
                }
            }
        }
Exemplo n.º 5
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();
        }