예제 #1
0
        public static GameObject CreateMessageBox(Resources resources)
        {
            GameObject go = CreateImage(resources);

            go.name = "IMCMessageBox";
            go.AddComponent <CanvasGroup>();
            IMCMessageBox mesBox = go.AddComponent <IMCMessageBox>();

            mesBox.background = go.GetComponent <IMCImage>();

            RectTransform goRT = go.GetComponent <RectTransform>();

            goRT.anchorMin = new Vector2(0.5f, 0.5f);
            goRT.anchorMax = new Vector2(0.5f, 0.5f);
            goRT.pivot     = new Vector2(0.5f, 0.5f);
            goRT.sizeDelta = new Vector2(400, 250);

            GameObject title = CreateText(resources);

            title.name = "Title";
            IMCText titleIMC = title.GetComponent <IMCText>();

            titleIMC.transform.SetParent(goRT);
            titleIMC.anchorMin          = new Vector2(0.5f, 1);
            titleIMC.anchorMax          = new Vector2(0.5f, 1);
            titleIMC.pivot              = new Vector2(0.5f, 1);
            titleIMC.sizeDelta          = new Vector2(400, 30);
            titleIMC.anchoredPosition3D = Vector3.zero;
            titleIMC.text      = "Title";
            titleIMC.fontSize  = 14;
            titleIMC.alignment = TextAnchor.MiddleCenter;
            mesBox.title       = titleIMC;

            GameObject content = CreateText(resources);

            content.name = "Content";
            IMCText contentIMC = content.GetComponent <IMCText>();

            contentIMC.transform.SetParent(goRT);
            contentIMC.anchorMin          = new Vector2(0.5f, 0.5f);
            contentIMC.anchorMax          = new Vector2(0.5f, 0.5f);
            contentIMC.pivot              = new Vector2(0.5f, 0.5f);
            contentIMC.sizeDelta          = new Vector2(400, 120);
            contentIMC.anchoredPosition3D = Vector3.zero;
            contentIMC.text      = "Content";
            contentIMC.fontSize  = 14;
            contentIMC.alignment = TextAnchor.MiddleCenter;
            mesBox.content       = contentIMC;

            GameObject    btns   = new GameObject("ButtonList");
            RectTransform btnsRT = btns.AddComponent <RectTransform>();

            btnsRT.SetParent(goRT);
            btnsRT.anchorMin          = new Vector2(0.5f, 0);
            btnsRT.anchorMax          = new Vector2(0.5f, 0);
            btnsRT.pivot              = new Vector2(0.5f, 0);
            btnsRT.sizeDelta          = new Vector2(380, 40);
            btnsRT.anchoredPosition3D = new Vector3(0, 10, 0);
            ContentSizeFitter btnsCSF = btns.AddComponent <ContentSizeFitter>();

            btnsCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            btnsCSF.verticalFit   = ContentSizeFitter.FitMode.Unconstrained;
            IMCHorizontalLayoutGroup btnsHLG = btns.AddComponent <IMCHorizontalLayoutGroup>();

            btnsHLG.spacing     = 5;
            mesBox.buttonParent = btns;
            for (int i = 0; i < 3; i++)
            {
                GameObject    tempBtn   = CreateButton(resources);
                LayoutElement tempBtnLE = tempBtn.AddComponent <LayoutElement>();
                tempBtn.transform.SetParent(btnsRT);
                tempBtnLE.preferredHeight = 35.9f;
                tempBtnLE.preferredWidth  = 124.4f;
                mesBox.btns.Add(tempBtn.GetComponent <IMCButton>());
            }

            GameObject closeBtn = CreateButton(resources);

            closeBtn.name = "closeBtn";
            RectTransform closeBtnRT = closeBtn.GetComponent <RectTransform>();

            closeBtnRT.SetParent(goRT);
            closeBtnRT.anchorMin          = Vector2.one;
            closeBtnRT.anchorMax          = Vector2.one;
            closeBtnRT.pivot              = Vector2.one;
            closeBtnRT.sizeDelta          = new Vector2(35, 30);
            closeBtnRT.anchoredPosition3D = Vector3.zero;
            IMCText closeText = closeBtn.GetComponent <IMCButton>().Text;

            closeText.text      = "X";
            closeText.fontSize  = 14;
            closeText.alignment = TextAnchor.MiddleCenter;
            mesBox.closeButton  = closeBtn.GetComponent <IMCButton>();

            return(go);
        }
