Ejemplo n.º 1
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            RectTransform rectTrans = gObj.transform as RectTransform;

            if (rectTrans != null)
            {
                string[] tmps = args.Split(',');
                float    xR   = 0;
                float    yR   = 0;
                float    zR   = 0;
                foreach (var tmp in tmps)
                {
                    var param = tmp.Split('-');
                    if (param[0].ToLower() == "x")
                    {
                        xR = Convert.ToSingle(param[1]);
                    }
                    else if (param[0].ToLower() == "y")
                    {
                        yR = Convert.ToSingle(param[1]);
                    }
                    else if (param[0].ToLower() == "z")
                    {
                        zR = Convert.ToSingle(param[1]);
                    }
                }
                rectTrans.localRotation = Quaternion.Euler(xR, yR, zR);
            }
            LayerWordBinder.swapComponent <UButtonScale>(gObj);
        }
Ejemplo n.º 2
0
        public void StartBinding(GameObject gObj, string args, string layerName)
        {
            Button button = LayerWordBinder.swapComponent <Button>(gObj);
            Image  imgBtn = LayerWordBinder.findChildComponent <Image>(gObj, "background", "bg");

            button.targetGraphic = imgBtn;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="context"></param>
        public static List <Word> BindingParse(GameObject context, string layerName)
        {
            List <Word> words   = ParseLayerName(context.name);
            string      newName = getGameObjectName(words);

            if (!string.IsNullOrEmpty(newName))
            {
                context.name = newName;
            }

            IBinding import = null;

            //解析绑定组件和参数
            foreach (Word word in words)
            {
                if (word.TypeAndParams == null)
                {
                    continue;
                }
                foreach (string key in word.TypeAndParams.Keys)
                {
                    import = LayerWordBinder.GetParser(key);

                    if (import == null)
                    {
                        Debug.LogWarning("Cant parse context ! key :" + key + " , layer:" + layerName);
                        continue;
                    }

                    import.StartBinding(context, word.TypeAndParams[key], layerName);
                }
            }

            return(words);
        }
Ejemplo n.º 4
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            Button button = LayerWordBinder.swapComponent <Button>(gObj);
            Image  imgBtn = LayerWordBinder.findChildComponent <Image>(gObj, "background", "bg");

            button.targetGraphic = imgBtn;
            button.transition    = Selectable.Transition.None;
            if (imgBtn != null)
            {
                Vector3       relativePos = imgBtn.transform.localPosition;
                RectTransform rect        = button.transform as RectTransform;
                rect.localPosition = relativePos;
                rect.sizeDelta     = (imgBtn.transform as RectTransform).sizeDelta;
                Transform[] transCaches = gObj.GetComponentsInChildren <Transform>(true);
                foreach (var trans in transCaches)
                {
                    if (trans == button.transform)
                    {
                        continue;
                    }
                    if (trans.localPosition != Vector3.zero)
                    {
                        trans.localPosition = trans.localPosition - relativePos;
                    }
                }
            }
            LayerWordBinder.swapComponent <UButtonScale>(gObj);
        }
Ejemplo n.º 5
0
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            try
            {
                UISlider slider = LayerWordBinder.swapComponent <UISlider>(mainObj);

                UISprite imgBg = LayerWordBinder.findChildComponent <UISprite>(mainObj, "background", "bg");
                imgBg.type = UIBasicSprite.Type.Sliced;

                UISprite imgFill = LayerWordBinder.findChildComponent <UISprite>(mainObj, "fill", "fl");
                imgFill.type            = UIBasicSprite.Type.Sliced;
                slider.foregroundWidget = imgFill;

                UISprite imgHandle = LayerWordBinder.findChildComponent <UISprite>(mainObj, "handle", "ha");
                if (imgHandle != null)
                {
                    slider.thumb = imgHandle.transform;
                    slider.thumb.localPosition -= imgBg.transform.localPosition;
                    imgFill.width = imgBg.width - imgHandle.width;
                }

                Vector3 offset = imgBg.transform.localPosition;
                NHelper.TransformOffset(mainObj.transform, offset, true);
                LayerWordBinder.NGUICopySprite(imgBg.gameObject, mainObj, true);
                mainObj.transform.localPosition = offset;

                slider.backgroundWidget = mainObj.GetComponent <UIWidget>();
                slider.value            = 0.2f;
                GameTools.AddWidgetCollider(mainObj);
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常Slider:{0}] 请检查是否存在(被隐藏)background和fill组! ", layerName));
            }
        }
