Example #1
0
        public FGroup <T> Create <T>(string resName, GameObject parent, FGroupTool tool = null, Action <int, T> call = null) where T : Component
        {
            var g = new FGroup <T>();

            g.Init(resName, parent, tool, call);
            mPools.Add(g);
            return(g);
        }
Example #2
0
        protected override void Init()
        {
            DontDestroyOnLoad(this.gameObject);
            mMainPlane = this.GetComponent <FCUniversalPanel>();
            mUICamera  = mMainPlane.GetFObject <Camera>("F_Camera");
            mLowPlane  = mMainPlane.GetFObject <RectTransform>("F_LowPlane");
            mLowPlane.gameObject.SetActive(false);
            HigPlane = mMainPlane.GetFObject <RectTransform>("F_HigPlane");
            HigPlane.gameObject.SetActive(false);
            RectTransform rt = mMainPlane.GetFObject <RectTransform>("F_Plane");

            mOtherPlane = new FGroup <RectTransform>();
            mOtherPlane.Init(rt, (i, t) =>
            {
                t.name = ((LayerType)i).ToString();
                t.anchoredPosition3D = Vector3.zero;
                t.sizeDelta          = Vector3.zero;
                t.gameObject.SetActive(false);
            });
            mOtherPlane.Refurbish((int)LayerType.LT_Hig);
            mUIPlane = mOtherPlane[(int)LayerType.LT_Normal];
        }
Example #3
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);
            }
        }
Example #4
0
        private void SetStart(int count, int startGroup = 0)
        {
            mScrollRect = this.gameObject.GetComponent <ScrollRect>();
            if (mScrollRect != null)
            {
                if (mContent == null)
                {
                    //初始化
                    mContent = mScrollRect.content;

                    if (mComponent == null)
                    {
                        mComponent = mContent.GetChild(0);
                    }
                    mStartContenPos = mContent.transform.localPosition;
                    mStartItemPos   = mComponent.transform.position;
                    //锚点置顶,防止拖动范围变大时,位置发生变化
                    var tempRect = mComponent.GetComponent <RectTransform>();
                    tempRect.anchorMin            = new Vector2(0, 1);
                    tempRect.anchorMax            = new Vector2(0, 1);
                    mComponent.transform.position = mStartItemPos;
                    mStartItemPos = mComponent.transform.localPosition;
                    m_Rect        = new Vector2(tempRect.sizeDelta.x, tempRect.sizeDelta.y);

                    var tempScroll = mScrollRect.GetComponent <RectTransform>();
                    m_CenterPosion = Vector3.zero;
                    m_IsVertical   = mScrollRect.vertical;
                    mGroups        = new FGroup <Transform>();
                    mGroups.Init(mComponent.transform);
                    var tempPos = mContent.transform.position;
                    tempPos = mScrollRect.transform.InverseTransformPoint(tempPos);
                    if (m_IsVertical)
                    {
                        m_SpaceDis       = m_Rect.y;
                        m_GroupDis       = m_Rect.x;
                        m_CenterPosion.x = tempPos.x;
                    }
                    else
                    {
                        m_SpaceDis       = m_Rect.x;
                        m_GroupDis       = m_Rect.y;
                        m_CenterPosion.y = tempPos.y;
                    }

                    if (m_IsCenter)
                    {
                        var offset = mScrollRect.transform.TransformPoint(m_CenterPosion);
                        offset = mContent.transform.InverseTransformPoint(offset);
                        m_DefaultCenterOffset = (m_IsVertical ? (offset.y - mStartItemPos.y) : (offset.x - mStartItemPos.x));
                    }

                    m_GLayPosition = FGLayPosition.Create(m_SpaceDis, m_IsVertical, m_GroupNum, m_GroupDis);
                    m_GLayPosition.SetStart(mStartItemPos);

                    if (mModeType == ScrollType.Repeat)
                    {
                        m_UpdateFun = UpdateRepeat;
                    }
                    else if (mModeType == ScrollType.Asy)
                    {
                        m_UpdateFun = UpdateAsy;
                    }
                    else if (mModeType == ScrollType.Circle)
                    {
                        m_UpdateFun = UpdateCircle;
                        mScrollRect.movementType = ScrollRect.MovementType.Unrestricted;
                    }
                    else
                    {
                        m_UpdateFun = UpdateNull;
                    }
                }
                else
                {
                    //复位
                    mContent.transform.localPosition = mStartContenPos;
                }
                m_LastIndex       = -99999;//重置
                m_LastCenterGroup = -99999;
                //配置滑动长度
                var       scrollTransform = mScrollRect.GetComponent <RectTransform>();
                Vector3[] sizeVector3     = new Vector3[4];
                scrollTransform.GetLocalCorners(sizeVector3);
                float sizeX = Mathf.Abs(sizeVector3[0].x - sizeVector3[2].x);
                float sizeY = Mathf.Abs(sizeVector3[0].y - sizeVector3[2].y);

                if (m_IsVertical)
                {
                    if (m_CacheLine <= 1)
                    {
                        SetCache(Mathf.Clamp((int)(sizeY / m_SpaceDis) + 2, 4, 999999));
                    }
                    mContent.sizeDelta = new Vector2(mContent.sizeDelta.x, m_SpaceDis * (1 + (count - 1) / m_GroupNum) + m_SpaceOffset);
                }
                else
                {
                    if (m_CacheLine <= 1)
                    {
                        SetCache(Mathf.Clamp((int)(sizeX / m_SpaceDis) + 2, 4, 999999));
                    }
                    mContent.sizeDelta = new Vector2(m_SpaceOffset + m_SpaceDis * (1 + (count - 1) / m_GroupNum), mContent.sizeDelta.y);
                }
                m_ActionNum = m_GroupNum * m_CacheLine;
                int rNum = mModeType == ScrollType.Circle ? m_ActionNum : Mathf.Min(m_ActionNum, count);
                mGroups.Refurbish(rNum);
                mItems.Clear();
                foreach (var k in mGroups)
                {
                    ScrollItem sItem = new ScrollItem(k.gameObject);
                    mItems.Add(sItem);
                }
                m_MaxNum  = count;
                m_MaxLine = 1 + (count - 1) / m_GroupNum;
                SelectGroup(startGroup);
                if (m_ScrollEx != null)
                {
                    m_ScrollEx.Init(this);
                }
            }
            else
            {
                Debug.LogError("ScrollRect未找到");
            }
        }