Esempio n. 1
0
        public void StartBinding(GameObject mainObj, string args, string layerName)
        {
            Slider slider = LayerWordBinder.swapComponent <Slider>(mainObj);

            Image imgBg = LayerWordBinder.findChildComponent <Image>(mainObj, "background", "bg");

            imgBg.type           = Image.Type.Sliced;
            slider.targetGraphic = imgBg;

            RectTransform sliderBgTrans = slider.targetGraphic.GetComponent <RectTransform>();
            RectTransform mainRectTrans = mainObj.GetComponent <RectTransform>();

            mainRectTrans.sizeDelta          = sliderBgTrans.sizeDelta;
            mainRectTrans.anchoredPosition3D = sliderBgTrans.anchoredPosition3D;

            sliderBgTrans.anchorMin          = new Vector2(0, 0.25f);
            sliderBgTrans.anchorMax          = new Vector2(1, 0.75f);
            sliderBgTrans.sizeDelta          = Vector2.zero;
            sliderBgTrans.anchoredPosition3D = Vector3.zero;

            slider.fillRect = LayerWordBinder.findChildComponent <RectTransform>(mainObj, "fill", "fl");
            if (slider.fillRect)
            {
                GameObject fillRoot = LayerWordBinder.CreateUIObject("fillArea", mainObj);
                fillRoot.transform.localScale    = Vector3.one;
                fillRoot.transform.localPosition = Vector3.zero;
                RectTransform rectTrans = fillRoot.GetComponent <RectTransform>();
                rectTrans.anchorMin = new Vector2(0, 0.25f);
                rectTrans.anchorMax = new Vector2(1, 0.75f);
                rectTrans.pivot     = Vector2.one * 0.5f;
                rectTrans.sizeDelta = new Vector2(-20, 0);

                slider.fillRect.transform.SetParent(fillRoot.transform);
                slider.fillRect.anchoredPosition = Vector3.zero;
                Image fillImage = slider.fillRect.GetComponent <Image>();
                fillImage.type = Image.Type.Sliced;

                slider.fillRect.anchorMax = new Vector2(0, 1);
                slider.fillRect.sizeDelta = new Vector2(10, 0);
            }

            slider.handleRect = LayerWordBinder.findChildComponent <RectTransform>(mainObj, "handle", "ha");
            if (slider.handleRect)
            {
                GameObject handleArea = LayerWordBinder.CreateUIObject("HandleSlideArea", mainObj);
                handleArea.transform.localScale    = Vector3.one;
                handleArea.transform.localPosition = Vector3.zero;

                RectTransform rectTrans = handleArea.GetComponent <RectTransform>();
                rectTrans.anchorMin = Vector2.zero;
                rectTrans.anchorMax = Vector2.one;
                rectTrans.pivot     = Vector2.one * 0.5f;
                rectTrans.sizeDelta = new Vector2(-20, 0);

                slider.handleRect.transform.SetParent(handleArea.transform);
                slider.handleRect.anchoredPosition = Vector3.zero;
                slider.handleRect.anchorMax        = new Vector2(0, 1);
                slider.handleRect.sizeDelta        = new Vector2(20, 0);
            }
        }
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            try
            {
                UIPanel panelView = LayerWordBinder.swapComponent <UIPanel>(mainObj);
                panelView.clipping = UIDrawCall.Clipping.SoftClip;
                UIPanel parentPanel = mainObj.transform.GetComponentInParent <UIPanel>();
                panelView.depth = parentPanel ? parentPanel.depth + 5 : 1;

                UIScrollView scrollview = LayerWordBinder.swapComponent <UIScrollView>(mainObj);
                ogrinPos = Vector3.zero;
                UISprite bgRectTrans = LayerWordBinder.findChildComponent <UISprite>(mainObj, "background", "bg");
                if (bgRectTrans != null)
                {
                    //                panelView.baseClipRegion = new Vector4(bgRectTrans.transform.localPosition.x , bgRectTrans.transform.localPosition.y ,
                    //                                                       bgRectTrans.width , bgRectTrans.height);

                    panelView.baseClipRegion = new Vector4(0, 0, bgRectTrans.width, bgRectTrans.height);

                    ogrinPos = bgRectTrans.transform.localPosition;
                }

                GameObject viewportGObj = LayerWordBinder.CreateUIObject("viewport", mainObj);
                //LayerWordBinder.CreateUIObject("content", viewportGObj);

                UIScrollBar hbar = LayerWordBinder.findChildComponent <UIScrollBar>(mainObj, "hbar", "hb");
                if (hbar != null)
                {
                    scrollview.horizontalScrollBar = hbar;
                    scrollview.movement            = UIScrollView.Movement.Horizontal;
                }

                UIScrollBar vbar = LayerWordBinder.findChildComponent <UIScrollBar>(mainObj, "vbar", "vb");
                if (vbar != null)
                {
                    scrollview.verticalScrollBar = hbar;
                    scrollview.movement          = UIScrollView.Movement.Vertical;
                }
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常ScrollView:{0}] 请检查是否存在(被隐藏)background组! ", layerName));
            }
        }
