Example #1
0
    // Use this for initialization
    void Start()
    {
        var grid = new UIGridLayout(5, 5, 2);

        grid.edgeInsets = new UIEdgeInsets(2);

        //add buttons automagically
        UISprite[] buttons = new UISprite[9];
        for (var i = 0; i < 9; i++)
        {
            var depth  = -(i + 1);
            var button = UIButton.create(UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, depth);
            buttons[i] = button;
        }
        grid.addChild(buttons);

        //add a button in a specific place with fixed width and height
        var anotherButton = UIButton.create(UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, 10);

        //columns and rows are zero based
        grid.AddChildAt(anotherButton, 2, 0, 2, 2);

        //add buttons with snapping
        for (var i = 0; i < 2; i++)
        {
            for (var j = 0; j < 2; j++)
            {
                var button = UIButton.create(UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, 11);
                grid.AddChildAt(button, 2 + i, 2 + j, true);
            }
        }
    }
Example #2
0
	// Use this for initialization
	void Start () 
	{
		var grid = new UIGridLayout(5, 5, 2);
		grid.edgeInsets = new UIEdgeInsets(2);
		
		//add buttons automagically
		UISprite[] buttons = new UISprite[9];
		for (var i=0; i<9; i++)
		{
			var depth = - (i+1);
			var button = UIButton.create( UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, depth);
			buttons[i] = button;
		
		}
		grid.addChild(buttons);
		
		//add a button in a specific place with fixed width and height
		var anotherButton = UIButton.create( UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, 10);
		//columns and rows are zero based
		grid.AddChildAt(anotherButton, 2, 0, 2, 2);
		
		//add buttons with snapping
		for (var i=0; i<2; i++)
		{
			for (var j=0; j<2; j++)
			{
				var button = UIButton.create( UI.firstToolkit, "emptyUp.png", "emptyDown.png", 0, 0, 11);
				grid.AddChildAt(button, 2+i, 2+j, true);
			}
		}
	}
    void Start()
    {
        UITextInfo buttonsTextInfo = new UITextInfo();
        buttonsTextInfo.SetFont(fontLevels).SetFontSize(64).SetColor(new Color(1f, 1f, 1f)).SetTextAlignment(UIAnchorLocation.CENTER);

        UITextInfo buttonsLargerTextInfo = new UITextInfo();
        buttonsLargerTextInfo.SetFont(fontLevels).SetFontSize(80).SetColor(new Color(1f, 1f, 1f)).SetTextAlignment(UIAnchorLocation.CENTER);

        UITextInfo backTextInfo = new UITextInfo();
        backTextInfo.SetFont(fontBack).SetFontSize(24).SetColor(new Color(1f, 1f, 1f)).SetTextAlignment(UIAnchorLocation.LEFT_TOP);

        UITextInfo backTextLargerInfo = new UITextInfo();
        backTextLargerInfo.SetFont(fontBack).SetFontSize(28).SetColor(new Color(1f, 1f, 1f)).SetTextAlignment(UIAnchorLocation.LEFT_TOP);

        UIRelativeLayout rootLayout = new UIRelativeLayout("rootLayout", 0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);

        UIStringLabel backLabelSmall = new UIStringLabel(0.01f, 0.99f, 0.2f, 0.1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_TOP, backTextInfo, "Back");
        UIStringLabel backLabelLarge = new UIStringLabel(0.01f, 0.99f, 0.2f, 0.1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_TOP, backTextLargerInfo, "Back");
        UIStaticButton backButton = new UIStaticButton(0.01f, 0.99f, 0.1f, 0.08f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_TOP, new MenuButtonListener(hover, dehover, "MainMenu"));

        backButton.SetUIComponentIdle(backLabelSmall).SetUIComponentHighlighted(backLabelLarge);

        rootLayout.AddUIComponent(backButton);

        UIGridLayout gridLayout = new UIGridLayout("GridLayout", 0.5f, 0.5f, 0.85f, 0.8f, null, UIAnchorLocation.CENTER, xGridSections, yGridSections);

        for (int n = 0; n < levelNames.Length; ++n)
        {
            UIRelativeLayout highlightedLayout = new UIRelativeLayout(0.015f, 0.05f, 0.97f, 0.90f, null, UIAnchorLocation.LEFT_BOT);

            highlightedLayout.AddUIComponent(new UITextureLabel(0f, 0f, 1f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, levelBorderTexture))
                .AddUIComponent(new UIStringLabel(0f, 0f, 1f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonsLargerTextInfo, "Level " + (n+1)));

            UIRelativeLayout notHighlightedLayout = new UIRelativeLayout(0.015f, 0.05f, 0.97f, 0.90f, null, UIAnchorLocation.LEFT_BOT);

            notHighlightedLayout.AddUIComponent(new UITextureLabel("Level" + (n+1) + "relativeLayout", 0f, 0f, 1f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, levelBorderTexture))
                .AddUIComponent(new UIStringLabel(0f, 0f, 1f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonsTextInfo, "Level " + (n+1)));

            UIStaticButton levelButton = new UIStaticButton(0.015f, 0.05f, 0.97f, 0.90f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, new MenuButtonListener(hover, dehover, levelNames[n]));

            levelButton.SetUIComponentIdle(notHighlightedLayout).SetUIComponentHighlighted(highlightedLayout);

            gridLayout.AddUIComponent(levelButton, n % xGridSections, n / xGridSections, 1, 1);
        }

        rootLayout.AddUIComponent(gridLayout);

        m_panel = new UI(rootLayout);
        m_panel.SetStartMenu(1);

        screenWidth = Screen.width;
        screenHeight = Screen.height;
    }
    void Start()
    {
        menu1Group = new UIGridLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT, 6, 5);

        buttonTextInfo = new UITextInfo();
        buttonTextInfo.SetFontSize(48).SetFontStyle(UIFontStyle.BOLD).SetColor(new Color(1f, 1f, 1f)).SetFont(m_font).SetTextAlignment(UIAnchorLocation.LEFT_MID);

        //		Texture2D menuBackgroundTexture = Resources.Load<Texture2D>("UITextures/MidBackground");
        //		Texture2D menuLeftSideTexture = Resources.Load<Texture2D>("UITextures/LeftSideThing");
        //		Texture2D buttonBorderTexture = Resources.Load<Texture2D>("UITextures/ButtonBorder");

        playButtonLayoutGroupIdle = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);
        playButtonLayoutGroupHighlighted = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);
        tutorialButtonLayoutGroupIdle = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);
        tutorialButtonLayoutGroupHighlighted = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);
        creditsButtonLayoutGroupIdle = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);
        creditsButtonLayoutGroupHighlighted = new UIRelativeLayout(0f, 0f, 1f, 1f, null, UIAnchorLocation.LEFT_BOT);

        playButtonBorderIdle = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);
        playButtonBorderHighlighted = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);
        tutorialButtonBorderIdle = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);
        tutorialButtonBorderHighlighted = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);
        creditsButtonBorderIdle = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);
        creditsButtonBorderHighlighted = new UITextureLabel(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonBorderTexture);

        playButtonStringLabelIdle = new UIStringLabel(0.14f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Play");
        playButtonStringLabelHighlighted = new UIStringLabel(0.24f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Play");
        tutorialButtonStringLabelIdle = new UIStringLabel(0.14f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Tutorial");
        tutorialButtonStringLabelHighlighted = new UIStringLabel(0.24f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Tutorial");
        creditsButtonStringLabelIdle = new UIStringLabel(0.14f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Credits");
        creditsButtonStringLabelHighlighted = new UIStringLabel(0.24f, 0f, 0.8f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, buttonTextInfo, "Credits");

        menuBackgroundLabel = new UITextureLabel(0.5f, 0.5f, 1.2f, 1.2f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.CENTER, menuBackgroundTexture);
        menuLeftSideLabel = new UITextureLabel(0f, 0f, 1f, 1f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, menuLeftSideTexture);

        playButtonLayoutGroupIdle.AddUIComponent(playButtonBorderIdle).AddUIComponent(playButtonStringLabelIdle);
        tutorialButtonLayoutGroupIdle.AddUIComponent(tutorialButtonBorderIdle).AddUIComponent(tutorialButtonStringLabelIdle);
        creditsButtonLayoutGroupIdle.AddUIComponent(creditsButtonBorderIdle).AddUIComponent(creditsButtonStringLabelIdle);

        playButtonLayoutGroupHighlighted.AddUIComponent(playButtonBorderHighlighted).AddUIComponent(playButtonStringLabelHighlighted);
        tutorialButtonLayoutGroupHighlighted.AddUIComponent(tutorialButtonBorderHighlighted).AddUIComponent(tutorialButtonStringLabelHighlighted);
        creditsButtonLayoutGroupHighlighted.AddUIComponent(creditsButtonBorderHighlighted).AddUIComponent(creditsButtonStringLabelHighlighted);

        playButton = new UIStaticButton(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, new DoNothingButtonListener());
        tutorialButton = new UIStaticButton(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, new DoNothingButtonListener());
        creditsButton = new UIStaticButton(0.1f, 0.1f, 0.8f, 0.8f, null, UILayoutType.RELATIVE_LAYOUT, UIAnchorLocation.LEFT_BOT, new DoNothingButtonListener());

        playButton.SetUIComponentIdle(playButtonLayoutGroupIdle).SetUIComponentHighlighted(playButtonLayoutGroupHighlighted);
        tutorialButton.SetUIComponentIdle(tutorialButtonLayoutGroupIdle).SetUIComponentHighlighted(tutorialButtonLayoutGroupHighlighted);
        creditsButton.SetUIComponentIdle(creditsButtonLayoutGroupIdle).SetUIComponentHighlighted(creditsButtonLayoutGroupHighlighted);

        menu1Group.AddUIComponent(menuBackgroundLabel, 1, 1, 4, 3)
            .AddUIComponent(menuLeftSideLabel, 0, 0, 1, 5)
                .AddUIComponent(playButton, 1, 1, 4, 1)
                .AddUIComponent(tutorialButton, 1, 2, 4, 1)
                .AddUIComponent(creditsButton, 1, 3, 4, 1);

        m_ui = new UI(menu1Group);
        m_ui.SetStartMenu(1);

        screenWidth = Screen.width;
        screenHeight = Screen.height;
    }