예제 #2
0
        public static GameObject CreateTabView(Resources resources)
        {
            GameObject go = CreateUIElementRoot("IMC Tab View", s_ImageElementSize);

            go.AddComponent <CanvasGroup>();
            IMCTabView tabView = go.AddComponent <IMCTabView>();

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

            image.sprite = resources.background;
            image.type   = IMCImage.Type.Sliced;
            image.color  = s_PanelColor;

            RectTransform tabViewRT = go.GetComponent <RectTransform>();

            tabViewRT.sizeDelta = new Vector2(600, 250);
            tabViewRT.pivot     = new Vector2(0.5f, 1);

            GameObject    toggleContainer   = CreateUIElementRoot("ToggleContainer", s_ImageElementSize);
            RectTransform toggleContainerRT = toggleContainer.GetComponent <RectTransform>();

            toggleContainerRT.SetParent(tabViewRT);
            toggleContainerRT.anchorMin        = new Vector2(0.5f, 1);
            toggleContainerRT.anchorMax        = new Vector2(0.5f, 1);
            toggleContainerRT.pivot            = new Vector2(0.5f, 0);
            toggleContainerRT.anchoredPosition = Vector2.zero;
            toggleContainerRT.sizeDelta        = new Vector2(600, 50);
            ContentSizeFitter contentSizeFitter = toggleContainer.AddComponent <ContentSizeFitter>();

            contentSizeFitter.horizontalFit = IMCUI.UI.ContentSizeFitter.FitMode.PreferredSize;
            toggleContainer.AddComponent <IMCHorizontalLayoutGroup>();
            ToggleGroup toggleGroup = toggleContainer.AddComponent <ToggleGroup>();

            for (int i = 0; i <= 2; i++)
            {
                GameObject toggle = CreateToggle(resources);
                toggle.transform.FindChild("Label").GetComponent <IMCText>().raycast = false;//if don't shut down IMCText is raycast attribute  ,occur BUG.

                IMCTabViewToggle tabViewToggle = toggle.AddComponent <IMCTabViewToggle>();
                tabViewToggle.tabView = tabViewRT.GetComponent <IMCTabView>();

                tabViewRT.GetComponent <IMCTabView>().toggles.Add(tabViewToggle);
                // in editor script , add event invalidity.
                //tabViewToggle.toggle.onValueChanged.AddListener(tabViewToggle.parent.TabViewControlShowOrClose);

                IMCToggle toggleT = toggle.GetComponent <IMCToggle>();
                toggleT.name = toggleT.name + i.ToString();
                toggleT.transform.SetParent(toggleContainerRT);

                toggleT.group = toggleGroup;

                // because toggleContainer is  ToggleGroup component,ToggleGroup is Execution order impact Toggle,so annotation this code .
                //if (i == 0)
                //    toggleT.isOn = true;
                //else
                //    toggleT.isOn = false;

                RectTransform backGround = toggle.transform.GetChild(0).GetComponent <RectTransform>();
                backGround.anchorMin        = Vector2.zero;
                backGround.anchorMax        = Vector2.one;
                backGround.pivot            = Vector2.zero;
                backGround.anchoredPosition = Vector2.zero;
                backGround.sizeDelta        = Vector2.zero;

                RectTransform checkmark = backGround.GetChild(0).GetComponent <RectTransform>();
                checkmark.anchorMin        = Vector2.zero;
                checkmark.anchorMax        = Vector2.one;
                checkmark.anchoredPosition = Vector2.zero;
                checkmark.sizeDelta        = Vector2.zero;

                RectTransform labelRT = toggle.transform.GetChild(1).GetComponent <RectTransform>();
                labelRT.anchoredPosition = Vector2.zero;
                labelRT.sizeDelta        = Vector2.zero;
                labelRT.GetComponent <IMCText>().alignment = TextAnchor.MiddleCenter;

                LayoutElement layoutElement = toggle.AddComponent <LayoutElement>();
                layoutElement.preferredWidth  = 200;
                layoutElement.preferredHeight = 20;
            }

            GameObject    contentContainer   = CreateUIElementRoot("ContentContainer", s_ImageElementSize);
            RectTransform contentContainerRT = contentContainer.GetComponent <RectTransform>();

            contentContainerRT.sizeDelta = tabViewRT.sizeDelta;
            contentContainerRT.SetParent(tabViewRT);
            contentContainerRT.anchoredPosition = Vector2.zero;
            for (int i = 0; i <= 2; i++)
            {
                GameObject toggleContent      = CreateUIElementRoot("TabContent" + i.ToString(), s_ImageElementSize);
                IMCImage   toggleContentImage = toggleContent.AddComponent <IMCImage>();
                toggleContentImage.sprite = resources.background;
                toggleContentImage.type   = IMCImage.Type.Sliced;
                toggleContentImage.color  = s_PanelColor;

                tabViewRT.GetComponent <IMCTabView>().contents.Add(toggleContentImage);

                RectTransform toggleContentRT = toggleContent.GetComponent <RectTransform>();
                toggleContentRT.sizeDelta = tabViewRT.sizeDelta;
                toggleContentRT.SetParent(contentContainerRT);
                toggleContentRT.anchoredPosition = Vector2.zero;
            }
            return(go);
        }