Пример #1
0
        protected void _Create(EleBaseRect parent, ScrollInfo scrollInfo, Vector2 size)
        {
            this.minSize = size;

            GameObject go = new GameObject("Slider_" + name);

            go.transform.SetParent(parent.GetContentRect(), false);
            //
            this.plate        = go.AddComponent <UnityEngine.UI.Image>();
            this.plate.type   = UnityEngine.UI.Image.Type.Sliced;
            this.plate.sprite = scrollInfo.backplateSprite;
            //
            this.slider = go.AddComponent <SldTy>();
            this.plate.RTQ().TopLeftAnchorsPivot();

            GameObject slideRegion = new GameObject("Slidergn_" + name);

            slideRegion.transform.SetParent(go.transform, false);
            RectTransform rtSliderRegion = slideRegion.AddComponent <RectTransform>();

            rtSliderRegion.RTQ().ExpandParentFlush().
            OffsetMin(scrollInfo.scrollbarDim * 0.5f, 0.0f).
            OffsetMax(-scrollInfo.scrollbarDim * 0.5f, 0.0f);

            GameObject goThumb = new GameObject("Thumb_" + name);

            goThumb.transform.SetParent(slideRegion.transform, false);
            //
            this.thumb      = goThumb.AddComponent <UnityEngine.UI.Image>();
            this.thumb.type = UnityEngine.UI.Image.Type.Sliced;
            //
            this.thumb.RTQ().CenterPivot().SizeDelta(scrollInfo.scrollbarDim, 0.0f);

            this.slider.targetGraphic = this.thumb;
            this.slider.handleRect    = this.thumb.rectTransform;

            scrollInfo.Apply(this.slider, this.thumb);
        }