Ejemplo n.º 6
0
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            try
            {
                UISprite background = LayerWordBinder.findChildComponent <UISprite>(mainObj, "background", "bg");
                background.type = UIBasicSprite.Type.Sliced;

                UISprite foreground = LayerWordBinder.findChildComponent <UISprite>(mainObj, "handle", "ha");
                foreground.transform.localPosition = Vector3.zero;
                foreground.width  = background.width - 10;
                foreground.height = background.height - 10;
                foreground.type   = UIBasicSprite.Type.Sliced;


                UIScrollBar scrollbar = LayerWordBinder.swapComponent <UIScrollBar>(mainObj);
                LayerWordBinder.NGUICopySprite(background.gameObject, mainObj, true);
                GameTools.AddWidgetCollider(mainObj);

                scrollbar.backgroundWidget = mainObj.GetComponent <UISprite>();
                scrollbar.foregroundWidget = foreground;
                scrollbar.value            = 0.1f;
                scrollbar.barSize          = 0.2f;

                GameTools.AddWidgetCollider(foreground.gameObject);
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常Scrollbar:{0}] 请检查是否存在(被隐藏)background和handle组! ", layerName));
            }
        }
Ejemplo n.º 7
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            try
            {
                UIToggle toggleCom = LayerWordBinder.swapComponent <UIToggle>(gObj);
                toggleCom.@group = 1;

                Transform bgTrans = LayerWordBinder.findChildComponent <Transform>(gObj, "background", "bg");
                UIWidget  bgWidge = bgTrans.GetComponent <UIWidget>();

                Transform imgMarkTrans = LayerWordBinder.findChildComponent <Transform>(gObj, "checkmark", "cm");
                UIWidget  imgMark      = LayerWordBinder.swapComponent <UIWidget>(imgMarkTrans.gameObject);
                imgMark.depth = bgWidge.depth + 1;
                imgMark.SetDimensions(bgWidge.width, bgWidge.height);

                toggleCom.activeSprite = imgMark;

                Vector3 orginPos = bgTrans.localPosition;
                NHelper.TransformOffsetParent(gObj.transform, bgTrans, orginPos);
                gObj.transform.localPosition = orginPos;

                GameTools.AddWidgetCollider(gObj);
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常Toggle:{0}] 请检查是否存在(被隐藏)background组! ", layerName));
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            if (args == "_root_")
            {
#if NGUI
                UIPanel rootPanel = LayerWordBinder.swapComponent <UIPanel>(gObj);
                rootPanel.depth = 1;
                return;
#endif
            }
            gObj.name = args;
        }
Ejemplo n.º 10
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            Toggle toggle = LayerWordBinder.swapComponent <Toggle>(gObj);

            Image imgBtn = LayerWordBinder.findChildComponent <Image>(gObj, "background", "bg");

            toggle.image = imgBtn;

            Image imgMark = LayerWordBinder.findChildComponent <Image>(gObj, "checkmark", "cm");

            toggle.graphic = imgMark;
            toggle.isOn    = true;
        }
Ejemplo n.º 11
0
        public override void ExitBinding(GameObject g, string args, string layerName)
        {
            RectTransform contentRectTrans = LayerWordBinder.findChildComponent <RectTransform>(g, "content", "content");

            foreach (RectTransform childTrans in g.transform)
            {
                if (childTrans.name == "viewport" || childTrans.name == "bg" || childTrans.name == "backgroud")
                {
                    continue;
                }
                childTrans.SetParent(contentRectTrans);
                childTrans.GetOrAddComponent <LayoutElement>();
            }
        }
Ejemplo n.º 12
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            UITexture mTexture = LayerWordBinder.swapComponent <UITexture>(gObj);
            UISprite  sprte    = gObj.GetComponent <UISprite>();

            mTexture.baseTexture = this.findBigTexture(sprte.spriteName);

            mTexture.depth  = sprte.depth;
            mTexture.width  = sprte.width;
            mTexture.height = sprte.height;

            mTexture.shader = Shader.Find("Unlit/Transparent Colored");
            GameObject.DestroyImmediate(sprte);
        }
Ejemplo n.º 13
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            if (args == "_root_")
            {
#if NGUI
                UIPanel rootPanel = LayerWordBinder.swapComponent <UIPanel>(gObj);
                rootPanel.depth = 1;
#elif UGUI
                Canvas cav = LayerWordBinder.swapComponent <Canvas>(gObj);
                cav.overrideSorting = true;
                GraphicRaycaster gr = LayerWordBinder.swapComponent <GraphicRaycaster>(gObj);
#endif
            }
            gObj.name = args;
        }
Ejemplo n.º 14
0
        public override void ExitBinding(GameObject g, string args, string layerName)
        {
            foreach (Transform childTrans in g.transform)
            {
                if (childTrans.name.StartsWith("item"))
                {
                    reducePosition(childTrans);
                    LayerWordBinder.swapComponent <UIDragScrollView>(childTrans.gameObject);
                    NGUITools.AddWidgetCollider(childTrans.gameObject);
                }
            }

            //更新子结点的坐标
            NHelper.TransformOffset(g.transform, ogrinPos, false);
            g.transform.localPosition = ogrinPos;
        }
