Ejemplo 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");

            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");
            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");
            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);
            }
        }
Ejemplo n.º 2
0
        public void StartBinding(GameObject mainObj, string args, string layerName)
        {
            Transform bgTrans = LayerWordBinder.findChildComponent <Transform>(mainObj, "background");

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

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

            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;
        }
Ejemplo n.º 3
0
        public void StartBinding(GameObject mainObj, string args, string layerName)
        {
            Image oldImg = LayerWordBinder.findChildComponent <Image>(mainObj, "background");

            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");

            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>();
        }
Ejemplo n.º 4
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");

            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");

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

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

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

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

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