/// <summary> /// Updates the text to reflect trap count /// </summary> /// <param name="manager">ARSetUp script with the traps</param> public void UpdateTrapCount(ARSetUp manager) { for (int i = 0; i < arUIbuttons.Length; i++) { arUIbuttons[i].GetComponentInChildren <Text>().text = "(" + manager.trapList[i].count + ")"; } }
void RpcDie() { if (!arSetUp) { arSetUp = FindObjectOfType <ARSetUp>(); } arSetUp.SetPhaseTo(GamePhase.Over); CanvasManager.Instance.SetPermanentMessage("AR player wins!"); }
/// <summary> /// Clears the selection of the trap buttons /// </summary> /// <param name="manager">ARSetUp script with the traps</param> public void ClearSelection(ARSetUp manager) { for (int i = 0; i < arUIbuttons.Length; i++) { if (manager.trapList[i].count > 0) { arUIbuttons[i].GetComponent <Button>().interactable = true; } } }
/// <summary> /// Shows the Game Over button /// </summary> /// <param name="manager">The ARSetUp script</param> public void ShowGameOverBtn(ARSetUp manager) { ClearMsg(); gameOverBtn.SetActive(true); gameOverBtn.GetComponent <Button>().onClick.RemoveAllListeners(); gameOverBtn.GetComponent <Button>().onClick.AddListener(() => { manager.ResetGame(); gameOverBtn.SetActive(false); }); }
/// <summary> /// Changes how the UI should look like based on the game phase of the AR Player /// </summary> /// <param name="manager">The SetUp Manager that tells what game phase it is</param> public void SetUpUI(ARSetUp manager) { switch (manager.CurrGamePhase) { //Adds a button to complete scanning phase case GamePhase.Scanning: planeAreaText.gameObject.SetActive(true); planeCountText.gameObject.SetActive(true); ARUI.SetActive(true); if (!doneBtn) { //loops through to find the correct button foreach (Button b in ARUI.GetComponentsInChildren <Button>()) { if (b.gameObject.name == "Done") { doneBtn = b; break; } } } //Callback function after clicking the 'done' button doneBtn.onClick.AddListener(() => { if (manager.CheckAggregrateArea()) { GamePhase nextLvl = (GamePhase)((int)manager.CurrGamePhase + 1); manager.SetPhaseTo(nextLvl); } else { message.SetMessage("Not enough play area! (Recommended: 3+ planes and over 4 units of play area)"); } }); break; //UI for placing traps case GamePhase.Placing: planeAreaText.gameObject.SetActive(false); planeCountText.gameObject.SetActive(false); ARUI.SetActive(true); //activates the 'Done' button doneBtn.gameObject.SetActive(true); //'resets' previously created button if (arUIbuttons != null) { foreach (GameObject obj in arUIbuttons) { Destroy(obj); } } //refills the array of buttons arUIbuttons = new GameObject[manager.trapList.Length]; for (int i = 0; i < manager.trapList.Length; i++) { arUIbuttons[i] = Instantiate(trapButtonPrefab, ARUI.transform); arUIbuttons[i].GetComponent <RectTransform>().anchoredPosition = new Vector2(-20, -100 - i * (trapButtonPrefab.GetComponent <RectTransform>().sizeDelta.y + 40)); arUIbuttons[i].name = "TrapBtn"; arUIbuttons[i].GetComponent <Image>().sprite = manager.trapList[i].image; } //loop through the buttons and hook up events for (int i = 0; i < arUIbuttons.Length; i++) { //variables for scope purposes int num = i; int count = arUIbuttons.Length; GameObject[] arbuttons = arUIbuttons; //callback function UnityAction action = () => { manager.SetCurrTrapSelection(num); //loops through all the buttons for (int j = 0; j < count; j++) { //sets currently selected button to un-interactable if (j == num) { arbuttons[j].GetComponent <Button>().interactable = false; } //sets other buttons (if count > 0) to interactable else if (manager.trapList[j].count > 0) { arbuttons[j].GetComponent <Button>().interactable = true; } } }; arUIbuttons[i].GetComponent <Button>().onClick.AddListener(action); } UpdateTrapCount(manager); break; //Disable UI elements case GamePhase.Playing: ARUI.SetActive(false); //foreach (Button b in ARUI.GetComponentsInChildren<Button>()) // b.gameObject.SetActive(false); break; default: ARUI.SetActive(false); break; } foreach (Text t in ARUI.GetComponentsInChildren <Text>()) { if (t.name == "Phase") { t.text = "Current Phase: " + manager.CurrGamePhase.ToString(); break; } } }
//Init public override void OnStartServer() { manager = FindObjectOfType <ARSetUp>(); }