public static DropdownUIChild DropdownChild(Transform parent, Sprite img, string txt, Vector3 localPosition, Vector2 size)
    {
        // Rect
        RectTransform   rect = AddRect(parent, localPosition, size);
        DropdownUIChild duie = rect.gameObject.AddComponent <DropdownUIChild>();

        duie.rectGo = rect;
        // Component Image
        if (img == null)
        {
            duie.imageGo = AddImage(duie.rectGo.transform);
        }
        else
        {
            duie.imageGo = AddImage(duie.rectGo.transform, img);
        }
        // Button
        duie.buttonGo = AddButton(duie.rectGo.transform);
        // Child Rect
        RectTransform chRect = AddTextRect(duie.rectGo.transform);

        // Child Rect's Text
        duie.textGo = AddText(chRect.transform, txt);
        ScaleRect(chRect, 0, 0);
        chRect.offsetMin = new Vector2(0, 0);
        chRect.offsetMax = new Vector2(0, 0);
        duie.Init();
        return(duie);
    }
Exemplo n.º 2
0
    public void AddChild()
    {
        if (children == null)
        {
            children = new List <DropdownUIElement>();
        }

        DropdownUIChild duiChild = UIElementFunctions.DropdownChild(this.container.transform, null, "", new Vector3(0, 0, 0), new Vector2(64, 64));

        if (rootDropdown == null)
        {
            rootDropdown = this;
        }

        duiChild.rootDropdown = this.rootDropdown;
        children.Add(duiChild);

        // Anchor to lower right
        duiChild.container.anchorMin = new Vector2(1, 0);
        duiChild.container.anchorMax = new Vector2(1, 0);

        duiChild.thisGo.AddComponent <LayoutElement>();

        duiChild.element.minHeight = this.childHeight;

        // Set image sprite and type
        duiChild.imageGo.sprite = this.imageGo.sprite;
        duiChild.imageGo.type   = this.imageGo.type;

        // Set childText font, font color, and font size
        duiChild.textGo.font     = this.textGo.font;
        duiChild.textGo.color    = this.textGo.color;
        duiChild.textGo.fontSize = this.childFontSize;

        // Set button normal, highlighted, pressed colors
        duiChild.events = duiChild.buttonGo.onClick;

        ColorBlock b = buttonGo.colors;

        b.normalColor      = this.normal;
        b.highlightedColor = this.highlighted;
        b.pressedColor     = this.pressed;
        buttonGo.colors    = b;

        // Set button's onClick and childEvents
        duiChild.buttonGo.onClick = duiChild.events;
        duiChild.buttonGo.onClick.AddListener(delegate() { CloseButton(); });
        duiChild.buttonGo.onClick.AddListener(delegate() { ChangeMainButton(duiChild.textGo.text, duiChild.imageGo.sprite, duiChild.defName); });
    }