Button.ButtonClickedEvent CreateOnButtonPressed(Button b, ContestantData cd) { Button.ButtonClickedEvent bcevent = new Button.ButtonClickedEvent(); bcevent.AddListener(() => { b.interactable = false; Team t = holder.Keys.ToList()[currentTeamIndex]; t.AddContestant(cd); b.transform.SetParent(holder[t], worldPositionStays: true); b.transform.localPosition = new Vector3(0f, -t.Contestants.Count * (b.GetComponent <RectTransform>().rect.height * 0.25f)); b.GetComponent <TeamSelectorButton>().originalChildPosition = b.transform.GetSiblingIndex(); b.GetComponent <TeamSelectorButton>().active = true; ColorBlock cb = b.colors; cb.disabledColor = t.Color; b.colors = cb; CheckEndOfList(); }); return(bcevent); }
public void SelectNext(Contestant c) { List <ContestantData> cons = TeamManager.Instance.CurrentTeam.Contestants; if (c != null) { int index = cons.IndexOf(c.Data) + 1; ContestantData posNext = cons [index % cons.Count]; while (c != posNext.Contestant) { posNext = cons [index % cons.Count]; if (posNext.Contestant.ActionsRemaining > 0) { Debug.Log("different contestnat"); StartCoroutine(SelectContestant(posNext.Contestant)); return; } else { index++; } } //if we've reached here, all teammates have run out of actions /* * if (c.ActionsRemaining <= 0) { * GameManager.Instance.NextTurn (); * }*/// we dont do this bc it is instant, and dont wait for any movement to happen } }
void Start() { //generalise Team t1 = new Team("Broncos", new Color(1f, 165f / 256f, 0f), teamLogos[0]); Team t2 = new Team("Raiders", new Color(139f / 256f, 0f, 0139f / 256f), teamLogos[1]); //temp spawn in brand new contestants each time //teamPositions = new Dictionary<Team, Vector3> (); holder = new Dictionary <Team, Transform> (); //teamPositions[t1] = new Vector3(0.6f * selectionButtonPrefab.GetComponent<RectTransform>().rect.width, 0f); //teamPositions[t2] = new Vector3(Screen.width - (0.6f * selectionButtonPrefab.GetComponent<RectTransform>().rect.width), 0f); holder [t1] = mainCanvas.transform.Find("Left Team Canvas"); holder [t2] = mainCanvas.transform.Find("Right Team Canvas"); //Contestant Data has three stats. Do we want ContestantData.NumberStats (static) or only know about it here? //also text field needs to be 20 height, should probably encapsulate float buttonHeight = (5 * 20); int numCols = Mathf.CeilToInt(((buttonHeight * 0.95f) * teamSize * 2) / (Screen.height - 160)); int numRows = Mathf.CeilToInt((teamSize * 2f) / numCols); Font arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; string[] names = new string[] { "Andre", "Bucky", "Chris", "Danny", "Eddy", "Frank", "Gummy", "Harold", "Illy", "James" }; for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { if (i * numCols + j >= (teamSize * 2)) { return; } ContestantData cd = new ContestantData(names [i * numCols + j], (int)(Random.value * 10), (int)(Random.value * 10), (int)(Random.value * 10), 10); GameObject button = Instantiate(selectionButtonPrefab, mainCanvas.transform); RectTransform bRT = button.GetComponent <RectTransform> (); bRT.sizeDelta = new Vector2(bRT.rect.width, buttonHeight); bRT.localPosition = new Vector3((i - ((numRows - 1) / 2f)) * (bRT.rect.width * 1.05f), (Screen.height / 2) - 80 - j * (bRT.rect.height * 1.05f), 0f); DisplayStats(button, cd.Stats, arial); button.GetComponent <Button>().onClick = CreateOnButtonPressed(button.GetComponent <Button>(), cd); } } //potentially unreachable code }
public void SpawnContestant(ContestantData d, Hex startingHex) { //prefab is temp, will load prefab of correct type GameObject go = Instantiate(testContestant, startingHex.Position, testContestant.transform.rotation, transform); go.transform.GetChild(0).GetComponent <MeshRenderer> ().material.color = d.Team.Color; Contestant c = go.GetComponent <Contestant> (); //Here set contestant values in line with data c.CurrentHex = startingHex; c.Position = startingHex.Position; c.Data = d; d.Contestant = c; //UI StatUIManager.Instance.InitLabelUI(c); //Possible Actions if (d.CanShoot) { c.PossibleActions.Add(ContestantActionsFactory.CreateAction <DamagableObject> ("Shoot", ContestantActionsEnum.Shoot, 1f, c, 4, 3f, false)); } Func <ICatcher, bool> throwReqs = (con) => { return(c.Ball != null && con.Ball == null); }; c.PossibleActions.Add(ContestantActionsFactory.CreateAction <ICatcher> ("Throw", ContestantActionsEnum.Throw, 2f, c, (int)(d.Dexerity * 2), 3f, true, throwReqs)); Func <Contestant, bool> checkForBall = (Contestant con) => { return(con.Ball != null); }; c.PossibleActions.Add(ContestantActionsFactory.CreateAction <Contestant> ("Swipe", ContestantActionsEnum.Swipe, 0f, c, 1, 3f, false, checkForBall)); ActionUIManager.Instance.CreateButtonPool(c); }
public void SelectedStatUI(ContestantData cd) { ShowStats(cd, statParent); }
public void AddContestant(ContestantData cd) { contestants.Add(cd); cd.Team = this; }