Пример #2
0
        protected void _Create(
            EleBaseRect parent,
            ScrollInfo horiz,
            ScrollInfo vert,
            bool showBack,
            Vector2 size,
            float sensitivity,
            string name = "")
        {
            //      SCROLL ITEMS
            ////////////////////////////////////////////////////////////////////////////////
            GameObject go = new GameObject("ScrollRgn_" + name);

            go.transform.SetParent(parent.GetContentRect(), false);
            RectTransform rt = go.AddComponent <RectTransform>();

            rt.anchorMin = new Vector2(0.0f, 1.0f);
            rt.anchorMax = new Vector2(0.0f, 1.0f);
            rt.pivot     = new Vector2(0.0f, 1.0f);

            GameObject goViewport = new GameObject("Viewport_" + name);

            goViewport.transform.SetParent(go.transform, false);
            UnityEngine.UI.Image imgViewport = goViewport.AddComponent <UnityEngine.UI.Image>();
            RectTransform        rtViewport  = imgViewport.rectTransform;

            rtViewport.anchorMin = new Vector2(0.0f, 0.0f);
            rtViewport.anchorMax = new Vector2(1.0f, 1.0f);
            rtViewport.pivot     = new Vector2(0.0f, 1.0f);
            rtViewport.offsetMin = new Vector2(0.0f, 0.0f);
            rtViewport.offsetMax = new Vector2(0.0f, 0.0f);

            UnityEngine.UI.Mask maskViewport = goViewport.AddComponent <UnityEngine.UI.Mask>();
            maskViewport.showMaskGraphic = showBack;

            GameObject goContent = new GameObject("Content_" + name);

            goContent.transform.SetParent(goViewport.transform, false);
            RectTransform rtContent = goContent.AddComponent <RectTransform>();

            //
            //      VERTICAL SCROLLBAR
            ////////////////////////////////////////////////////////////////////////////////
            GameObject goScrollVert = new GameObject("ScrollVert_" + name);

            goScrollVert.transform.SetParent(go.transform, false);
            UnityEngine.UI.Image imgScrollVert = goScrollVert.AddComponent <UnityEngine.UI.Image>();
            RectTransform        rtScrollVert  = imgScrollVert.rectTransform;

            rtScrollVert.pivot            = new Vector2(0.0f, 1.0f);
            rtScrollVert.anchorMin        = new Vector2(1.0f, 0.0f);
            rtScrollVert.anchorMax        = new Vector2(1.0f, 1.0f);
            rtScrollVert.anchoredPosition = new Vector2(-vert.scrollbarDim, 0.0f);
            rtScrollVert.sizeDelta        = new Vector2(vert.scrollbarDim, 0.0f);
            imgScrollVert.sprite          = vert.backplateSprite;
            imgScrollVert.type            = UnityEngine.UI.Image.Type.Sliced;

            GameObject goThumbVert = new GameObject("ThumbVert_" + name);

            goThumbVert.transform.SetParent(goScrollVert.transform, false);
            UnityEngine.UI.Image imgThumbVert = goThumbVert.AddComponent <UnityEngine.UI.Image>();
            RectTransform        rtThumbVert  = imgThumbVert.rectTransform;

            rtThumbVert.pivot            = new Vector2(1.0f, 1.0f);
            rtThumbVert.anchorMin        = new Vector2(0.0f, 0.0f);
            rtThumbVert.anchorMax        = new Vector2(1.0f, 1.0f);
            rtThumbVert.anchoredPosition = new Vector2(0.0f, 0.0f);
            rtThumbVert.sizeDelta        = new Vector2(0.0f, 0.0f);

            ScrollTy sbVert = goScrollVert.AddComponent <ScrollTy>();

            sbVert.direction     = UnityEngine.UI.Scrollbar.Direction.BottomToTop;
            sbVert.targetGraphic = imgThumbVert;
            sbVert.handleRect    = rtThumbVert;
            vert.Apply(sbVert, imgThumbVert);

            //
            //      HORIZONTAL SCROLLBAR
            ////////////////////////////////////////////////////////////////////////////////
            GameObject goScrollHoriz = new GameObject("ScrollHoriz_" + name);

            goScrollHoriz.transform.SetParent(go.transform, false);
            UnityEngine.UI.Image imgScrollHoriz = goScrollHoriz.AddComponent <UnityEngine.UI.Image>();
            RectTransform        rtScrollHoriz  = imgScrollHoriz.rectTransform;

            rtScrollHoriz.pivot     = new Vector2(0.0f, 0.0f);
            rtScrollHoriz.anchorMin = new Vector2(0.0f, 0.0f);
            rtScrollHoriz.anchorMax = new Vector2(1.0f, 0.0f);
            rtScrollHoriz.sizeDelta = new Vector2(0.0f, horiz.scrollbarDim);
            imgScrollHoriz.sprite   = horiz.backplateSprite;
            imgScrollHoriz.type     = UnityEngine.UI.Image.Type.Sliced;

            GameObject goThumbHoriz = new GameObject("ThumbHoriz_" + name);

            goThumbHoriz.transform.SetParent(goScrollHoriz.transform, false);
            UnityEngine.UI.Image imgThumbHoriz = goThumbHoriz.AddComponent <UnityEngine.UI.Image>();
            RectTransform        rtThumbHoriz  = imgThumbHoriz.rectTransform;

            rtThumbHoriz.pivot            = new Vector2(0.0f, 1.0f);
            rtThumbHoriz.anchorMin        = new Vector2(0.0f, 0.0f);
            rtThumbHoriz.anchorMax        = new Vector2(1.0f, 1.0f);
            rtThumbHoriz.anchoredPosition = new Vector2(0.0f, 0.0f);
            rtThumbHoriz.sizeDelta        = new Vector2(0.0f, 0.0f);

            ScrollTy sbHoriz = goScrollHoriz.AddComponent <ScrollTy>();

            sbHoriz.direction     = UnityEngine.UI.Scrollbar.Direction.LeftToRight;
            sbHoriz.targetGraphic = imgThumbHoriz;
            sbHoriz.handleRect    = rtThumbHoriz;
            horiz.Apply(sbHoriz, imgThumbHoriz);

            //      FINISH
            ////////////////////////////////////////////////////////////////////////////////

            RectTy scrollR = go.AddComponent <RectTy>();

            scrollR.horizontalScrollbarVisibility = UnityEngine.UI.ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
            scrollR.verticalScrollbarVisibility   = UnityEngine.UI.ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
            scrollR.viewport            = rtViewport;
            scrollR.content             = rtContent;
            scrollR.horizontalScrollbar = sbHoriz;
            scrollR.verticalScrollbar   = sbVert;
            scrollR.scrollSensitivity   = sensitivity;

            this.viewportMask = maskViewport;
            //
            this.horizScroll = sbHoriz;
            this.vertScroll  = sbVert;
            //
            this.rt         = rt;
            this.scrollRect = scrollR;
        }