Esempio n. 1
0
        public static void CreateToggle(MenuCommand command)
        {
            GameObject   go     = CreateUIElementRoot("Toggle", command, s_ThinGUIElementSize);
            ToggleExpand toggle = go.AddComponent <ToggleExpand>();

            ClearRays(toggle);

            GameObject Bg      = CreateObj("BackGround", go);
            var        bgImage = AddImage(Bg, whiteColor, kStandardSpritePath);

            GameObject Checkmark      = CreateObj("Checkmark", Bg);
            var        checkmarkImage = AddImage(Checkmark, whiteColor, kStandardSpritePath);

            GameObject textGo = CreateObj("Label", go);
            TextExpand text   = textGo.AddComponent <TextExpand>();

            text.text  = "Kubility";
            text.color = Color.black;

            ClearRays(text);

            toggle.graphic       = checkmarkImage;
            toggle.targetGraphic = bgImage;


            RectTransform bgRect = Bg.GetComponent <RectTransform>();

            bgRect.anchorMin        = new Vector2(0f, 1f);
            bgRect.anchorMax        = new Vector2(0f, 1f);
            bgRect.anchoredPosition = new Vector2(10f, -10f);
            bgRect.sizeDelta        = new Vector2(kThinHeight, kThinHeight);

            RectTransform checkmarkRect = Checkmark.GetComponent <RectTransform>();

            checkmarkRect.anchorMin        = new Vector2(0.5f, 0.5f);
            checkmarkRect.anchorMax        = new Vector2(0.5f, 0.5f);
            checkmarkRect.anchoredPosition = Vector2.zero;
            checkmarkRect.sizeDelta        = new Vector2(20f, 20f);

            RectTransform labelRect = textGo.GetComponent <RectTransform>();

            labelRect.anchorMin = new Vector2(0f, 0f);
            labelRect.anchorMax = new Vector2(1f, 1f);
            labelRect.offsetMin = new Vector2(23f, 1f);
            labelRect.offsetMax = new Vector2(-5f, -2f);

            Selection.activeObject = go;
        }
Esempio n. 2
0
        public static void CreateDropdown(MenuCommand command)
        {
            GameObject root = CreateUIElementRoot("Dropdown", command, s_ThickGUIElementSize);

            GameObject label          = CreateObj("Label", root);
            GameObject arrow          = CreateObj("Arrow", root);
            GameObject template       = CreateObj("Template", root);
            GameObject viewport       = CreateObj("Viewport", template);
            GameObject content        = CreateObj("Content", viewport);
            GameObject item           = CreateObj("Item", content);
            GameObject itemBackground = CreateObj("Item Background", item);
            GameObject itemCheckmark  = CreateObj("Item Checkmark", item);
            GameObject itemLabel      = CreateObj("Item Label", item);

            // Sub controls.

            GameObject scrollbar = CreateScrollbar();

            scrollbar.name = "Scrollbar";
            SetParentAndAlign(scrollbar, template);

            ScrollbarExpand scrollbarScrollbar = scrollbar.GetComponent <ScrollbarExpand>();

            scrollbarScrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);

            RectTransform vScrollbarRT = scrollbar.GetComponent <RectTransform>();

            vScrollbarRT.anchorMin = Vector2.right;
            vScrollbarRT.anchorMax = Vector2.one;
            vScrollbarRT.pivot     = Vector2.one;
            vScrollbarRT.sizeDelta = new Vector2(vScrollbarRT.sizeDelta.x, 0);

            // Setup item UI components.

            TextExpand itemLabelText = itemLabel.AddComponent <TextExpand>();

            itemLabelText.alignment = TextAnchor.MiddleLeft;
            itemLabelText.color     = Color.black;

            ImageExpand itemBackgroundImage = itemBackground.AddComponent <ImageExpand>();

            itemBackgroundImage.color = new Color32(245, 245, 245, 255);

            ImageExpand itemCheckmarkImage = itemCheckmark.AddComponent <ImageExpand>();

            itemCheckmarkImage.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kCheckmarkPath);

            ToggleExpand itemToggle = item.AddComponent <ToggleExpand>();

            itemToggle.targetGraphic = itemBackgroundImage;
            itemToggle.graphic       = itemCheckmarkImage;
            itemToggle.isOn          = true;

            // Setup template UI components.

            ImageExpand templateImage = template.AddComponent <ImageExpand>();

            templateImage.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kStandardSpritePath);
            templateImage.type   = Image.Type.Sliced;

            ScrollRect templateScrollRect = template.AddComponent <ScrollRect>();

            templateScrollRect.content                     = (RectTransform)content.transform;
            templateScrollRect.viewport                    = (RectTransform)viewport.transform;
            templateScrollRect.horizontal                  = false;
            templateScrollRect.movementType                = ScrollRect.MovementType.Clamped;
            templateScrollRect.verticalScrollbar           = scrollbarScrollbar;
            templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
            templateScrollRect.verticalScrollbarSpacing    = -3;

            Mask scrollRectMask = viewport.AddComponent <Mask>();

            scrollRectMask.showMaskGraphic = false;

            ImageExpand viewportImage = viewport.AddComponent <ImageExpand>();

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

            // Setup dropdown UI components.

            TextExpand labelText = label.AddComponent <TextExpand>();

            labelText.text      = "Option A";
            labelText.alignment = TextAnchor.MiddleLeft;

            ImageExpand arrowImage = arrow.AddComponent <ImageExpand>();

            arrowImage.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/DropdownArrow.psd");//UI/Skin/DropdownArrow.psd

            ImageExpand backgroundImage = root.AddComponent <ImageExpand>();

            backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kStandardSpritePath);
            backgroundImage.color  = whiteColor;
            backgroundImage.type   = Image.Type.Sliced;

            DropDownExpand dropdown = root.AddComponent <DropDownExpand>();

            dropdown.targetGraphic = backgroundImage;

            ColorBlock colors = dropdown.colors;

            colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
            colors.pressedColor     = new Color(0.698f, 0.698f, 0.698f);
            colors.disabledColor    = new Color(0.521f, 0.521f, 0.521f);

            dropdown.template    = template.GetComponent <RectTransform>();
            dropdown.captionText = labelText;
            dropdown.itemText    = itemLabelText;

            // Setting default Item list.
            //itemLabelText.text = "Option A";

            // Set up RectTransforms.

            RectTransform labelRT = label.GetComponent <RectTransform>();

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

            RectTransform arrowRT = arrow.GetComponent <RectTransform>();

            arrowRT.anchorMin        = new Vector2(1, 0.5f);
            arrowRT.anchorMax        = new Vector2(1, 0.5f);
            arrowRT.sizeDelta        = new Vector2(20, 20);
            arrowRT.anchoredPosition = new Vector2(-15, 0);

            RectTransform templateRT = template.GetComponent <RectTransform>();

            templateRT.anchorMin        = new Vector2(0, 0);
            templateRT.anchorMax        = new Vector2(1, 0);
            templateRT.pivot            = new Vector2(0.5f, 1);
            templateRT.anchoredPosition = new Vector2(0, 2);
            templateRT.sizeDelta        = new Vector2(0, 150);

            RectTransform viewportRT = viewport.GetComponent <RectTransform>();

            viewportRT.anchorMin = new Vector2(0, 0);
            viewportRT.anchorMax = new Vector2(1, 1);
            viewportRT.sizeDelta = new Vector2(-18, 0);
            viewportRT.pivot     = new Vector2(0, 1);

            RectTransform contentRT = content.GetComponent <RectTransform>();

            contentRT.anchorMin        = new Vector2(0f, 1);
            contentRT.anchorMax        = new Vector2(1f, 1);
            contentRT.pivot            = new Vector2(0.5f, 1);
            contentRT.anchoredPosition = new Vector2(0, 0);
            contentRT.sizeDelta        = new Vector2(0, 28);

            RectTransform itemRT = item.GetComponent <RectTransform>();

            itemRT.anchorMin = new Vector2(0, 0.5f);
            itemRT.anchorMax = new Vector2(1, 0.5f);
            itemRT.sizeDelta = new Vector2(0, 20);

            RectTransform itemBackgroundRT = itemBackground.GetComponent <RectTransform>();

            itemBackgroundRT.anchorMin = Vector2.zero;
            itemBackgroundRT.anchorMax = Vector2.one;
            itemBackgroundRT.sizeDelta = Vector2.zero;

            RectTransform itemCheckmarkRT = itemCheckmark.GetComponent <RectTransform>();

            itemCheckmarkRT.anchorMin        = new Vector2(0, 0.5f);
            itemCheckmarkRT.anchorMax        = new Vector2(0, 0.5f);
            itemCheckmarkRT.sizeDelta        = new Vector2(20, 20);
            itemCheckmarkRT.anchoredPosition = new Vector2(10, 0);

            RectTransform itemLabelRT = itemLabel.GetComponent <RectTransform>();

            itemLabelRT.anchorMin = Vector2.zero;
            itemLabelRT.anchorMax = Vector2.one;
            itemLabelRT.offsetMin = new Vector2(20, 1);
            itemLabelRT.offsetMax = new Vector2(-10, -2);

            template.SetActive(false);

            //ClearRays(dropdown);
        }