void createAudioButton() { audioButton = UIToggleButton.create("audio_on.png", "audio_off.png", "audio_on.png", 0, 0); audioButton.onToggle += onToggleAudioButton; audioButton.selected = AudioListener.pause; audioButton.positionFromTopLeft(0.01f, 0.01f); }
void HandlePipsOnSelect (UIRadioButtonGroup sender, UIToggleButton selected) { print ("pips selection changed"); int pageIndex = Mathf.RoundToInt( 20f / sender.NumberOfChildren * sender.IndexOfCurrentlySelected ); m_scrollable.scrollToPage(pageIndex); }
void HandlePipsOnSelect(UIRadioButtonGroup sender, UIToggleButton selected) { print("pips selection changed"); int pageIndex = Mathf.RoundToInt(20f / sender.NumberOfChildren * sender.IndexOfCurrentlySelected); m_scrollable.scrollToPage(pageIndex); }
void HandleToggleonToggle(UIToggleButton sender, bool selected) { if (m_currentlySelected == sender) { return; } m_currentlySelected = sender; UpdateToggleStates(); DispatchChangeEvent(); }
void toggleMusic(UIToggleButton sender) { if (sender.selected) { audioplay.setMusicMode(true); } else { audioplay.setMusicMode(false); } }
void toggleSound(UIToggleButton sender) { if (sender.selected) { audioplay.setSoundMode(true); } else { audioplay.setSoundMode(false); } }
private void onToggleAudioButton(UIToggleButton sender, bool selected) { if (selected) { PlayerPrefs.SetInt("Audio", 0); } // TODO: Disattiva una eventuale musica else { PlayerPrefs.SetInt("Audio", 1); } // TODO: Riattiva una eventuale musica }
void Start() { // IMPORTANT: depth is 1 on top higher numbers on the bottom. This means the lower the number is the closer it gets to the camera. var playButton = UIButton.create("playUp.png", "playDown.png", 0, 0); playButton.highlightedTouchOffsets = new UIEdgeOffsets(30); // Scores button var scores = UIContinuousButton.create("scoresUp.png", "scoresDown.png", 0, 0); scores.highlightedTouchOffsets = new UIEdgeOffsets(30); scores.touchDownSound = scoresSound; // Options button var optionsButton = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0); optionsButton.touchDownSound = optionsSound; // Knob var knob = UIKnob.create("knobUp.png", "knobDown.png", 0, 0); knob.highlightedTouchOffsets = new UIEdgeOffsets(30); knob.value = 0.3f; // Toggle Button var toggleButton = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); toggleButton.selected = true; // HorizontalLayout var hBox = new UIHorizontalLayout(20); hBox.addChild(playButton, scores, optionsButton); // VerticalLayout var vBox = new UIVerticalLayout(20); vBox.addChild(knob, toggleButton); vBox.matchSizeToContentSize(); vBox.positionFromTopRight(0, 0); // Layouts can be animated like any UIObject StartCoroutine(animatePanel(hBox)); }
public void onTouchAudioBtn(UIToggleButton sender, bool toggle) { //toggle audio on / off Debug.Log(toggle); if (toggle) { AudioListener.volume = 0; PlayerPrefs.SetInt("volume", 1); } else { AudioListener.volume = 1; PlayerPrefs.SetInt("volume", 2); } }
void UpdateToggleStates() { foreach (UISprite child in _children) { UIToggleButton toggle = child as UIToggleButton; if (toggle == m_currentlySelected) { toggle.selected = true; toggle.disabled = true; } else { toggle.selected = false; toggle.disabled = false; } } }
public override void addChild(params UISprite[] children) { foreach (UISprite child in children) { if (child is UIToggleButton) { UIToggleButton toggle = child as UIToggleButton; toggle.onToggle += HandleToggleonToggle; } else { UnityEngine.Debug.LogWarning(child.GetType() + " is not a UIToggleButton and will not be added to the radio group"); } } base.addChild(children); }
private IEnumerator createOptionsMenu() { Debug.Log("Create OptionsMenu"); currentPage = PageOLD.Options; if (audioLabel == null) { // Audio Label audioLabel = UI.firstToolkit.addSprite("RGB_button.png", 0, 0); // Audio Checkbox audioCheckBox = UIToggleButton.create("RGB_slider_thumb.png", "RGB_slider_thumb.png", "RGB_slider_thumb.png", 0, 0); audioCheckBox.parentUIObject = audioLabel; audioCheckBox.onToggle += onToggleAudioButton; // Sens Label sensitivityLabel = UI.firstToolkit.addSprite("RGB_button.png", 0, 0); sensitivityLabel.parentUIObject = audioLabel; // Sens Slider sensitivitySlider = UISlider.create("RGB_slider_thumb.png", "RGB_slider_bar.png", 0, 0, UISliderLayout.Horizontal, 1, true); if (PlayerPrefs.HasKey("Sensitivity")) { sensitivitySlider.value = PlayerPrefs.GetFloat("Sensitivity"); } sensitivitySlider.onChange += onSensitivitySliderChanged; // Account button accountButton = UIButton.create("RGB_button.png", "RGB_button.png", 0, 0); accountButton.parentUIObject = audioLabel; accountButton.onTouchUp += onTouchAccountButton; } // Posizioni audioLabel.positionFromTop(0.05f); audioCheckBox.positionFromRight(-0.5f); sensitivityLabel.positionFromBottom(-1.1f); sensitivitySlider.position = sensitivityLabel.position + new Vector3(sensitivityLabel.width, -sensitivityLabel.height / 2, 0.0f); accountButton.positionFromBottom(-2.2f); // Animazione audioLabel.positionFrom(1.0f, new Vector3(-Screen.width, audioLabel.position.y, audioLabel.position.z), Easing.Quartic.easeIn); sensitivitySlider.positionFrom(1.0f, new Vector3(-Screen.width, sensitivitySlider.position.y, sensitivitySlider.position.z), Easing.Quartic.easeIn); yield return(null); }
// Build Options Menu private void BuildOptions() { // Options List box containerOptions = new UIScrollableVerticalLayoutContainer(0); containerOptions.setSize(Screen.width - backButton.width, Screen.height); //scrollable.setSize(width, height); containerOptions.position = new Vector3(backButton.width, 0, 0); //scrollable.position = new Vector3((Screen.width - width) / 2, -Screen.height + height, 0); containerOptions.zIndex = 1; containerOptions.myPadding = backButton.width; UIHorizontalLayoutWrap WrapperColors = new UIHorizontalLayoutWrap(0); UIToggleButton buttonColors = UIToggleButton.create("hexbox_false.png", "hexbox_true.png", "hexbox_down.png", 0, 0); buttonColors.scale *= menuScale; buttonColors.onToggle += (sender, newValue) => buttonOptionsColors(sender, newValue); buttonColors.selected = gameSetup.showColorTransitions; var textColors = text.addTextInstance("Color Transitions", 0, 0); textColors.scale *= menuScale; textColors.color = Color.white; textColors.zIndex = -1; WrapperColors.addChild(buttonColors, textColors); UIHorizontalLayoutWrap WrapperFPS = new UIHorizontalLayoutWrap(0); UIToggleButton buttonFPS = UIToggleButton.create("hexbox_false.png", "hexbox_true.png", "hexbox_down.png", 0, 0); buttonFPS.scale *= menuScale; buttonFPS.onToggle += (sender, newValue) => buttonOptionsFPS(sender, newValue); buttonFPS.selected = gameSetup.showFPS; var textFPS = text.addTextInstance("Show FPS", 0, 0); textFPS.scale *= menuScale; textFPS.color = Color.white; textFPS.zIndex = -1; WrapperFPS.addChild(buttonFPS, textFPS); containerOptions.addChild(WrapperColors, WrapperFPS); }
void buttonOptionsFPS(UIToggleButton sender, bool value) { gameSetup.showFPS = value; }
void CreateScrollableMenuWithPips() { m_scrollable = new UIScrollableHorizontalLayout(20); // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete m_scrollable.beginUpdates(); // if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the // left + right inset is equal to the extra width you set float itemWidth = 250f; float leftInset; float rightInset; leftInset = rightInset = (Screen.width - itemWidth) / 2; m_scrollable.edgeInsets = new UIEdgeInsets(0, Mathf.RoundToInt(leftInset), 0, Mathf.RoundToInt(rightInset)); var scrollerHeight = UI.scaleFactor * itemWidth; var scrollerWidth = UI.scaleFactor * (itemWidth + leftInset + rightInset); // item width + 150 extra width m_scrollable.setSize(scrollerWidth, scrollerHeight); // paging will snap to the nearest page when scrolling m_scrollable.pagingEnabled = true; m_scrollable.pageWidth = itemWidth * UI.scaleFactor; // center the scrollable horizontally m_scrollable.position = new Vector3((Screen.width - scrollerWidth) / 2, -Screen.height + scrollerHeight, 0); for (var i = 0; i < 20; i++) { var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0); m_scrollable.addChild(button); } m_scrollable.endUpdates(); m_scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice //pips var pips = new UIRadioButtonGroup(0, UIAbstractContainer.UILayoutType.Horizontal); int pageCount = Mathf.CeilToInt(20 * itemWidth / scrollerWidth); for (int i = 0; i < pageCount; i++) { var toggle = UIToggleButton.create("emptyUp.png", "emptyDown.png", "emptyUp.png", 0, 0); pips.addChild(toggle); } pips.beginUpdates(); float screenUnits = 1.0f / Screen.width; float halfWidth = 140 * pageCount / 2; float offset = halfWidth * screenUnits; pips.positionFromCenter(-50 * screenUnits, -offset); pips.endUpdates(); pips.OnSelect += HandlePipsOnSelect; pips.IndexOfCurrentlySelected = 1; }
void Start() { text = new UIText(textToolkit, "GhoulishFont", "GhoulishFont_0.png"); startScript = FindObjectOfType(typeof(StartScript)) as StartScript; loader = FindObjectOfType(typeof(loadingScript)) as loadingScript; character = FindObjectOfType(typeof(CharacterMaster)) as CharacterMaster; //DontDestroyOnLoad(this.gameObject); AmmoText = text.addTextInstance("Bullets: " + startScript.Ammunition.ToString(), 0, 0, textScaleFactor, 2, Color.white, UITextAlignMode.Left, UITextVerticalAlignMode.Middle); PickupAmount = text.addTextInstance("+20", 0, 0, textScaleFactor * 5, 2, Color.white, UITextAlignMode.Left, UITextVerticalAlignMode.Middle); PickupAmount.alphaTo(0.1f, 0, Easing.Quartic.easeIn); PickupAmount.hidden = true; LevelInstruc = text.addTextInstance("" + LvlInstructions, 0, 0, textScaleFactor, 2, Color.white, UITextAlignMode.Center, UITextVerticalAlignMode.Middle); LevelInstruc.positionCenter(); LevelInstruc.alphaTo(0.01f, 0, Easing.Quartic.easeIn); StartCoroutine(StartLvlInstruction()); // buttons ------------------------------------ PauseBtn = UIButton.create(buttonUI, "PauseBtn.png", "PauseBtn.png", 0, 0, 10); PauseBtn.positionFromTopLeft(0.035f, 0.045f); PauseBtn.onTouchUpInside += onTouchPauseBtn; PauseBtn.touchDownSound = buttonSound; PauseBtn.hidden = false; PlayBtn = UIButton.create(buttonUI, "PlayBtn.png", "PlayBtn.png", 0, 0, 10); PlayBtn.positionFromCenter(0.2f, -0.21f); PlayBtn.onTouchUpInside += onTouchPlayBtn; PlayBtn.touchDownSound = buttonSound; PlayBtn.hidden = true; RetryBtn = UIButton.create(buttonUI, "RetryBtn.png", "RetryBtn.png", 0, 0, 10); RetryBtn.positionFromCenter(0.2f, -0.07f); RetryBtn.onTouchUpInside += onTouchRetryBtn; RetryBtn.touchDownSound = buttonSound; RetryBtn.hidden = true; QuitBtn = UIButton.create(buttonUI, "QuitBtn.png", "QuitBtn.png", 0, 0, 10); QuitBtn.positionFromCenter(0.2f, 0.07f); QuitBtn.onTouchUpInside += onTouchQuitBtn; QuitBtn.touchDownSound = buttonSound; QuitBtn.hidden = true; //------TOGGLE BTNS------------------------------- AudioBtn = UIToggleButton.create(buttonUI, "AudioOffBtn.png", "AudioBtn.png", "AudioOffBtn.png", 0, 0, 10); AudioBtn.positionFromCenter(0.2f, 0.21f); AudioBtn.onToggle += onTouchAudioBtn; AudioBtn.hidden = true; if (PlayerPrefs.GetInt("volume") == 1) { AudioBtn.selected = true; } //-------------------HEALTH METER-------------------------------------- HealthBG = buttonUI.addSprite("HealthBG.png", 0, 0, 10); HealthBG.positionFromCenter(-0.41f, 0.0f); HealthBar = UIProgressBar.create(buttonUI, "HealthBar.png", 0, 0, false, 5, false); Vector2 tempVec; tempVec = new Vector2(HealthBG.position.x + 95, HealthBG.position.y - 10); HealthBar.position = tempVec; HealthBar.value = 1; //----------------------PICKUPS------------------------- HealthPickup = buttonUI.addSprite("HeartPickup.png", 0, 0, 10); HealthPickup.positionFromCenter(-0.0f, 0.0f); HealthPickup.alphaTo(0.1f, 0, Easing.Quartic.easeIn); HealthPickup.hidden = true; AmmoPickup = buttonUI.addSprite("AmmoPickup.png", 0, 0, 10); AmmoPickup.positionFromCenter(-0.0f, 0.0f); AmmoPickup.alphaTo(0.1f, 0, Easing.Quartic.easeIn); AmmoPickup.hidden = true; //-----------------------------CONTROLS------------------------------------------ LToggle = UIJoystick.create(buttonUI, "LToggle.png", new Rect(Screen.width * 0.01f, Screen.height * 0.45f, Screen.width * 0.4f, Screen.height * 0.6f), Screen.width * 0.175f, Screen.height * -0.3f); LToggle.deadZone = new Vector2(0.8f, 0.8f); //LToggle.setJoystickHighlightedFilename( "LToggleT.png" ); AttackBtn = UIContinuousButton.create("AttackBtn.png", "AttackBtn.png", 0, 0); AttackBtn.positionFromBottomRight(0.05f, 0.05f); AttackBtn.centerize(); // centerize the button so we can scale it from the center AttackBtn.highlightedTouchOffsets = new UIEdgeOffsets(30); AttackBtn.onTouchIsDown += onTouchAttackBtn; AttackBtn.onTouchUpInside += onTouchAttackBtnUp; if (loader != null) { if (loader.ControllerCount > 0) { LToggle.hidden = true; AttackBtn.hidden = true; } } }
void Start() { // add two scrollables: one with paging enabled and one without var scrollable = new UIScrollableHorizontalLayout(10); // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete scrollable.beginUpdates(); var height = UI.scaleFactor * 50f; var width = Screen.width / 1.4f; scrollable.setSize(width, height); scrollable.position = new Vector3((Screen.width - width) / 2, -Screen.height + height, 0); scrollable.zIndex = 3; for (var i = 0; i < 20; i++) { UITouchableSprite touchable; if (i == 4) // text sprite { touchable = UIButton.create("emptyUp.png", "emptyDown.png", 0, 0); } else if (i % 3 == 0) { touchable = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); } else if (i % 2 == 0) { touchable = UIButton.create("playUp.png", "playDown.png", 0, 0); } else { touchable = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0); } if (i == 1) { var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = touchable; ch.pixelsFromRight(0); ch.client.name = "TEST THINGY"; ch.scale = new Vector3(0.5f, 0.5f, 1); } else if (i == 4) { var text = new UIText(textManager, "prototype", "prototype.png"); var helloText = text.addTextInstance("Child Text", 0, 0, 0.5f, -1, Color.blue, UITextAlignMode.Center, UITextVerticalAlignMode.Middle); helloText.parentUIObject = touchable; helloText.positionCenter(); var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = helloText; ch.pixelsFromRight(-16); ch.client.name = "subsub"; ch.scale = new Vector3(0.25f, 0.25f, -2); } // only add a touchUpInside handler for buttons if (touchable is UIButton) { var button = touchable as UIButton; // store i locally so we can put it in the closure scope of the touch handler var j = i; button.onTouchUpInside += (sender) => Debug.Log("touched button: " + j); } // add random spacers every so often if (i % 3 == 0) { scrollable.addChild(new UISpacer(Random.Range(10, 100), 40)); } scrollable.addChild(touchable); } scrollable.endUpdates(); scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice // add another scrollable, this one with paging enabled. scrollable = new UIScrollableHorizontalLayout(20); // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete scrollable.beginUpdates(); height = UI.scaleFactor * 250f; // if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the // left + right inset is equal to the extra width you set scrollable.edgeInsets = new UIEdgeInsets(0, 75, 0, 75); width = UI.scaleFactor * (250f + 150f); // item width + 150 extra width scrollable.setSize(width, height); // paging will snap to the nearest page when scrolling scrollable.pagingEnabled = true; scrollable.pageWidth = 250f * UI.scaleFactor; // center the scrollable horizontally scrollable.position = new Vector3((Screen.width - width) / 2, 0, 0); for (var i = 0; i < 5; i++) { var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0); scrollable.addChild(button); } scrollable.endUpdates(); scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice }
// Use this for initialization void Start() { audioplay = GameObject.FindGameObjectWithTag("SoundLoader").GetComponent <AudioScript>(); if (AudioScript.status == false) { audioplay.PlayMenuMusic(); } var scaleFactor = ScaleFactor.GetScaleFactor(); Time.timeScale = 1; print("Width " + Screen.width + " Height " + Screen.height); //main menu //play game playButton = UIButton.create("PlayBtn_normal.png", "PlayBtn_active.png", 0, 0); playButton.setSize(playButton.width / scaleFactor, playButton.height / scaleFactor); playButton.onTouchUpInside += sender => Application.LoadLevel("Loading"); //view collections of toy darts collectionButton = UIButton.create("CollectionBtn_normal.png", "CollectionBtn_active.png", 0, 0); collectionButton.onTouchUpInside += sender => Application.LoadLevel("collections"); collectionButton.setSize(collectionButton.width / scaleFactor, collectionButton.height / scaleFactor); //store storeButton = UIButton.create("StoreBtn_normal.png", "StoreBtn_active.png", 0, 0); storeButton.onTouchUpInside += sender => Application.LoadLevel("gameStore"); storeButton.setSize(storeButton.width / scaleFactor, storeButton.height / scaleFactor); //high score highScoreButton = UIButton.create("HighScoBtn_normal.png", "HighScoBtn_active.png", 0, 0); highScoreButton.onTouchUpInside += sender => Application.LoadLevel("HS");; highScoreButton.setSize(highScoreButton.width / scaleFactor, highScoreButton.height / scaleFactor); //credits creditsButton = UIButton.create("CreditsBtn_normal.png", "CreditsBtn_activel.png", 0, 0); creditsButton.onTouchUpInside += sender => Application.LoadLevel("credits"); creditsButton.setSize(creditsButton.width / scaleFactor, creditsButton.height / scaleFactor); //post post = UIButton.create("post.png", "post.png", 0, 0); post.setSize(post.width / scaleFactor, post.height / scaleFactor); //sound sound = UIToggleButton.create("sound_normal.png", "sound_mute.png", "sound_active.png", 0, 0); sound.onToggle += (sender, selected) => toggleSound(sender); sound.selected = false; sound.setSize(sound.width / scaleFactor, sound.height / scaleFactor); //music music = UIToggleButton.create("music_normal.png", "music_mute.png", "music_active.png", 0, 0); music.onToggle += (sender, selected) => toggleMusic(sender); music.selected = false; music.setSize(music.width / scaleFactor, music.height / scaleFactor); help = UIButton.create("HelpBtn.png", "HelpBtn.png", 0, 0); help.onTouchUpInside += sender => x++; help.onTouchUpInside += sender => showTutorial(); help.setSize(help.width / scaleFactor, help.height / scaleFactor); originalPosition(); }
void onToggleAudioButton(UIToggleButton sender, bool selected) { AudioListener.pause = selected; }
void buttonOptionsColors(UIToggleButton sender, bool value) { gameSetup.showColorTransitions = value; }
void Start() { var scrollable = new UIScrollableVerticalLayout(10); scrollable.alignMode = UIAbstractContainer.UIContainerAlignMode.Center; scrollable.position = new Vector3(0, -50, 0); var width = UI.isHD ? 300 : 150; scrollable.setSize(width, Screen.height / 1.4f); for (var i = 0; i < 20; i++) { UITouchableSprite touchable; if (i == 4) // text sprite { touchable = UIButton.create("emptyUp.png", "emptyDown.png", 0, 0); } else if (i % 3 == 0) { touchable = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); } else if (i % 2 == 0) { touchable = UIButton.create("playUp.png", "playDown.png", 0, 0); } else { touchable = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0); } // extra flair added by putting some child objects in some of the buttons created above if (i == 1) { // add a toggle button to the first element in the list var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = touchable; ch.pixelsFromRight(0); ch.client.name = "TEST THINGY"; ch.scale = new Vector3(0.5f, 0.5f, 1); } else if (i == 4) { // add some text to the 4th element in the list var text = new UIText(textManager, "prototype", "prototype.png"); var helloText = text.addTextInstance("Child Text", 0, 0, 0.5f, -1, Color.black, UITextAlignMode.Center, UITextVerticalAlignMode.Middle); helloText.parentUIObject = touchable; helloText.positionCenter(); // add a scaled down toggle button as well but this will be parented to the text var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = helloText; ch.pixelsFromRight(-16); ch.client.name = "subsub"; ch.scale = new Vector3(0.25f, 0.25f, 0); } // only add a touchUpInside handler for buttons if (touchable is UIButton) { var button = touchable as UIButton; // store i locally so we can put it in the closure scope of the touch handler var j = i; button.onTouchUpInside += (sender) => Debug.Log("touched button: " + j); } scrollable.addChild(touchable); } // click to scroll to a specific offset var scores = UIButton.create("scoresUp.png", "scoresDown.png", 0, 0); scores.positionFromTopRight(0, 0); scores.highlightedTouchOffsets = new UIEdgeOffsets(30); scores.onTouchUpInside += (sender) => { scrollable.scrollTo(-10, true); }; scores = UIButton.create("scoresUp.png", "scoresDown.png", 0, 0); scores.positionFromBottomRight(0, 0); scores.highlightedTouchOffsets = new UIEdgeOffsets(30); scores.onTouchUpInside += (sender) => { scrollable.scrollTo(-600, true); }; scores = UIButton.create("scoresUp.png", "scoresDown.png", 0, 0); scores.centerize(); scores.positionFromTopRight(0.5f, 0); scores.highlightedTouchOffsets = new UIEdgeOffsets(30); scores.onTouchUpInside += (sender) => { var target = scrollable.position; var moveBy = _movedContainer ? -100 : 100; if (!UI.isHD) { moveBy /= 2; } target.x += moveBy * 2; target.y += moveBy; scrollable.positionTo(0.4f, target, Easing.Quintic.easeIn); _movedContainer = !_movedContainer; }; }
private void SetupSettingsPanel() { panelSettings = new BaseElement { Width = { Percent = 100 }, Height = { Pixels = -28, Percent = 100 }, Y = { Pixels = 28 } }; UIText textWhitelist = new UIText(Language.GetText("Mods.BaseLibrary.UI.Whitelist")) { Y = { Pixels = 8 } }; panelSettings.Add(textWhitelist); buttonsWhitelist = new UIToggleButton[Container is TileEntities.UltimateTeleporter ? 5 : 4]; for (int i = 0; i < buttonsWhitelist.Length; i++) { buttonsWhitelist[i] = new UIToggleButton(Teleportation.whitelist[i], ScaleMode.Zoom) { Size = new Vector2(40), Y = { Pixels = 36 }, X = { Pixels = 48 * i }, Padding = new Padding(6, 6, 6, 6), Toggled = Container.Whitelist[i], HoverText = Language.GetText($"Mods.Teleportation.UI.Whitelist_{i}") }; int pos = i; buttonsWhitelist[i].OnClick += args => { Container.Whitelist[pos] = !Container.Whitelist[pos]; Net.SendTeleporterWhitelist(Container); }; panelSettings.Add(buttonsWhitelist[i]); } UIText textIcon = new UIText(Language.GetText("Mods.BaseLibrary.UI.Icon")) { Y = { Pixels = 84 } }; panelSettings.Add(textIcon); UIIcon buttonIcon = new UIIcon(Container) { Size = new Vector2(40), Y = { Pixels = 112 }, Padding = new Padding(6, 6, 6, 6), HoverText = Language.GetText("Mods.Teleportation.UI.SetIcon").Format(ModContent.ItemType <Pipette>()) }; buttonIcon.OnClick += args => { Pipette pipette = (Pipette)Main.mouseItem.modItem; if (pipette?.icon == null) { return; } Container.Icon = pipette.icon.Clone(); Net.SendTeleporterIcon(Container); Main.PlaySound(SoundID.MenuTick); }; panelSettings.Add(buttonIcon); }
void HandleToggleonToggle (UIToggleButton sender, bool selected) { if(m_currentlySelected == sender) { return; } m_currentlySelected = sender; UpdateToggleStates(); DispatchChangeEvent(); }
void Start() { var scrollable = new UIScrollableVerticalLayout( 10 ); scrollable.position = new Vector3( 0, -50, 0 ); var width = UI.instance.isHD ? 300 : 150; scrollable.setSize( width, Screen.height / 1.4f ); for( var i = 0; i < 20; i++ ) { UITouchableSprite touchable; if( i % 3 == 0 ) { touchable = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 ); } else if( i % 2 == 0 ) { touchable = UIButton.create( "playUp.png", "playDown.png", 0, 0 ); } else { touchable = UIButton.create( "optionsUp.png", "optionsDown.png", 0, 0 ); } // only add a touchUpInside handler for buttons if( touchable is UIButton ) { var button = touchable as UIButton; // store i locally so we can put it in the closure scope of the touch handler var j = i; button.onTouchUpInside += ( sender ) => Debug.Log( "touched button: " + j ); } scrollable.addChild( touchable ); } // click to scroll to a specific offset var scores = UIButton.create( "scoresUp.png", "scoresDown.png", 0, 0 ); scores.positionFromTopRight( 0, 0 ); scores.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); scores.onTouchUpInside += ( sender ) => { scrollable.scrollTo( -10, true ); }; scores = UIButton.create( "scoresUp.png", "scoresDown.png", 0, 0 ); scores.positionFromBottomRight( 0, 0 ); scores.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); scores.onTouchUpInside += ( sender ) => { scrollable.scrollTo( -600, true ); }; scores = UIButton.create( "scoresUp.png", "scoresDown.png", 0, 0 ); scores.centerize(); scores.positionFromTopRight( 0.5f, 0 ); scores.highlightedTouchOffsets = new UIEdgeOffsets( 30 ); scores.onTouchUpInside += ( sender ) => { var target = scrollable.position; var moveBy = _movedContainer ? -100 : 100; if( !UI.instance.isHD ) moveBy /= 2; target.x += moveBy * 2; target.y += moveBy; scrollable.positionTo( 0.4f, target, Easing.Quintic.easeIn ); _movedContainer = !_movedContainer; }; }
void Start() { // IMPORTANT: depth is 1 on top higher numbers on the bottom. This means the lower the number is the closer it gets to the camera. var playButton = UIButton.create("playUp.png", "playDown.png", 0, 0); playButton.positionFromTopLeft(0.05f, 0f); playButton.highlightedTouchOffsets = new UIEdgeOffsets(30); playButton.onTouchUpInside += (sender) => Debug.Log("clicked the button: " + sender); #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER // hover state example for illustration purposes. the playButton will get the scoresDown image when hovered over playButton.hoveredUVframe = UI.firstToolkit.uvRectForFilename("scoresDown.png"); #endif // Scores button var scores = UIContinuousButton.create("scoresUp.png", "scoresDown.png", 0, 0); scores.positionFromTopLeft(.24f, .02f); scores.centerize(); // centerize the button so we can scale it from the center scores.highlightedTouchOffsets = new UIEdgeOffsets(30); scores.onTouchUpInside += onTouchUpInsideScoresButton; scores.onTouchIsDown += (sender) => Debug.Log("touch is down: " + Time.time); scores.touchDownSound = scoresSound; scores.autoRefreshPositionOnScaling = false; // Options button var optionsButton = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0); optionsButton.positionFromTopLeft(.43f, .02f); optionsButton.onTouchUpInside += onTouchUpInsideOptionsButton; optionsButton.touchDownSound = optionsSound; // Knob var knob = UIKnob.create("knobUp.png", "knobDown.png", 0, 0); knob.positionFromTopLeft(.39f, .5f); knob.normalTouchOffsets = new UIEdgeOffsets(10); // give the knob a bit extra touch area knob.highlightedTouchOffsets = new UIEdgeOffsets(30); knob.onKnobChanged += onKnobChanged; knob.value = 0.3f; // Horizontal Slider var hSlider = UISlider.create("sliderKnob.png", "hSlider.png", 0, 0, UISliderLayout.Horizontal); hSlider.positionFromTopLeft(.7f, .02f); hSlider.highlightedTouchOffsets = new UIEdgeOffsets(30, 20, 30, 20); hSlider.onChange += (sender, val) => Debug.Log(val); hSlider.value = 0.6f; // Vertical Slider var vSlider = UISlider.create("vSliderKnob.png", "vSlider.png", 0, 0, UISliderLayout.Vertical); vSlider.positionFromTopRight(.17f, .05f); vSlider.highlightedTouchOffsets = new UIEdgeOffsets(20, 30, 20, 30); vSlider.continuous = true; vSlider.onChange += (sender, val) => Debug.Log(val); vSlider.value = 0.3f; // Toggle Button var toggleButton = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); toggleButton.positionFromTopRight(.3f, .2f); toggleButton.onToggle += (sender, newValue) => hSlider.hidden = !newValue; toggleButton.selected = true; // Progress/Health bar var progressBar = UIProgressBar.create("progressBar.png", 0, 0); progressBar.positionFromBottomLeft(.05f, .02f); progressBar.resizeTextureOnChange = true; progressBar.value = 0.4f; // animated sprite var animatedSprite = UI.firstToolkit.addSprite("Gai_1.png", 0, 0, 1); var anim = animatedSprite.addSpriteAnimation("anim", 0.15f, "Gai_1.png", "Gai_2.png", "Gai_3.png", "Gai_4.png", "Gai_5.png", "Gai_6.png", "Gai_7.png", "Gai_8.png", "Gai_9.png", "Gai_10.png", "Gai_11.png", "Gai_12.png"); animatedSprite.positionFromBottomRight(.0f, .25f); anim.loopReverse = true; // optinally loop in reverse animatedSprite.playSpriteAnimation("anim", 5); // Test movement StartCoroutine(marqueePlayButton(playButton)); StartCoroutine(animateProgressBar(progressBar)); StartCoroutine(pulseOptionButton(optionsButton)); // UIObjects can be used like panels to group other UIObjects var panel = new UIObject(); scores.parentUIObject = panel; optionsButton.parentUIObject = panel; StartCoroutine(animatePanel(panel)); }
void Start() { // add two scrollables: one with pageing enabled var scrollable = new UIScrollableHorizontalLayout(10); // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete scrollable.beginUpdates(); var height = UI.instance.isHD ? 150 : 300; var width = Screen.width / 1.4f; scrollable.setSize(width, height); scrollable.position = new Vector3((Screen.width - width) / 2, -Screen.height + height, 0); scrollable.zIndex = 3; for (var i = 0; i < 20; i++) { UITouchableSprite touchable; if (i == 4) // text sprite { touchable = UIButton.create("emptyUp.png", "emptyDown.png", 0, 0); } else if (i % 3 == 0) { touchable = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); } else if (i % 2 == 0) { touchable = UIButton.create("playUp.png", "playDown.png", 0, 0); } else { touchable = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0); } if (i == 1) { var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = touchable; ch.pixelsFromRight(0); ch.client.name = "TEST THINGY"; ch.scale = new Vector3(0.5f, 0.5f, 1); } else if (i == 4) { var text = new UIText(textManager, "prototype", "prototype.png"); var helloText = text.addTextInstance("Child Text", 0, 0, 0.5f, -1, Color.blue, UITextAlignMode.Center, UITextVerticalAlignMode.Middle); helloText.parentUIObject = touchable; helloText.positionCenter(); var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0); ch.parentUIObject = helloText; ch.pixelsFromRight(-16); ch.client.name = "subsub"; ch.scale = new Vector3(0.25f, 0.25f, -2); } // only add a touchUpInside handler for buttons if (touchable is UIButton) { var button = touchable as UIButton; // store i locally so we can put it in the closure scope of the touch handler var j = i; button.onTouchUpInside += (sender) => Debug.Log("touched button: " + j); } scrollable.addChild(touchable); } scrollable.endUpdates(); scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice // add another scrollable scrollable = new UIScrollableHorizontalLayout(0); // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete scrollable.beginUpdates(); var widthAndHeight = UI.instance.isHD ? 500 : 250; scrollable.setSize(widthAndHeight, widthAndHeight); scrollable.pagingEnabled = true; // paging will snap to the nearest page when scrolling scrollable.position = new Vector3((Screen.width - widthAndHeight) / 2, 0, 0); for (var i = 0; i < 5; i++) { var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0); scrollable.addChild(button); } scrollable.endUpdates(); scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice }
void Start() { mMaxCityRank = 1; mSun = new Sun(); LoadCities(); LoadEarth("Earth-1"); EnableCities(); // Get the Canvas the script is attached to UIElement canvas = new UIElement(gameObject); canvas.AddVerticalLayoutGroup(expandWidth: false, expandHeight: true); // Create a main panel which will include all UI elements UIElement mainPanel = new UIPanel(canvas, "Main Panel"); mainPanel.AddVerticalLayoutGroup(expandWidth: true, padding: new RectOffset(0, 0, 5, 0)); // left, right, top, bottom mainPanel.AddLayoutElement(preferredWidth: 210); // Create a header panel at the top with the title text UIElement titlePanel = new UIEmptyPanel(mainPanel, "Title Panel"); titlePanel.AddVerticalLayoutGroup(expandWidth: true, padding: new RectOffset(5, 5, 0, 0)); // left, right, top, bottom titlePanel.AddLayoutElement(minHeight: 40); new UIText(titlePanel, "UltimaEarth 2.0", fontSize: 18); new UIText(titlePanel, "for uGUI (4.6+)", fontSize: 14); // create a panel for all content below the header panel UIElement contentPanel = new UIPanel(mainPanel, "Content Panel"); contentPanel.AddVerticalLayoutGroup(padding: new RectOffset(5, 5, 5, 0)); // left, right, top, bottom //contentPanel.AddLayoutElement(preferredHeight: 1000); // A group panel is used as a toggle group UIGroupPanel radioGroup = new UIGroupPanel(contentPanel, "Earth Representation"); // The radio buttons will be arranged vertically radioGroup.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(5, 0, 0, 5)); // left, right, top, bottom radioGroup.AddLayoutElement(preferredWidth: 210); UIText header1 = new UIText(radioGroup, "Earth Representation", fontSize: 14); header1.AddLayoutElement(preferredWidth: 200, preferredHeight: 30); header1.SetAlignment(TextAnchor.MiddleCenter); UIToggleButton radio1 = new UIToggleButton(radioGroup, "Natural, Ocean Floor", fontSize: controlFontSize); radio1.AddLayoutElement(preferredWidth: 200); // When a toggle button is attached to the group panel it is turns into a radio group // Sets the intial state of this toggle button to 'on' radio1.SetState(isOn: true); radioGroup.AddToggleButton(radio1); radio1.OnValueChanged((v) => { if (v) { LoadEarth("Earth-1"); } }); UIToggleButton radio2 = new UIToggleButton(radioGroup, "Natural, Ocean Floor, Ice", fontSize: controlFontSize); radio2.AddLayoutElement(preferredWidth: 200); // add the second toggle button to the radio group radioGroup.AddToggleButton(radio2); radio2.OnValueChanged((v) => { if (v) { LoadEarth("Earth-1 Polar Ice"); } }); UIToggleButton radio3 = new UIToggleButton(radioGroup, "Natural", fontSize: controlFontSize); radio3.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio3); radio3.OnValueChanged((v) => { if (v) { LoadEarth("Earth-2"); } }); UIToggleButton radio4 = new UIToggleButton(radioGroup, "Natural, Ice", fontSize: controlFontSize); radio4.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio4); radio4.OnValueChanged((v) => { if (v) { LoadEarth("Earth-2 Polar Ice"); } }); UIToggleButton radio5 = new UIToggleButton(radioGroup, "Hypsometric", fontSize: controlFontSize); radio5.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio5); radio5.OnValueChanged((v) => { if (v) { LoadEarth("Earth-3"); } }); UIToggleButton radio6 = new UIToggleButton(radioGroup, "Hypsometric, Ice", fontSize: controlFontSize); radio6.AddLayoutElement(preferredWidth: 200); radioGroup.AddToggleButton(radio6); radio6.OnValueChanged((v) => { if (v) { LoadEarth("Earth-3 Polar Ice"); } }); //------------------------------------------------------------------- // Parameter Panel UIPanel parmPanel = new UIPanel(contentPanel, "Parameter Panel"); parmPanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(5, 0, 5, 5)); // left, right, top, bottom parmPanel.AddLayoutElement(preferredWidth: 200); UIText header2 = new UIText(parmPanel, "Parameters", fontSize: 14); header2.AddLayoutElement(preferredWidth: 200, preferredHeight: 30); header2.SetAlignment(TextAnchor.MiddleCenter); UIHorizontalSlider slider1 = new UIHorizontalSlider(parmPanel); slider1.SetText("Earth Speed", controlFontSize); slider1.SetValue(mEarth.rotationSpeed); slider1.OnValueChanged((v) => { mEarth.rotationSpeed = v; }); UIHorizontalSlider slider2 = new UIHorizontalSlider(parmPanel); slider2.SetText("Sun Speed", controlFontSize); slider2.SetValue(mSun.rotationSpeed); slider2.OnValueChanged((v) => { mSun.rotationSpeed = v; }); UIHorizontalSlider slider3 = new UIHorizontalSlider(parmPanel); slider3.SetText("Cloud Intensity", controlFontSize); slider3.SetValue(mEarth.cloudIntensity); slider3.OnValueChanged((v) => { mEarth.cloudIntensity = v; }); UIHorizontalSlider slider4 = new UIHorizontalSlider(parmPanel); slider4.SetText("Cloud Speed", controlFontSize); slider4.SetValue(mEarth.cloudSpeed); slider4.OnValueChanged((v) => { mEarth.cloudSpeed = v; }); UIHorizontalSlider slider5 = new UIHorizontalSlider(parmPanel); slider5.SetText("Earth Tilt", controlFontSize); slider5.SetValue(mEarth.tilt); slider5.OnValueChanged((v) => { mEarth.tilt = v; }); UIHorizontalSlider citySlider = new UIHorizontalSlider(parmPanel); citySlider.SetText("Cities", controlFontSize); citySlider.SetMinMaxValue(-1, 8); // -1 means no cities citySlider.SetValue(mMaxCityRank); citySlider.OnValueChanged((v) => { mMaxCityRank = v; EnableCities(); }); //------------------------------------------------------------------- // Info Panel UIPanel infoPanel = new UIPanel(contentPanel, "Info Panel"); infoPanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom infoPanel.AddLayoutElement(preferredWidth: 210); UIText infoText1 = new UIText(infoPanel, "There are many more parameters!", fontSize: 12); infoText1.AddLayoutElement(preferredWidth: 200, preferredHeight: 20); infoText1.SetAlignment(TextAnchor.MiddleCenter); UIText infoText2 = new UIText(infoPanel, "Please refer to the PDF manual.", fontSize: 12); infoText2.AddLayoutElement(preferredWidth: 200, preferredHeight: 20); infoText2.SetAlignment(TextAnchor.MiddleCenter); //------------------------------------------------------------------- // Asset Store Panel UIPanel storePanel = new UIPanel(contentPanel, "Store Panel"); storePanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom storePanel.AddLayoutElement(preferredWidth: 210); UIText storeText = new UIText(storePanel, "Available from the Unity Asset Store:", fontSize: 12); storeText.AddLayoutElement(preferredWidth: 200, preferredHeight: 40); storeText.SetAlignment(TextAnchor.MiddleCenter); UIButton storeButton = new UIButton(storePanel, "http://www.assetstore.unity3d.com", fontSize: 11); storeButton.AddLayoutElement(preferredWidth: 200, preferredHeight: 40); storeButton.OnValueChanged(() => { Application.ExternalEval("window.open('https://www.assetstore.unity3d.com', '_blank')"); }); //------------------------------------------------------------------- // Website Panel UIPanel sitePanel = new UIPanel(contentPanel, "Website Panel"); sitePanel.AddVerticalLayoutGroup(spacing: 0, padding: new RectOffset(2, 5, 5, 5)); // left, right, top, bottom sitePanel.AddLayoutElement(preferredWidth: 210); UIButton siteButton = new UIButton(sitePanel, "(C) Michael Schmeling\nhttp://www.aridocean.com", fontSize: 11); siteButton.AddLayoutElement(preferredWidth: 200, preferredHeight: 55); siteButton.OnValueChanged(() => { Application.ExternalEval("window.open('http://www.aridocean.com', '_blank')"); }); }