예제 #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static CheckboxButton CreateCheckbox(Transform parent, Color color, Text textPrefab, string label, float width = 100)
        {
            var checkboxButton = new GameObject("Checkbox", typeof(RectTransform));
            var rt             = checkboxButton.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, width, 20);
            rt.anchoredPosition = new Vector2(0, 0);

            var iconWidth = 20;
            var checkbox  = LockerPrefabShared.CreateIcon(rt, color, 0);

            RectTransformExtensions.SetSize(checkbox.rectTransform, iconWidth, iconWidth);
            checkbox.rectTransform.anchoredPosition = new Vector2(-width / 2 + iconWidth / 2, 0);

            var spacing = 5;
            var text    = LockerPrefabShared.CreateText(rt, textPrefab, color, 0, 10, label);

            RectTransformExtensions.SetSize(text.rectTransform, width - iconWidth - spacing, iconWidth);
            text.rectTransform.anchoredPosition = new Vector2(iconWidth / 2 + spacing, 0);
            text.alignment = TextAnchor.MiddleLeft;

            checkboxButton.AddComponent <BoxCollider2D>();

            var button = checkboxButton.AddComponent <CheckboxButton>();

            button.image   = checkbox;
            button.text    = text;
            button.UpColor = color;

            return(button);
        }
예제 #2
0
        protected static void Create(Transform parent, Picker instance, int buttonCount)
        {
            var lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab   = Instantiate(lockerPrefab.GetComponentInChildren <Text>());

            textPrefab.fontSize = 12;
            textPrefab.color    = HabitatControlPanel.ScreenContentColor;

            var rt = instance.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, 1000 / 5.0f, (buttonCount <= 10 ? 400 : 900) / 5.0f);

            instance.background = instance.gameObject.AddComponent <Image>();

            for (int i = 0; i < buttonCount; ++i)
            {
                var colorButton = PickerButton.Create(instance.transform, ButtonSize, ButtonSize * 0.7f);
                instance.buttons.Add(colorButton);
            }

            instance.prevPageButton = PickerPageButton.Create(instance.transform, Color.white);
            (instance.prevPageButton.transform as RectTransform).anchoredPosition = new Vector2(-20, -70);

            instance.nextPageButton = PickerPageButton.Create(instance.transform, Color.white);
            (instance.nextPageButton.transform as RectTransform).anchoredPosition = new Vector2(20, -70);

            instance.pageText = LockerPrefabShared.CreateText(instance.transform, textPrefab, Color.white, 0, 10, "X/X");
            RectTransformExtensions.SetSize(instance.pageText.rectTransform, 20, 20);
            instance.pageText.rectTransform.anchoredPosition = new Vector2(0, -70);
        }
        private static Image CreateScreen(Transform parent)
        {
            var canvas = LockerPrefabShared.CreateCanvas(parent);

            canvas.transform.localPosition = new Vector3(0, 0, 0.02f);

            var background = new GameObject("Background", typeof(RectTransform)).AddComponent <Image>();
            var rt         = background.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), canvas.transform);
            RectTransformExtensions.SetSize(rt, 178, 298);
            background.transform.localScale = new Vector3(0.01f, 0.01f, 1);

            background.type  = Image.Type.Simple;
            background.color = new Color(1, 1, 1);
            //background.gameObject.SetActive(false);

            return(background);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static PickerPageButton Create(Transform parent, Color color, float iconWidth = 20)
        {
            var pageButton = new GameObject("PageButton", typeof(RectTransform));
            var rt         = pageButton.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, iconWidth, iconWidth);
            rt.anchoredPosition = new Vector2(0, 0);

            var icon = LockerPrefabShared.CreateIcon(rt, color, 0);

            RectTransformExtensions.SetSize(icon.rectTransform, iconWidth, iconWidth);
            icon.rectTransform.anchoredPosition = new Vector2(0, 0);

            pageButton.AddComponent <BoxCollider2D>();

            var button = pageButton.AddComponent <PickerPageButton>();

            button.image = icon;

            return(button);
        }
예제 #5
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static PickerButton Create(Transform parent, float width, float iconWidth)
        {
            var button = new GameObject("PickerButton", typeof(RectTransform)).AddComponent <PickerButton>();
            var rt     = button.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, width, width);

            var highlight = LockerPrefabShared.CreateIcon(rt, Color.white, 0);

            RectTransformExtensions.SetParams(highlight.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform);
            RectTransformExtensions.SetSize(highlight.rectTransform, width, width);
            button.highlight = highlight;
            button.highlight.gameObject.SetActive(false);

            var image = new GameObject("Image", typeof(RectTransform)).AddComponent <uGUI_Icon>();

            RectTransformExtensions.SetParams(image.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform);
            RectTransformExtensions.SetSize(image.rectTransform, iconWidth, iconWidth);
            image.rectTransform.anchoredPosition = new Vector2(0, 0);
            button.image = image;

            return(button);
        }