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); }
public Game() { levelNumber = PlayerPrefs.GetInt("level", 0); GameObject background = Primitives.CreateRectangle(Screen.width, Screen.height, Colours.DARK); background.name = "backdrop"; background.transform.SetParent(GetMisc("UI").transform, false); int gap = 5 * S_Camera.scale; mysteryButton = S_Button.CreateButton(Sprites.outline); S_Camera.SetupScale(mysteryButton.transform); mysteryButton.transform.position = new Vector2(gap, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y * S_Camera.scale); mysteryButton.SetDownAction(() => { MysteryButton(); }); mysteryButton.name = "mystery"; mysteryButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(mysteryButton.gameObject, Util.ZLayer.Buttons); S_Button optionsButton = S_Button.CreateButton(Sprites.options); S_Camera.SetupScale(optionsButton.transform); optionsButton.transform.position = new Vector2(gap*2 + Sprites.GetBounds(Sprites.options).x * S_Camera.scale, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y * S_Camera.scale); optionsButton.SetDownAction(()=> { PauseButton(); } ); optionsButton.name = "options_button"; optionsButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(optionsButton.gameObject, Util.ZLayer.Buttons); S_Button restartButton = S_Button.CreateButton(Sprites.restart); S_Camera.SetupScale(restartButton.transform); restartButton.transform.position = new Vector2(gap*3 + Sprites.GetBounds(Sprites.options).x * S_Camera.scale * 2, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y * S_Camera.scale); restartButton.SetDownAction(()=> { RestartButton(); }); restartButton.name = "restart_button"; restartButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(restartButton.gameObject, Util.ZLayer.Buttons); }
public static S_Button CreateInputBlocker() { GameObject go = new GameObject("blocker"); SpriteRenderer sr = go.AddComponent <SpriteRenderer>(); BoxCollider2D collider = go.AddComponent <BoxCollider2D>(); collider.size = new Vector2(Screen.width, Screen.height); collider.offset = new Vector2(Screen.width / 2, Screen.height / 2); S_Button butt = go.AddComponent <S_Button>(); return(butt); }
public static S_Button CreateButton(Sprite sprite) { GameObject result = new GameObject(); SpriteRenderer sr = result.AddComponent <SpriteRenderer>(); sr.sortingLayerName = "UI"; sr.sprite = sprite; S_Button buttonScript = result.AddComponent <S_Button>(); result.AddComponent <BoxCollider2D>(); buttonScript.sr = buttonScript.GetComponent <SpriteRenderer>(); return(buttonScript); }
public void Pause() { if (pauseScreen == null) { inputBlocker = Primitives.CreateInputBlocker(); inputBlocker.SetDownAction(() => { Unpause(); Sounds.PlaySound(Sounds.deselect); }); Util.SetZ(inputBlocker.gameObject, Util.ZLayer.Blocker); pauseScreen = PauseMaker.CreatePauseScreen(); Time.timeScale = 0; } inputBlocker.gameObject.SetActive(true); pauseScreen.SetActive(true); Game.paused = true; }
// Use this for initialization void Start() { iSelectStage = iSelectJiki = 0; SelectJiki.SetActive(true); SelectStage.SetActive(false); Button b_btn = B_Button.GetComponent <Button>(); b_btn.onClick.AddListener(B_ButtonOnClick); Button p_btn = P_Button.GetComponent <Button>(); p_btn.onClick.AddListener(P_ButtonOnClick); Button s_btn = S_Button.GetComponent <Button>(); s_btn.onClick.AddListener(S_ButtonOnClick); Button d_btn = D_Button.GetComponent <Button>(); d_btn.onClick.AddListener(D_ButtonOnClick); Button one_btn = ONE_Button.GetComponent <Button>(); one_btn.onClick.AddListener(One_ButtonOnClick); Button two_btn = TWO_Button.GetComponent <Button>(); two_btn.onClick.AddListener(Two_ButtonOnClick); Button three_btn = THREE_Button.GetComponent <Button>(); three_btn.onClick.AddListener(Three_ButtonOnClick); Button four_btn = FOUR_Button.GetComponent <Button>(); four_btn.onClick.AddListener(Four_ButtonOnClick); Button five_btn = FIVE_Button.GetComponent <Button>(); five_btn.onClick.AddListener(Five_ButtonOnClick); Button return_Button = Return_Button.GetComponent <Button>(); Return_Button.onClick.AddListener(Return_ButtonOnClick); }
public Game() { levelNumber = PlayerPrefs.GetInt("level", 0); GameObject background = Primitives.CreateRectangle(Screen.width, Screen.height, Colours.DARK); background.name = "backdrop"; background.transform.SetParent(GetMisc("UI").transform, false); int gap = 5 * S_Camera.scale; mysteryButton = S_Button.CreateButton(Sprites.outline); S_Camera.SetupScale(mysteryButton.transform); mysteryButton.transform.position = new Vector2(gap, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale); mysteryButton.SetDownAction(() => { MysteryButton(); }); mysteryButton.name = "mystery"; mysteryButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(mysteryButton.gameObject, Util.ZLayer.Buttons); S_Button optionsButton = S_Button.CreateButton(Sprites.options); S_Camera.SetupScale(optionsButton.transform); optionsButton.transform.position = new Vector2(gap * 2 + Sprites.GetBounds(Sprites.options).x *S_Camera.scale, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale); optionsButton.SetDownAction(() => { PauseButton(); }); optionsButton.name = "options_button"; optionsButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(optionsButton.gameObject, Util.ZLayer.Buttons); S_Button restartButton = S_Button.CreateButton(Sprites.restart); S_Camera.SetupScale(restartButton.transform); restartButton.transform.position = new Vector2(gap * 3 + Sprites.GetBounds(Sprites.options).x *S_Camera.scale * 2, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale); restartButton.SetDownAction(() => { RestartButton(); }); restartButton.name = "restart_button"; restartButton.transform.SetParent(GetMisc("UI").transform, false); Util.SetZ(restartButton.gameObject, Util.ZLayer.Buttons); }
public void Setup(int[] headerData) { List <S_Button> buttons = new List <S_Button>(); name = "Ability Panel"; int numAbilities = Util.ProperSign(headerData[0]) + Util.ProperSign(headerData[1]) + Util.ProperSign(headerData[2]); // for (int i = 0; i < headerData.Length; i++) { int datum = headerData[i]; if (datum == 0) { continue; } S_Button buttonScrip = S_Button.CreateButton(Sprites.ability_border); S_Ability ability = null; switch (datum & 3) { case 1: ability = buttonScrip.gameObject.AddComponent <S_Ability_Move3>(); break; case 2: ability = buttonScrip.gameObject.AddComponent <S_Ability_Eye>(); break; case 3: ability = buttonScrip.gameObject.AddComponent <S_Ability_Swap>(); break; } abilities.Add(ability); ability.init((datum & 28) >> 2); buttonScrip.SetDownAction(() => { if (Game.IsPaused()) { return; } ability.Click(); }); GameObject button = buttonScrip.gameObject; button.name = "Button"; Util.SetColour(button, Colours.RED); buttons.Add(button.GetComponent <S_Button>()); S_Camera.SetupScale(buttonScrip.transform); GameObject image = Primitives.CreateActor(ability.GetSprite(), 1, 9); image.name = "image"; Util.SetLayer(image, Util.LayerName.Tiles, 0); image.transform.SetParent(buttonScrip.gameObject.transform, false); if (Game.KEYBOARD) { GameObject text = Primitives.CreateText("[" + ability.GetKey() + "]", 0, 0); S_Follower follower = text.AddComponent <S_Follower>(); follower.Follow(button, -20 * S_Camera.scale, (int)((Sprites.GetBounds(Sprites.ability_border).y *S_Camera.scale / 2f - 7 * S_Camera.scale))); ability.SetText(text); } Util.SetZ(button, Util.ZLayer.Gameplay); } int gap = 10 * S_Camera.scale; int currentY = -gap; foreach (S_Button butt in buttons) { currentY += gap; butt.transform.position = new Vector2(0, currentY); currentY += (int)(butt.GetBounds().size.y); } width = 37 * S_Camera.scale;; height = currentY; foreach (S_Button butt in buttons) { butt.transform.SetParent(transform, false); } }
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); }