Example #1
0
        public FGroup(Vector2 nextPos, T obj, int count = 0, int xNum = -1, Action <int, T> callBack = null, int dpNum = 0)
        {
            GLayPosition pos = null;

            if (nextPos.x != 0 || nextPos.y != 0)
            {
                pos = GLayPosition.Create(nextPos.x, nextPos.y, xNum);
            }
            Init(obj, pos, callBack);
            if (count != 0)
            {
                Refurbish(count);
            }
        }
Example #2
0
        //autolen,自动控制,TempObject锚点必须置顶,

        public void Init(Func <int, CircleData, bool> callEvent, int num, bool autoLen = true, bool isLoop = false)
        {
            mLoop = isLoop;
            if (mLoop)
            {
                this.GetComponent <ScrollRect>().movementType = ScrollRect.MovementType.Unrestricted;
                autoLen   = false;
                mIsCircle = true;
            }

            mAutoLen = autoLen;
            mSize    = new Vector2(Mathf.Abs(mSize.x), Math.Abs(mSize.y) * -1);

            mCallEvent = callEvent;
            if (mIsCircle)
            {
                mChangeCallFun = ChangeItemEx;
            }
            else
            {
                mChangeCallFun = mAsyncChange;
            }
            mScrollRect = this.gameObject.GetComponent <ScrollRect>();
            if (mContent == null)
            {
                mContent   = mScrollRect.content;
                mContenPos = mContent.transform.position;
                mTempPos   = TempObject.transform.position;
                //锚点置顶,防止拖动范围变大时,位置发生变化
                var tempRect = TempObject.GetComponent <RectTransform>();
                tempRect.anchorMin            = new Vector2(0, 1);
                tempRect.anchorMax            = new Vector2(0, 1);
                TempObject.transform.position = mTempPos;
            }
            else
            {
                mContent.transform.position          = mContenPos;
                mTempObject[0].go.transform.position = mTempPos;
            }

            mIndexPacge = 0;
            if (mScrollRect != null)
            {
                isVertical = mScrollRect.vertical;
            }
            else
            {
                Debug.LogError("未找到ScrollRect");
            }

            SetIntNum(num);

            if (TempObject != null)
            {
                /*
                 * List<Transform> tempGos = new List<Transform>();
                 * if (mTempObject.Count == 0)
                 * {
                 *  tempGos.Add(TempObject);
                 *  //mTempObject.Add(new CircleData() { go = TempObject.gameObject });
                 * }
                 * else
                 * {
                 *  for (int j = 0; j < mTempObject.Count; j++)
                 *  {
                 *      tempGos.Add(mTempObject[j].go.transform);
                 *  }
                 * }
                 */

                if (mGroupTransform == null)
                {
                    mGroupTransform = new FGroup <Transform>();
                    if (string.IsNullOrEmpty(ResName))
                    {
                        mGroupTransform.Init(TempObject, GLayPosition.Create(mSize.x, mSize.y, WidthCount));
                    }
                    else
                    {
                        mGroupTransform.Init(ResName, TempObject.gameObject, GLayPosition.Create(mSize.x, mSize.y, WidthCount));
                    }
                }
                mGroupTransform.Refurbish(WidthCount * HightCount);
                //SceneManager.CloneObjectList(mSize, tempGos, WidthCount * HightCount, WidthCount);
                int maxCount = isVertical ? HightCount : WidthCount;
                mIndexs.Clear();
                mBuffs.Clear();
                for (int i = 0; i < maxCount; i++)
                {
                    mBuffs[i] = new List <CircleData>();
                    mIndexs.Add(i);
                }

                int allNum = WidthCount * HightCount;
                for (int i = 0; i < allNum; i++)
                {
                    //mTempObject[i].name = i.ToString();
                    CircleData cd = null;
                    if (mTempObject.Count > i)
                    {
                        cd = mTempObject[i];
                    }
                    else
                    {
                        cd    = new CircleData();
                        cd.go = mGroupTransform[i].gameObject;
                        mTempObject.Add(cd);
                    }
                    if (isVertical)
                    {
                        mBuffs[i / WidthCount].Add(cd);
                    }
                    else
                    {
                        mBuffs[i % WidthCount].Add(cd);
                    }
                    if (!SentEvent(mTempObject[i], i))
                    {
                        mTempObject[i].go.SetActive(false);
                    }
                }


                mStartPos = mTempObject[0].go.transform.position;
                mEndPos   = mTempObject[allNum - 1].go.transform.position;

                mWorldSzie = (mEndPos - mStartPos);
                mDatilSize = mSize;
                if (isVertical)
                {
                    mWorldSzie.y  = mWorldSzie.y / (HightCount - 1);
                    mWorldSzie.x  = 0;
                    mDatilSize.x  = 0;
                    mDatilSize.y *= -1;
                }
                else
                {
                    mWorldSzie.x = mWorldSzie.x / (WidthCount - 1);
                    mWorldSzie.y = 0;
                    mDatilSize.y = 0;
                }

                mEndPos    = mStartPos;
                mStartPos -= mWorldSzie * 3.0f;
                mEndPos   -= (mWorldSzie / 2.0f);
            }
        }