Exemplo n.º 1
0
 private void SetObject(S2DragPanelObject obj)
 {
     if (obj.ObjectIndex < TotalCount)
     {
         obj.gameObject.SetActive(true);
         obj.Set();
     }
     else
     {
         obj.gameObject.SetActive(false);
     }
 }
Exemplo n.º 2
0
    public void Init <T>(Action <int, T> initObject, Action <int, T> setObject)
    {
        _panel        = GetComponent <UIPanel>();
        _scrollView   = GetComponent <UIScrollView>();
        _initPanelPos = transform.localPosition;
        if (objectsParent == null)
        {
            objectsParent = gameObject;
        }

        if (_panel == null || _scrollView == null)
        {
            throw new Exception("S2DragPanel: UIPanel or UIScrollView is null");
        }

        _movement = _scrollView.movement;
        InitX     = initX;
        InitY     = initY;
        GapX      = gapX;
        GapY      = gapY;
        float startPos = CalculateInitPosAndGap();

        float gap    = Mathf.Abs(_gap);
        float finalP = startPos + _length + 3.5f * gap;

        if (countInLine == 0)
        {
            throw new Exception("S2DragPanel: countInLine must not be zero");
        }
        if (gap == 0)
        {
            throw new Exception("S2DragPanel: gap must not be zero");
        }

        int lineCount = (int)((finalP - startPos) / gap);

        if (lineCount >= 999)
        {
            throw new Exception("S2DragPanel: gap is too small");
        }
        _objectList = new List <S2DragPanelObject[]>(lineCount);
        AllObjects  = new S2DragPanelObject[lineCount * countInLine];

        int index = 0;

        for (int i = 0; i < lineCount; i++)
        {
            var newLine = new S2DragPanelObject[countInLine];
            for (int k = 0; k < countInLine; k++)
            {
                var baseObj = NGUITools.AddChild(objectsParent, dragObjectPref);
                S2DragPanelObject <T> obj = new S2DragPanelObject <T>();
                obj.Init(baseObj, _panel, index, initObject, setObject);
                _setPosition(obj);
                newLine[k]        = obj;
                AllObjects[index] = obj;
                index++;
            }
            _objectList.Add(newLine);
        }

/*
 *      while (_p < finalP && index < 1000)
 *      {
 *          var newLine = new S2DragPanelObject[countInLine];
 *          for (int k = 0; k < countInLine; k++)
 *          {
 *              var baseObj = NGUITools.AddChild(objectsParent, dragObjectPref);
 *              S2DragPanelObject<T> obj = new S2DragPanelObject<T>();
 *              obj.Init(baseObj, _panel, index, initObject, setObject);
 *              _setPosition(obj);
 *              newLine[k] = obj;
 *              ObjectList.Add(obj);
 *              index++;
 *          }
 *          _objectList.Add(newLine);
 *          _p += gap;
 *      }
 *      if (index >= 999)
 *      {
 *          throw new Exception("S2DragPanel: gap is too small");
 *      }
 */
        if (AllObjects.Length == 0)
        {
            throw new Exception("S2DragPanel: Object is not exist");
        }
        _isEnable = true;
    }
Exemplo n.º 3
0
    private void SetHorizontalPanelPosition(S2DragPanelObject obj)
    {
        int index = obj.ObjectIndex;

        obj.transform.localPosition = new Vector3(InitX + GapX * (index / countInLine), InitY - GapY * (index % countInLine));
    }