/*************************** * * * Basic Attack Menu Options * * ***************************/ public void AttackA() { Debug.Log("Doing Attack A"); if (_targetContainer == null) { _targetContainer = Instantiate(targetContainerPrefab, BattleManager.battleCanvas.transform, false); } // Create buttons ONLY if container has no buttons if (_targetContainer.transform.childCount == 0) { List <GameObject> enemies = BattleManager.bm.GetEnemies(); // TODO: Add new buttons at the enemies position foreach (var targetEnemy in enemies) { // Debug.LogFormat("Found target {0}", targetEnemy.name); GameObject newButton = Instantiate(targetButtonPrefab, targetEnemy.transform.position, Quaternion.identity, _targetContainer.transform); TargetButton targetButton = newButton.GetComponent <TargetButton>(); targetButton.target = targetEnemy; Character currentUnit = BattleManager.bm.GetCurrentUnit(); targetButton.AddChooseTargetEventListener(currentUnit.DoAttackA); // Add target to current units attack currentUnit.AddActionListener(AttackTarget); // Debug.LogFormat("newButton: {0}, {1}", newButton.name, newButton.transform.position); } } previousOptions.Push(eventSystem.currentSelectedGameObject); // Add attack A option to previous options SetButtonsInteractable(_attackMenu, false); SetMenuActive(_attackMenu, false); SetMenuActive(_targetContainer, true); SetButtonsInteractable(_targetContainer, true); eventSystem.SetSelectedGameObject(_targetContainer.transform.GetChild(0).gameObject); // Debug.Log("currentSelected " + eventSystem.currentSelectedGameObject.name); }
// Use this for initialization void Start() { targetButtons = new List <TargetButton>(); targetSelectionPanel = GameObject.Find("Canvas").transform.FindChild("Dialogs").FindChild("Target Selection Dialog").gameObject; Transform unites = targetSelectionPanel.transform.FindChild("Unités"); // Récupération des boutons déjà existant et ajout de celui-ci à la liste des premiers. for (int i = 0; i < unites.childCount; i++) { TargetButton button = unites.GetChild(i).GetComponent <TargetButton>(); if (!button.Equals(this)) { targetButtons.Add(button); button.targetButtons.Add(this); } } }
public void ShowTargetMenu(bool targetEnemies) { targetMenu.SetActive(true); skillMenu.SetActive(false); baseMenu.SetActive(false); currentMenu = MenuState.Target; List <GameObject> potentialTargets; int firstIndex = 0; if (targetEnemies) { potentialTargets = enemies; firstIndex = allies.Count; } else { potentialTargets = allies; } for (int i = 0; i < targetMenu.transform.childCount - 1; i++) { if (i >= potentialTargets.Count) { // disable the button if it doesn't correlate to something targetMenu.transform.GetChild(i).gameObject.SetActive(false); } else { targetMenu.transform.GetChild(i).gameObject.SetActive(true); GameObject obj = potentialTargets[i]; Entity e = obj.GetComponent <Entity>(); TargetButton button = targetMenu.transform.GetChild(i).GetComponent <TargetButton>(); button.GetComponentInChildren <Text>().text = e.e_name; button.SetIndex(firstIndex + i); } } }
public void LoadGameButton() { TargetButton.LoadLevel(); loadButton.interactable = false; }
/// <summary> /// Activates this targeting choice, creates the UI objects and checks for input /// </summary> /// <returns></returns> public IEnumerator resolve() { PhaseManager.chosenTarget = null; GameObject prefab = Resources.Load <GameObject>("Prefabs/TargetButton"); float xAverage = 0f; float yHighest = Mathf.NegativeInfinity; //float yHighest = targets[0].Position.y; int count = 0; foreach (Ship t in targets) { if (t == null) { continue; } if (t.Position.y > yHighest) { yHighest = t.Position.y; } xAverage += t.Position.x; GameObject go = GameObject.Instantiate(prefab, t.transform); TargetButton tb = go.GetComponent <TargetButton>(); tb.parent = this; tb.target = t; buttons.Add(tb); count++; } if (count == 0) { yield break; } xAverage = xAverage / targets.Count; prefab = Resources.Load <GameObject>("Prefabs/ChooseText"); GameObject textObj = GameObject.Instantiate(prefab, new Vector2(xAverage, yHighest + 0.6f), Quaternion.identity); textObj.GetComponentInChildren <Text>().text = text; textObj.GetComponent <Canvas>().sortingOrder = 10; //Node targetNode = targets[0].getNode(); //foreach (Ship s in targetNode.Ships) { // s.updateNodePos(0.6f,0.6f); //} while (chosenTarget == null) { yield return(null); } foreach (TargetButton tb in buttons) { GameObject.Destroy(tb.gameObject); } buttons.Clear(); GameObject.Destroy(textObj); PhaseManager.chosenTarget = chosenTarget; if (PhotonNetwork.IsConnected) { PhotonView.Get(GameManager.main).RPC("SyncTargetChoice", RpcTarget.MasterClient, chosenTarget.Id, (int)chosenTarget.team.TeamFaction); } //foreach (Ship s in targetNode.Ships) { // s.updateNodePos(); //} }
/// <summary> /// Overwrites the target button. /// </summary> public void OverwriteTargetButton() { TargetButton.OverwriteLinkedFile(); gameButtonCollection.Sort(); ReattachGameButton(TargetButton); }
public PGeneralButtonUI Initialize(Transform Prototype, int _Index, int LineCapacity, PGeneral _General) { Index = _Index; General = _General; UIBackgroundImage.GetComponentInChildren <Text>().text = General.Name; UIBackgroundImage.localScale = new Vector3(1, 1, 1); UIBackgroundImage.localPosition = new Vector3(70.0f * (Index % LineCapacity) + Prototype.localPosition.x, -70.0f * (Index / LineCapacity) + Prototype.localPosition.y, 0.0f); void InvokeBuyGeneral(Button TargetButton) { string Method = (TargetButton.Equals(PUIManager.GetUI <PGeneralUI>().BuyArchPointButton) ? "成就点" : "银两"); TargetButton.onClick.RemoveAllListeners(); TargetButton.GetComponentInChildren <Text>().text = General.Cost.ToString() + Method + " 购买"; TargetButton.onClick.AddListener(() => { if (!PSystem.UserManager.GeneralList.Contains(General.Name)) { bool CanPurchase = false; if (Method.Equals("成就点") && PSystem.UserManager.ArchPoint >= General.Cost) { PSystem.UserManager.ArchPoint -= General.Cost; CanPurchase = true; } else if (Method.Equals("银两") && PSystem.UserManager.Money >= General.Cost) { PSystem.UserManager.Money -= General.Cost; CanPurchase = true; } if (CanPurchase) { PSystem.UserManager.GeneralList.Add(General.Name); PSystem.UserManager.Write(); UIBackgroundImage.GetComponent <Image>().color = PGeneralUI.Config.GotGeneralColor; PUIManager.GetUI <PGeneralUI>().BuyArchPointButton.interactable = false; PUIManager.GetUI <PGeneralUI>().BuyMoneyButton.interactable = false; } } }); if (PSystem.UserManager.GeneralList.Contains(General.Name)) { TargetButton.interactable = false; } else { TargetButton.interactable = true; } } GeneralButton.onClick.AddListener(() => { PUIManager.GetUI <PGeneralUI>().GeneralInfoInputField.text = General.Name + "\n" + "性别:" + General.Sex + "\n" + "时代:" + General.Age + "\n" + string.Join("\n", General.SkillList.ConvertAll((PSkill Skill) => { PSkillInfo SkillInfo = ListInstance <PSkillInfo>().Find((PSkillInfo Info) => Info.Name.Equals(Skill.Name)); if (SkillInfo == null) { return(Skill.Name); } else { return(Skill.Name + ":" + SkillInfo.ToolTip); } })) + "\n\n" + General.Tips; InvokeBuyGeneral(PUIManager.GetUI <PGeneralUI>().BuyArchPointButton); InvokeBuyGeneral(PUIManager.GetUI <PGeneralUI>().BuyMoneyButton); }); UIBackgroundImage.gameObject.SetActive(true); return(this); }