示例#1
0
    void CreateButtons()
    {
        int spriteCount = 0;

        foreach (Button button in data.buttons)
        {
            if (button.image != null)
            {
                spriteCount++;
            }
        }
        totalImages = spriteCount;

        int iterator      = 0;
        int offsetCounter = 0;

        foreach (Button button in data.buttons)
        {
            if (button.image != null)
            {
                //create a sprite
                Vector2 spriteSize = new Vector2(images[iterator].width, images[iterator].height);
                Sprite  tempSprite = Sprite.Create(images[iterator], new Rect(Vector2.zero, spriteSize), new Vector2(0.5f, 0.5f));
                sprites.Add(tempSprite);

                //build the button GameObject;
                GameObject go = new GameObject();
                go.name = data.buttons[iterator].title;
                UnityEngine.UI.Image uiSprite = go.AddComponent <UnityEngine.UI.Image>();
                uiSprite.sprite = tempSprite;
                UnityEngine.UI.Button uiButton = go.AddComponent <UnityEngine.UI.Button>();
                uiButton.targetGraphic = uiSprite;
                uiButton.onClick.AddListener(delegate { FindInJSON(uiButton.name); });

                //build the text child of the button
                GameObject textGO = new GameObject();
                textGO.name = "Text";
                Text text = textGO.AddComponent <Text>();
                text.text  = data.buttons[iterator].title;
                text.font  = defaultFont;
                text.color = Color.white;
                //HACK: missing offset for text...

                //going to need some more positional stuff for the scroll window
                textGO.transform.SetParent(uiButton.gameObject.transform);
                go.transform.SetParent(content.transform);
                go.transform.localPosition = Vector3.zero;

                //adding transform tools
                ButtonTransform bt = go.AddComponent <ButtonTransform>();
                bt.imageWidth  = (int)spriteSize.x;
                bt.imageHeight = (int)spriteSize.y;
                bt.offset      = offsetCounter;
                bt.total       = totalImages;
                offsetCounter++;
            }
            iterator++;
        }
    }
示例#2
0
        private void AddTransformButton() {
            _buttonTransform1 = new ButtonTransform(DesignConfig) {
                Location = new Point(0, DesignConfig.Resources.RetreatSize),
            };
            this._buttonTransform1.Click += this.ButtonTransform1Click1;

            this.Controls.Add(_buttonTransform1);
        }
示例#3
0
        private void AddTransformButton()
        {
            _buttonTransform1 = new ButtonTransform(DesignConfig)
            {
                Text     = "<<<",
                Location = new Point(0, DesignConfig.Resources.RetreatSize),
            };

            this.Controls.Add(_buttonTransform1);
        }