Ejemplo n.º 1
0
        public static void CreateButton(MenuCommand commond)
        {
            GameObject go = CreateUIElementRoot("Button", commond, s_ThickGUIElementSize);

            go.AddComponent <ImageExpand>();
            go.AddComponent <ButtonExpand>();

            GameObject textGo = new GameObject("Label");
            TextExpand text   = textGo.AddComponent <TextExpand>();

            text.text      = "Kubility";
            text.fontSize  = 20;
            text.color     = Color.black;
            text.alignment = TextAnchor.MiddleCenter;
            ClearRays(text);

            SetParentAndAlign(go, Selection.activeGameObject);
            SetParentAndAlign(textGo, go);

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

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

            Selection.activeObject = go;
        }
Ejemplo n.º 2
0
        public static void CreateInputField(MenuCommand command)
        {
            GameObject go = CreateUIElementRoot("InputField", command, s_ThickGUIElementSize);
            GameObject childPlaceholder = CreateObj("Placeholder", go);
            GameObject childText        = CreateObj("Text", go);

            ImageExpand image = go.AddComponent <ImageExpand>();

            image.sprite = AssetDatabase.GetBuiltinExtraResource <Sprite>(kInputFieldBackgroundPath);
            image.type   = Image.Type.Sliced;
            image.color  = Color.white;

            InputExpand inputField = go.AddComponent <InputExpand>();

            ColorBlock colors = inputField.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);
            inputField.colors       = colors;

            TextExpand text = childText.AddComponent <TextExpand>();

            text.text            = "";
            text.supportRichText = false;
            text.color           = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);

            TextExpand placeholder = childPlaceholder.AddComponent <TextExpand>();

            placeholder.text      = "Kubility";
            placeholder.fontStyle = FontStyle.Italic;

            // Make placeholder color half as opaque as normal text color.
            Color placeholderColor = text.color;

            placeholderColor.a *= 0.5f;
            placeholder.color   = placeholderColor;

            RectTransform textRectTransform = childText.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);

            RectTransform placeholderRectTransform = childPlaceholder.GetComponent <RectTransform>();

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

            inputField.textComponent = text;
            inputField.placeholder   = placeholder;
        }
Ejemplo n.º 3
0
        protected override void Awake()
        {
            base.Awake();

            if (btnlabel == null)
            {
                Transform tr = this.transform.Find("Label");
                if (tr != null)
                {
                    btnlabel = tr.GetComponent <TextExpand>();
                }
            }
        }
Ejemplo n.º 4
0
        public static void CreateText(MenuCommand commond)
        {
            GameObject go   = CreateUIElementRoot("Text", commond, s_ThickGUIElementSize);
            TextExpand text = go.AddComponent <TextExpand>();

            text.text            = "Test UI";
            text.supportRichText = false;
            text.fontSize        = 20;
            ClearRays(text);

            SetParentAndAlign(go, Selection.activeGameObject);

            Selection.activeObject = go;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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);
        }