Esempio n. 3
0
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            Transform bgTrans = LayerWordBinder.findChildComponent <Transform>(mainObj, "background", "bg");

            LayerWordBinder.copyRectTransform(bgTrans.gameObject, mainObj, true);

            Text holderText = LayerWordBinder.findChildComponent <Text>(mainObj, "holder", "ho");

            if (holderText)
            {
                RectTransform holderTrans = holderText.GetComponent <RectTransform>();
                holderTrans.anchorMin = Vector2.zero;
                holderTrans.anchorMax = Vector2.one;
                holderTrans.sizeDelta = Vector2.zero;
                holderTrans.offsetMin = new Vector2(10, 6);
                holderTrans.offsetMax = new Vector2(-10, -7);
            }

            GameObject textObj = LayerWordBinder.CreateUIObject("text", mainObj);
            Text       text    = textObj.AddComponent <Text>();

            text.text            = "";
            text.supportRichText = false;
            if (holderText)
            {
                text.alignment = holderText.alignment;
                text.fontSize  = holderText.fontSize - 1;
                text.font      = holderText.font;
            }

            RectTransform textRectTransform = textObj.GetComponent <RectTransform>();

            textRectTransform.anchorMin = Vector2.zero;
            textRectTransform.anchorMax = Vector2.one;
            textRectTransform.sizeDelta = Vector2.zero;
            textRectTransform.offsetMin = new Vector2(10, 6);
            textRectTransform.offsetMax = new Vector2(-10, -7);

            InputField inputField = LayerWordBinder.swapComponent <InputField>(mainObj);

            inputField.textComponent = text;
            inputField.placeholder   = holderText;
        }
Esempio n. 4
0
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            Image oldImg = LayerWordBinder.findChildComponent <Image>(mainObj, "background", "bg");

            LayerWordBinder.copyRectTransform(oldImg.gameObject, mainObj, true);

            GameObject    sliderArea     = LayerWordBinder.CreateUIObject("Sliding Area", mainObj);
            RectTransform sliderAreaRect = sliderArea.GetComponent <RectTransform>();

            sliderAreaRect.sizeDelta = new Vector2(-20, -20);
            sliderAreaRect.anchorMin = Vector2.zero;
            sliderAreaRect.anchorMax = Vector2.one;

            RectTransform handleRect = LayerWordBinder.findChildComponent <RectTransform>(mainObj, "handle", "ha");

            handleRect.transform.SetParent(sliderArea.transform);
            handleRect.sizeDelta        = new Vector2(20, 20);
            handleRect.anchoredPosition = Vector2.zero;

            Scrollbar scrollbar = LayerWordBinder.swapComponent <Scrollbar>(mainObj);

            scrollbar.handleRect    = handleRect;
            scrollbar.targetGraphic = handleRect.GetComponent <Image>();
        }
Esempio n. 5
0
        public void StartBinding(GameObject mainObj, string args, string layerName)
        {
            ScrollRect    scrollview    = LayerWordBinder.swapComponent <ScrollRect>(mainObj);
            RectTransform viewRectTrans = scrollview.GetComponent <RectTransform>();
            RectTransform bgRectTrans   = LayerWordBinder.findChildComponent <RectTransform>(mainObj, "background", "bg");

            viewRectTrans.anchoredPosition3D = bgRectTrans.anchoredPosition3D;
            viewRectTrans.sizeDelta          = bgRectTrans.sizeDelta;

            LayerWordBinder.offsetAnchorPosition(viewRectTrans, bgRectTrans.anchoredPosition3D);


            GameObject viewportGObj = LayerWordBinder.CreateUIObject("viewport", mainObj);
            // Make viewport fill entire scroll view.
            RectTransform viewportRT = viewportGObj.GetComponent <RectTransform>();

            viewportRT.anchorMin = Vector2.zero;
            viewportRT.anchorMax = Vector2.one;
            viewportRT.sizeDelta = Vector2.zero;
            viewportRT.pivot     = Vector2.up;

            Mask viewportMask = viewportGObj.AddComponent <Mask>();

            viewportMask.showMaskGraphic = false;

            Image viewportImage = viewportGObj.AddComponent <Image>();

            viewportImage.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/UIMask.psd");
            viewportImage.type   = Image.Type.Sliced;

            GameObject contentGObj = LayerWordBinder.CreateUIObject("content", viewportGObj);
            // Make context match viewpoprt width and be somewhat taller.
            // This will show the vertical scrollbar and not the horizontal one.
            RectTransform     contentRT  = contentGObj.GetComponent <RectTransform>();
            ContentSizeFitter sizeFitter = contentGObj.AddComponent <ContentSizeFitter>();

            contentRT.anchorMin = Vector2.up;
            contentRT.anchorMax = Vector2.one;
            contentRT.sizeDelta = new Vector2(0, 300);
            contentRT.pivot     = Vector2.up;

            scrollview.viewport = viewportRT;
            scrollview.content  = contentRT;

            Scrollbar hbar = LayerWordBinder.findChildComponent <Scrollbar>(mainObj, "hbar", "hb");

            if (hbar != null)
            {
                scrollview.horizontalScrollbar = hbar;
                scrollview.horizontal          = true;
                sizeFitter.horizontalFit       = ContentSizeFitter.FitMode.PreferredSize;
            }

            Scrollbar vbar = LayerWordBinder.findChildComponent <Scrollbar>(mainObj, "vbar", "vb");

            if (vbar != null)
            {
                scrollview.verticalScrollbar = hbar;
                scrollview.vertical          = true;
                sizeFitter.verticalFit       = ContentSizeFitter.FitMode.PreferredSize;
            }

            RectTransform cell = LayerWordBinder.findChildComponent <RectTransform>(mainObj, "cell", "cl");

            if (cell)
            {
                Vector3 minPosition = LayerWordBinder.findMinPosition(cell, Vector3.one * float.MaxValue, hbar);
                cell.anchoredPosition3D = minPosition;
                LayerWordBinder.offsetAnchorPosition(cell, minPosition);
            }
        }