Exemplo n.º 1
0
    public static S_OptionSlider CreateSlider(int width)
    {
        GameObject go  = new GameObject("Slider");
        GameObject pip = Primitives.CreateActor(Sprites.pip);
        S_Button   bar = S_Button.CreateButton(Sprites.pixel);

        bar.transform.localScale = new Vector2(width, BAR_HEIGHT);
        bar.GetComponent <BoxCollider2D>().size   = new Vector2(1f, 3.5f);
        bar.GetComponent <SpriteRenderer>().color = Colours.GREEN;


        Util.SetLayer(pip, Util.LayerName.UI, 5);
        pip.transform.SetParent(go.transform, false);
        pip.transform.position = new Vector2((int)(width / 5f * 3), (int)(-Sprites.GetBounds(Sprites.pip).y *S_Camera.scale / 2f + BAR_HEIGHT / 2));
        S_OptionSlider slider = go.AddComponent <S_OptionSlider>();

        slider.width = width;
        bar.transform.SetParent(go.transform, false);
        Util.SetLayer(bar.gameObject, Util.LayerName.UI, 5);
        slider.pipObject = pip.gameObject;
        bar.SetDownAction(() => slider.down = true);
        bar.SetUpAction(() => slider.OnUp());

        S_Camera.SetupScale(pip.transform);
        return(slider);
    }
Exemplo n.º 2
0
    public static GameObject CreatePauseScreen()
    {
        //all this code is a big pile of rubbish, I need to try unity unity ui next time!

        //background
        GameObject pauseScreen = new GameObject("pause_screen");
        GameObject pauseBG     = Primitives.CreateRectangle(pauseWidth, pauseHeight, Colours.RED);

        pauseBG.transform.SetParent(pauseScreen.transform, false);
        BoxCollider2D pausebgcol = pauseBG.AddComponent <BoxCollider2D>();

        pausebgcol.size   = new Vector2(1, 1);
        pausebgcol.offset = new Vector2(.5f, .5f);
        Util.SetLayer(pauseBG, Util.LayerName.UI, 0);
        Util.SetZ(pauseBG, Util.ZLayer.PauseLayer);
        GameObject pauseBGInner = Primitives.CreateRectangle(pauseWidth - border * 2, pauseHeight - border * 2, Colours.DARK);

        pauseBGInner.transform.position = new Vector2(border, border);
        pauseBGInner.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(pauseBGInner, Util.LayerName.UI, 1);
        Util.SetLayer(pauseBG, Util.LayerName.UI, 1);
        pauseScreen.transform.position = new Vector2((int)(Screen.width / 2 - pauseWidth / 2), (int)(Screen.height / 2 - pauseHeight / 2));

        //sliders
        int barWidth = (int)(pauseWidth - border * 2 - gap * 3 - Sprites.GetBounds(Sprites.sound).x *S_Camera.scale);
        int barX     = (int)(border + gap * 2 + Sprites.GetBounds(Sprites.sound).x *S_Camera.scale);
        int currentY = pauseHeight - border;

        currentY            -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.music = S_OptionSlider.CreateSlider(barWidth);
        S_OptionSlider.music.transform.position = new Vector2(barX, currentY);
        S_OptionSlider.music.transform.SetParent(pauseScreen.transform, false);
        Util.SetZ(S_OptionSlider.music.gameObject, Util.ZLayer.Sliders);
        GameObject music = Primitives.CreateActor(Sprites.music);

        S_Camera.SetupScale(music.transform);
        music.transform.position = new Vector2(border + gap, currentY + S_OptionSlider.BAR_HEIGHT / 2 - Sprites.GetBounds(Sprites.music).y *S_Camera.scale / 2);
        music.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(music, Util.LayerName.UI, 50);
        currentY -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.music.SetUpAction(() => { PlayerPrefs.SetFloat("music", S_OptionSlider.music.GetValue()); });
        S_OptionSlider.music.SetRatio(PlayerPrefs.GetFloat("music", .7f));

        S_OptionSlider.sfx = S_OptionSlider.CreateSlider(barWidth);
        S_OptionSlider.sfx.transform.position = new Vector2(barX, currentY);
        S_OptionSlider.sfx.transform.SetParent(pauseScreen.transform, false);
        Util.SetZ(S_OptionSlider.sfx.gameObject, Util.ZLayer.Sliders);
        GameObject sound = Primitives.CreateActor(Sprites.sound);

        S_Camera.SetupScale(sound.transform);
        sound.transform.position = new Vector2(border + gap, currentY + S_OptionSlider.BAR_HEIGHT / 2 - Sprites.GetBounds(Sprites.music).y *S_Camera.scale / 2);
        sound.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(sound, Util.LayerName.UI, 50);
        currentY -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.sfx.SetUpAction(() => { PlayerPrefs.SetFloat("sfx", S_OptionSlider.sfx.GetValue()); });
        S_OptionSlider.sfx.SetRatio(PlayerPrefs.GetFloat("sfx", .7f));

        //icons
        int codeX  = (pauseWidth - border * 2) / 3 + border;
        int musicX = (pauseWidth - border * 2) / 3 * 2 + border;

        int iconY    = currentY;
        int twitterY = (int)(iconY - gap - Sprites.GetBounds(Sprites.twitter).y *S_Camera.scale / 2f);

        iconY += gap / 2;

        GameObject code = Primitives.CreateActor(Sprites.code);

        S_Camera.SetupScale(code.transform);
        code.transform.position = new Vector2(codeX - Sprites.GetBounds(Sprites.code).x *S_Camera.scale / 2f, iconY - Sprites.GetBounds(Sprites.code).y *S_Camera.scale / 2f);
        code.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(code, Util.LayerName.UI, 50);

        music = Primitives.CreateActor(Sprites.music);
        S_Camera.SetupScale(music.transform);
        music.transform.position = new Vector2(musicX - Sprites.GetBounds(Sprites.music).x *S_Camera.scale / 2f, iconY - Sprites.GetBounds(Sprites.music).x *S_Camera.scale / 2f);
        music.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(music, Util.LayerName.UI, 50);


        //bottom info
        S_Button myTwitter = S_Button.CreateButton(Sprites.twitter);

        S_Camera.SetupScale(myTwitter.transform);
        myTwitter.transform.position = new Vector2(codeX - Sprites.GetBounds(Sprites.twitter).x *S_Camera.scale / 2f, twitterY - Sprites.GetBounds(Sprites.twitter).y *S_Camera.scale / 2f);
        myTwitter.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(myTwitter.gameObject, Util.LayerName.UI, 50);
        myTwitter.SetDownAction(() => Application.OpenURL("https://twitter.com/ColourTann"));

        S_Button website = S_Button.CreateButton(Sprites.website);

        S_Camera.SetupScale(website.transform);
        website.transform.position = new Vector2(musicX - Sprites.GetBounds(Sprites.website).x *S_Camera.scale / 2f, twitterY - Sprites.GetBounds(Sprites.website).x *S_Camera.scale / 2f);
        website.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(website.gameObject, Util.LayerName.UI, 50);
        website.SetDownAction(() => Application.OpenURL("http://chriszabriskie.com/"));

        return(pauseScreen);
    }