Ejemplo n.º 15
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));
            }
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
0
        public static GameObject BuildPsdRoot(GameObject root, PsdExportSettings settings, PsdFileInfo fileInfo,
                                              SpriteAlignment align, IPsdConstructor constructor)
        {
            GameObject spriteObject = constructor.CreateGameObject(settings.Filename, root);

            spriteObject.name += "[name:_root_]";
            LayerWordBinder.registWord();

            PSDLayerGroupInfo rootGroup = new PSDLayerGroupInfo(settings.Filename, settings.Psd.Layers.Count - 1, true, true);

            rootGroup.start = 0;

            BuildPsd(spriteObject, rootGroup, settings, fileInfo, align, constructor);

            //bind gen flag
            bindGenFlags(spriteObject);

            return(spriteObject);
        }
Ejemplo n.º 18
0
        public static void exitBindingParse(List <Word> words, GameObject context, string layerName)
        {
            IBinding import = null;

            foreach (Word word in words)
            {
                if (word.TypeAndParams == null)
                {
                    continue;
                }
                foreach (string key in word.TypeAndParams.Keys)
                {
                    import = LayerWordBinder.GetParser(key);
                    if (import == null)
                    {
                        continue;
                    }
                    import.ExitBinding(context, word.TypeAndParams[key], layerName);
                }
            }
        }
Ejemplo n.º 19
0
        public override void StartBinding(GameObject mainObj, string args, string layerName)
        {
            try
            {
                UISprite bgTrans = LayerWordBinder.findChildComponent <UISprite>(mainObj, "background", "bg");
                bgTrans.type = UIBasicSprite.Type.Sliced;

                UILabel text = LayerWordBinder.findChildComponent <UILabel>(mainObj, "holder", "ho");
                text.transform.localPosition -= bgTrans.transform.localPosition;
                text.pivot = UIWidget.Pivot.Left;

                LayerWordBinder.NGUICopySprite(bgTrans.gameObject, mainObj, true);
                NGUITools.AddWidgetCollider(mainObj);

                UIInput inputField = LayerWordBinder.swapComponent <UIInput>(mainObj);
                inputField.label = text;
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常InputField:{0}] 请检查是否存在(被隐藏)background和holder组! ", layerName));
            }
        }
Ejemplo n.º 20
0
        public override void StartBinding(GameObject gObj, string args, string layerName)
        {
            try
            {
                //需求添加,用于导出Lua识别类型
                UIButton btn = LayerWordBinder.swapComponent <UIButton>(gObj);
                btn.enabled = false;

                UIButtonScale button = LayerWordBinder.swapComponent <UIButtonScale>(gObj);
                LayerWordBinder.swapComponent <UIEventListener>(gObj);
                button.pressed = Vector3.one * 0.8f;
                //            UIButton button = LayerWordBinder.swapComponent<UIButton>(gObj);
                //            button.pressed = Color.white;
                //            button.hover = Color.white;

                UISprite imgBtn = gObj.GetComponent <UISprite>();
                if (imgBtn == null)
                {
                    imgBtn = LayerWordBinder.findChildComponent <UISprite>(gObj, "background", "bg");
                }

                if (imgBtn != null)
                {
                    //button.tweenTarget = imgBtn.gameObject;
                    Vector3 originPos = imgBtn.transform.localPosition;
                    NHelper.TransformOffset(gObj.transform, imgBtn.transform.localPosition, true);
                    gObj.transform.localPosition = originPos;
                }

                NGUITools.AddWidgetCollider(gObj);
            }
            catch (Exception)
            {
                Debug.LogError(string.Format("[异常Button:{0}] 请检查是否存在(被隐藏)background组! ", layerName));
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 绑定结点操作的标志
        /// </summary>
        /// <param name="root"></param>
        private static void bindGenFlags(GameObject root)
        {
            string genDir   = Path.Combine(Application.dataPath, ToolConst.GenLogFolder);
            string filePath = Path.Combine(genDir, root.name + ".xml");

            if (!File.Exists(filePath))
            {
                Debug.LogWarning("Cant find file . File path is " + filePath);
                return;
            }

            string      text = File.ReadAllText(filePath);
            XmlDocument doc  = new XmlDocument();

            doc.LoadXml(text);

            XmlNode rootNodes = doc.SelectSingleNode("panelRoots");

            foreach (XmlNode childNode in rootNodes.ChildNodes)
            {
                XmlElement panelEle  = (XmlElement)childNode;
                string     hierarchy = panelEle.GetAttribute("hierarchy");
                if (string.IsNullOrEmpty(hierarchy) || hierarchy == root.gameObject.name)
                {
                    UIPanelRoot panelRoot = LayerWordBinder.swapComponent <UIPanelRoot>(root);
                    panelRoot.deserializePanelRoot(panelEle);
                }
                else
                {
                    hierarchy = hierarchy.Replace(".", "/");
                    GameObject  child     = root.transform.FindChild(hierarchy).gameObject;
                    UIPanelRoot panelRoot = LayerWordBinder.swapComponent <UIPanelRoot>(child);
                    panelRoot.deserializePanelRoot(panelEle);
                }
            }
        }
Ejemplo n.º 22
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>();
        }
Ejemplo n.º 23
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);
            }
        }