public ContestantAction(string name, ContestantActionsEnum actionType, Action <float> action, float time, Contestant con, int range, float timeCost, bool friendlyTeam, Func <T, bool> additionalChecks) { this.name = name; this.actionType = actionType; this.action = action; this.time = time; this.caUI = new ContestantActionUI(ContestantActionsFactory.GetSpriteFromType(actionType)); this.controlMode = new TargetSelectorMode <T> (this, con, range, timeCost, friendlyTeam, additionalChecks); }
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); }
//Player button pools public void CreateButtonPool(Contestant con) { con.RegisterOnMoveCompleteCallback((c) => { if (UserControlManager.Instance.Selected == c) { SetButtonListActive(c, true); } }); con.RegisterOnMoveBeganCallback((c) => { if (UserControlManager.Instance.Selected == c) { SetButtonListActive(c, false); } //CheckButtons }); List <GameObject> buttons = new List <GameObject> (); foreach (IContestantAction a in con.PossibleActions) { GameObject buttonBackground = Instantiate(actionButtonPrefab, Vector3.zero, Quaternion.identity, con.transform.Find("Canvas")); GameObject button = buttonBackground.transform.GetChild(0).gameObject; buttons.Add(buttonBackground); buttonBackground.name = con.name + " Button " + a.Name; button.GetComponent <Image> ().sprite = ContestantActionsFactory.GetSpriteFromType(a.ActionType); Button.ButtonClickedEvent bcevent = new Button.ButtonClickedEvent(); bcevent.AddListener(() => { UserControlManager.Instance.ControlMode = a.ControlMode; }); button.GetComponent <Button> ().onClick = bcevent; button.GetComponent <OnEnableCallbacks> ().RegisterOnEnabledConditionCallback(() => { return(a.ControlMode.CheckValidity()); }); button.GetComponent <OnEnableCallbacks> ().RegisterOnEnabledFalseCallback(() => { buttonBackground.GetComponent <CanvasRenderer>().SetAlpha(0.6f); button.GetComponent <Button>().interactable = false; }); button.GetComponent <OnEnableCallbacks> ().RegisterOnEnabledTrueCallback(() => { buttonBackground.GetComponent <CanvasRenderer>().SetAlpha(1.0f); button.GetComponent <Button>().interactable = true; }); } if (buttons.Count > 0) { float totalDist = (1.1f * ((RectTransform)buttons[0].transform).rect.width); float limit = totalDist * (buttons.Count - 1); for (int i = 0; i < buttons.Count; i++) { buttons [i].GetComponent <RectTransform> ().anchoredPosition = new Vector2((i * totalDist) - (limit / 2), 10); } } constantButtonPools[con] = buttons; }