Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }