// Function to display numbers public void ShowListNumber() { RectTransform rectContent = panelContent.GetComponent <RectTransform>(); rectContent.anchoredPosition = new Vector3(0, 0, 0); rectContent.sizeDelta = new Vector2(rectContent.sizeDelta.x, rectContent.sizeDelta.y); float screenWidth = rectContent.sizeDelta.x; float screenHeight = rectContent.sizeDelta.y; draw.RandomPossition(screenWidth, screenHeight, numberCount, positions, marginLeft, marginRight, marginTop, marginBottom, 1, PanelChoiceScript.Instance.Choice_Level); for (int i = 0; i < numberCount; i++) { btn = Instantiate(prefabBtn) as GameObject; rectBtn = btn.GetComponent <RectTransform>(); rectBtn.SetParent(rectContent); rectBtn.localPosition = new Vector3(positions[i].x, positions[i].y, 0); rectBtn.localScale = new Vector3(1f, 1f, 1f); btnScript = btn.GetComponent <ButtonPrefab>(); btnScript.SetInfo((i + 1).ToString(), i + 1); btn.GetComponent <Button>().onClick.AddListener(() => ShowCircle()); } }
public void AddButtons() { for (int i = 0; i < itemList.Count; i++) { Item item = itemList[i]; GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); ButtonPrefab sampleButton = newButton.GetComponent <ButtonPrefab>(); sampleButton.Setup(item, this); } }
protected override void LoadContent() { #if USE_KINECT _kinectChooser.LoadContent(); #endif PrefabRepository.Instance.RegisterPrefab("Robot", RobotPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("DamagedRobot1", DamagedRobot1Prefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Crate", CratePrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Mesh", SimpleMeshPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Camera", CameraPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab(MenuCubePrefab.PrefabName, MenuCubePrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Button", ButtonPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Floor", FloorPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Wall", WallPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("LiftedDoor", LiftedDoorPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Trigger", TriggerPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Saf", SafPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("FloorBridge", FloorBridgePrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("UpgradePlatform", UpgradePlatformPrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("Pipe", PipePrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("SafCollectible", SafCollectiblePrefab.CreatePrefab()); PrefabRepository.Instance.RegisterPrefab("WallBackground", SimpleMeshPrefab.CreatePrefab("models/quad", "WallMaterial", "wall-node")); PrefabRepository.Instance.RegisterPrefab("WallMenu", SimpleMeshPrefab.CreatePrefab("models/quad", "WallMenuMaterial", "wall-node-2")); PrefabRepository.Instance.RegisterPrefab("WallMenu2", SimpleMeshPrefab.CreatePrefab("models/quad", "WallMenuMaterial2", "wall-node-3")); MaterialRepository.Instance.RegisterMaterial("MenuCubeMaterial", args => MenuCubeMaterial.CreateMaterial(args)); MaterialRepository.Instance.RegisterMaterial("SafMaterial", args => SafMaterial.CreateMaterial()); MaterialRepository.Instance.RegisterMaterial("HighlightMaterial", args => HighlightMaterial.CreateMaterial()); // Unlit materials for style2.0 MaterialRepository.Instance.RegisterMaterial("ButtonMaterial", args => TexturedMaterial.CreateMaterial("color_button")); MaterialRepository.Instance.RegisterMaterial("RobotMaterial", args => TexturedMaterial.CreateMaterial("color_robo")); MaterialRepository.Instance.RegisterMaterial("UPlatformMaterial", args => TexturedMaterial.CreateMaterial("color_uplatform")); MaterialRepository.Instance.RegisterMaterial("CrateMaterial", args => TexturedMaterial.CreateMaterial("color_crate")); MaterialRepository.Instance.RegisterMaterial("CelShadingMaterial", args => TexturedMaterial.CreateMaterial("color_crate")); MaterialRepository.Instance.RegisterMaterial("InnerDoorMaterial", args => TexturedMaterial.CreateMaterial("color_door_inner")); MaterialRepository.Instance.RegisterMaterial("OuterDoorMaterial", args => TexturedMaterial.CreateMaterial("color_door_outer")); MaterialRepository.Instance.RegisterMaterial("WallMaterial", args => TexturedMaterial.CreateMaterial("empty_gray")); MaterialRepository.Instance.RegisterMaterial("TileMaterial", args => TexturedMaterial.CreateMaterial("empty_dark_gray")); MaterialRepository.Instance.RegisterMaterial("FloorBridgeMaterial", args => TexturedMaterial.CreateMaterial("color_bridge")); MaterialRepository.Instance.RegisterMaterial("PipeMaterial", args => TexturedMaterial.CreateMaterial("color_pipe")); MaterialRepository.Instance.RegisterMaterial("PowerupSphereMaterial", args => TexturedMaterial.CreateMaterial("empty_dark_gray")); }
private void AddButtons() { GetSongList(); for (int i = 0; i < songList.Count; i++) { string song = songList[i]; GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); ButtonPrefab buttonPrefab = newButton.GetComponent <ButtonPrefab>(); buttonPrefab.Setup(song, this); } //for (int i = 0; i < itemList.Count; i++) //{ // Item item = itemList[i]; // GameObject newButton = buttonObjectPool.GetObject(); // newButton.transform.SetParent(contentPanel); // ButtonPrefab buttonPrefab = newButton.GetComponent<ButtonPrefab>(); // buttonPrefab.Setup(item, this); //} }
// Use this for initialization void Start() { Instance = this; // Set margin by screen size if (((float)Screen.height / (float)Screen.width) < 1.7f) { marginLeft = 25f; marginRight = 25f; } else { marginLeft = 40f; marginRight = 40f; } marginTop = 150f; marginBottom = 25f; // Disable PanelChoice PanelChoice.SetActive(false); draw = gameObject.AddComponent <DrawNumber>(); btnScript = gameObject.AddComponent <ButtonPrefab>(); // Load Best Score of each level BestScoreLV_0 = PlayerPrefs.GetInt(saveBestScoreLV_0, 0); BestScoreLV_1 = PlayerPrefs.GetInt(saveBestScoreLV_1, 0); BestScoreLV_2 = PlayerPrefs.GetInt(saveBestScoreLV_2, 0); BestScoreLV_3 = PlayerPrefs.GetInt(saveBestScoreLV_3, 0); BestScoreLV_4 = PlayerPrefs.GetInt(saveBestScoreLV_4, 0); Gold = PlayerPrefs.GetInt(saveGold, 0); // Set time for each level if (PanelChoiceScript.Instance.Choice_Level == 0) { numberCount = 90; TimeLevel = 16; time = TimeLevel; } if (PanelChoiceScript.Instance.Choice_Level == 1) { numberCount = 100; TimeLevel = 16; time = TimeLevel; } if (PanelChoiceScript.Instance.Choice_Level == 2) { numberCount = 100; TimeLevel = 11; time = TimeLevel; } // Level 2 if (PanelChoiceScript.Instance.Choice_Level == 3) { numberCount = 100; TimeLevel = 501; time = TimeLevel; ImgClock.gameObject.SetActive(false); ImgClockLV3.gameObject.SetActive(true); TxttimeLV3.gameObject.SetActive(true); } // Level 4 Generate_ListRanDomNumber(); count = 0; if (PanelChoiceScript.Instance.Choice_Level == 4) { numberCount = 100; TxtcurrentNumber.text = ListRandomNumber[0].ToString(); TimeLevel = 16; time = TimeLevel; } runTime = true; resetTime = false; // Sound SoundClick = gameObject.AddComponent <AudioSource>(); SoundResult = gameObject.AddComponent <AudioSource>(); SoundResult100 = gameObject.AddComponent <AudioSource>(); isSoundON = UIManagerScript.Instance.isSoundON; isMusicON = UIManagerScript.Instance.isMusicON; AudioClip ClickAudioClip; ClickAudioClip = (AudioClip)Resources.Load("Audio/Click_Number1"); SoundClick.clip = ClickAudioClip; SoundClick.loop = false; AudioClip ResultAudioClip; ResultAudioClip = (AudioClip)Resources.Load("Audio/Result"); SoundResult.clip = ResultAudioClip; SoundResult.loop = false; AudioClip Result100AudioClip; Result100AudioClip = (AudioClip)Resources.Load("Audio/Winner"); SoundResult100.clip = Result100AudioClip; SoundResult100.loop = false; // Show numbers ShowListNumber(); }
// Display circle when click to number and correct private void ShowCircle() { EventSystem ev = eventSystem.GetComponent <EventSystem>(); GameObject btnSelect = ev.currentSelectedGameObject; ButtonPrefab btnScript = btnSelect.GetComponent <ButtonPrefab>(); // If Level 0 or 1 or 2 if (PanelChoiceScript.Instance.Choice_Level == 0 || PanelChoiceScript.Instance.Choice_Level == 1 || PanelChoiceScript.Instance.Choice_Level == 2) { if (btnScript.id - Score == 1) { btnScript.SetCircle(circle); TxtcurrentNumber.text = btnScript.id.ToString(); Score++; if (PanelChoiceScript.Instance.Choice_Level == 0) { Gold += 1; } if (PanelChoiceScript.Instance.Choice_Level == 1) { Gold += 2; } if (PanelChoiceScript.Instance.Choice_Level == 2) { Gold += 5; } resetTime = true; // Play sound when click to correct number if (isSoundON == true) { SoundClick.Play(); } } } // If Level 3 if (PanelChoiceScript.Instance.Choice_Level == 3) { if (btnScript.id - Score == 1) { btnScript.SetCircle(circle); TxtcurrentNumber.text = btnScript.id.ToString(); Score++; Gold += 7; // Play sound when click to correct number if (isSoundON == true) { SoundClick.Play(); } } } // If Level 4 if (PanelChoiceScript.Instance.Choice_Level == 4) { if (btnScript.id == ListRandomNumber[count]) { btnScript.SetCircle(circle); TxtcurrentNumber.text = ListRandomNumber[count + 1].ToString(); Score++; Gold += 10; resetTime = true; count++; // Play sound when click to correct number if (isSoundON == true) { SoundClick.Play(); } } } }
// Hiển thị khoanh tròn private void ShowCircle(int player) { EventSystem ev = eventSystem.GetComponent <EventSystem>(); GameObject btnSelect = ev.currentSelectedGameObject; ButtonPrefab btnScript = btnSelect.GetComponent <ButtonPrefab>(); if (player == 1 && (btnScript.id - tmp) == 1) { listBtnScript1[tmp].SetCircle(circle1); listBtnScript2[tmp].SetCircle(circle1); TxtcurrentNumber1.text = listBtnScript1[tmp].id.ToString(); TxtcurrentNumber2.text = listBtnScript1[tmp].id.ToString(); tmp++; ScorePlayer_1++; if (isSoundON == true) { SoundClick1.Play(); } } if (player == 2 && (btnScript.id - tmp) == 1) { listBtnScript1[tmp].SetCircle(circle2); listBtnScript2[tmp].SetCircle(circle2); TxtcurrentNumber1.text = listBtnScript1[tmp].id.ToString(); TxtcurrentNumber2.text = listBtnScript1[tmp].id.ToString(); tmp++; ScorePlayer_2++; if (isSoundON == true) { SoundClick2.Play(); } } if (tmp == 75) { if (isMusicON == true) { SoundResult.Play(); } if (ScorePlayer_1 > ScorePlayer_2) { PanelResult1.SetActive(true); PanelResult2.SetActive(false); TxtScoreLine_1Win.text = ScorePlayer_1.ToString() + " - " + ScorePlayer_2.ToString(); TxtScoreLine_2Lose.text = ScorePlayer_2.ToString() + " - " + ScorePlayer_1.ToString(); } else if (ScorePlayer_1 < ScorePlayer_2) { PanelResult1.SetActive(false); PanelResult2.SetActive(true); TxtScoreLine_1Lose.text = ScorePlayer_1.ToString() + " - " + ScorePlayer_2.ToString(); TxtScoreLine_2Win.text = ScorePlayer_2.ToString() + " - " + ScorePlayer_1.ToString(); } } }