// 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 Start() { var scrollable = new UIScrollableVerticalLayout(10); scrollable.alignMode = UIAbstractContainer.UIContainerAlignMode.Center; scrollable.position = new Vector3(0, -50, 0); var width = UI.scaleFactor * 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 ? -50 : 50; moveBy *= UI.scaleFactor; target.x += moveBy * 2; target.y += moveBy; scrollable.positionTo(0.4f, target, Easing.Quintic.easeIn); _movedContainer = !_movedContainer; }; }
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() { // 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 y = UIRelative.yPercentFrom(UIyAnchor.Top, .05f); var playButton = UIButton.create("playUp.png", "playDown.png", 0, (int)y); playButton.highlightedTouchOffsets = new UIEdgeOffsets(30); playButton.onTouchUpInside += (sender) => Debug.Log("clicked the button: " + sender); // 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; // 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", "progressBarBorder.png", 5, 3, 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)); }