public void EnableMinionButtons(bool value, bool forceValue = false) { var btns = _availablesPanel.GetComponentsInChildren <MinionSaleButton>().ToList(); foreach (var item in btns) { item.SetInteractability(forceValue, value); } }
public void CheckForFullfillment() { if (requirementsLayoutGroup.GetComponentsInChildren <Toggle>() .Any(requirement => !requirement.isOn)) { return; } GetComponentInChildren <Button>().interactable = true; }
public void EnableMinionButtons(bool value) { var btns = _availablesPanel.GetComponentsInChildren <Transform>().Where(i => i.GetComponent <Button>() != null); var realBtns = btns.Select(i => i.GetComponent <Button>()); foreach (var item in realBtns) { item.interactable = value; } }
public void Setup() { m_Canvas = GetComponent <Canvas>(); if (!m_Canvas) { Debug.LogAssertion("There is no canvas"); } m_MoveActionButton.onClick.AddListener(delegate { SelectMove(); }); m_CharacterPortrait.onClick.AddListener(delegate { ClickedCharacterPortrait(); }); m_EndTurnButton.onClick.AddListener(delegate { SelectEndTurn(); }); m_SelectCharacterButton.onClick.AddListener(delegate { SelectCharacter(); }); m_DismissCharacterButton.onClick.AddListener(delegate { DismissCharacter(); }); m_ActionButtons = m_ActionBar.GetComponentsInChildren <Button>(); for (int i = 0; i < m_ActionButtons.Length; i++) { int j = i; m_ActionButtons[i].onClick.AddListener(delegate { SelectAction(j); }); } m_InventoryButtons = m_InventoryBar.GetComponentsInChildren <Button>(); for (int i = 0; i < m_InventoryButtons.Length; i++) { int j = i; m_InventoryButtons[i].onClick.AddListener(delegate { SelectInventoryItem(j); }); } }
// Start is called before the first frame update void Start() { HorizontalLayoutGroup group = GetComponentInChildren <HorizontalLayoutGroup>(); healthBars = group.GetComponentsInChildren <RectTransform>(); health = GetComponentInParent <Health>(); health.OnTakeDamage += Health_OnTakeDamage; }
private void Awake() { _horizontalGroup = GetComponent <HorizontalLayoutGroup>(); _rectTransform = GetComponent <RectTransform>(); //initialize any pre-made slots in the scene as part of the pool of slots foreach (hotbarSlotController slot in _horizontalGroup.GetComponentsInChildren <hotbarSlotController>()) { _hotSlotsPool.Add(slot); } }
private void Reset() { grid = GetComponentInChildren <HorizontalLayoutGroup>(); slots = grid.GetComponentsInChildren <ActionbarSlot>(); for (int i = 0; i < slots.Length; i++) { slots[i].name = $"Act Slot {i + 1} + [{slots[i].requireType}]"; slots[i].Set(); slots[i].Awake(); slots[i].Update(); } }
public void LoadSelectList(List <BaseMember> selectList) { currentSelectItems = selectListLayout.GetComponentsInChildren <SelectItem>(); foreach (SelectItem item in currentSelectItems) { item.DestroySelf(); } int count = selectList.Count; for (int i = 0; i < count; i++) { GameObject selectObject = GameObject.Instantiate(selectItemsPanel); selectObject.transform.SetParent(selectListLayout.transform); selectObject.GetComponent <SelectItem>().SetSelectInfo(selectList[i]); } Vector2 size = selectListLayout.GetComponent <RectTransform>().sizeDelta; float sizeWidth = count * (selectItemsPanel.GetComponent <RectTransform>().sizeDelta.x + selectListLayout.spacing); selectListLayout.GetComponent <RectTransform>().sizeDelta = new Vector2(sizeWidth, size.y); selectListLayout.GetComponent <RectTransform>().localPosition = new Vector3(sizeWidth / 2, 0); //TODO可以更简单的恢复到顶部 currentSelectItems = selectListLayout.GetComponentsInChildren <SelectItem>(); }
private void UpdateUpgradeIcons() { Image[] icons = upgradeIcons.GetComponentsInChildren <Image>(); for (int i = 0; i < icons.Length; i++) { if (i < UpgradeLevel) { icons[i].enabled = true; } else { icons[i].enabled = false; } } }
public void ShowUpgradeChoices() { var choices = GetUpgradeChoices(); if (choices == null) { return; } var i = 0; foreach (var view in Container.GetComponentsInChildren <UpgradeView>()) { view.Show(choices[i++]); } }
public void Awake() { tabs = buttons.GetComponentsInChildren <TabScript>(); for (int i = 0; i < tabs.Length; i++) { TabScript tab = tabs[i]; tab.button.onClick.AddListener(() => ChangeTab(tab)); if (i == 0) { defaultTab = tab; selectedTab = tab; } } //gameObject.SetActive(false); }
// PRIVATE private void InitializeListeners(HorizontalLayoutGroup choicesLayout) { if (BoltNetwork.IsServer) { choicesLayout.gameObject.SetActive(true); _toggles = choicesLayout.GetComponentsInChildren <Toggle>(); foreach (var toggle in _toggles) { var choice = toggle.GetComponentInChildren <Label>().String.Value; toggle.onValueChanged.AddListener((b) => { SetChoice(choice); HideChoices(); }); } } }
void Awake() { manager = GameObject.Find("MainObject").GetComponent <ClashGameManager>(); foreach (var species in manager.availableSpecies) { var item = (Instantiate(shopElementPrefab) as GameObject).GetComponent <ClashShopItem>(); item.displayText.text = species.name; var texture = Resources.Load <Texture2D>("Images/" + species.name); item.displayImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); item.addButton.onClick.AddListener(() => { // If item exists in the list already, don't add. foreach (ClashSelectedUnit existing in selectedGroup.GetComponentsInChildren <ClashSelectedUnit>()) { if (existing.label.text == item.displayText.text) { return; } } // If the selected list already contains 5 units, don't add. if (selectedGroup.transform.childCount == 5) { errorCanvas.SetActive(true); errorMessage.text += "Only a total of 5 unique units can be selected"; return; } // Instantiated a selected item prefab and configure it. var selected = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); selected.transform.SetParent(selectedGroup.transform); selected.image.sprite = item.displayImage.sprite; selected.transform.localScale = Vector3.one; selected.label.text = item.displayText.text; selected.remove.onClick.AddListener(() => { Destroy(selected.gameObject); }); }); var description = species.description; var stats = species.Stats(); item.previewButton.onClick.AddListener(() => { previewImage.sprite = item.displayImage.sprite; descriptionText.text = description; statsText.text = stats; infoButton.GetComponentInChildren <Text>().text = "Get Stat Info"; descriptionText.gameObject.SetActive(true); statsText.gameObject.SetActive(false); textSwitch = true; infoButton.onClick.RemoveAllListeners(); infoButton.onClick.AddListener(() => { textSwitch = !textSwitch; if (textSwitch) { infoButton.GetComponentInChildren <Text>().text = "Get Stat Info"; descriptionText.gameObject.SetActive(true); statsText.gameObject.SetActive(false); } else { infoButton.GetComponentInChildren <Text>().text = "Get Description"; descriptionText.gameObject.SetActive(false); statsText.gameObject.SetActive(true); } }); }); switch (species.type) { case SpeciesType.CARNIVORE: item.transform.SetParent(carnivoreGroup.transform); break; case SpeciesType.HERBIVORE: item.transform.SetParent(herbivoreGroup.transform); break; case SpeciesType.OMNIVORE: item.transform.SetParent(omnivoreGroup.transform); break; case SpeciesType.PLANT: item.transform.SetParent(plantGroup.transform); break; default: break; } item.transform.position = new Vector3(item.transform.position.x, item.transform.position.y, 0.0f); item.transform.localScale = Vector3.one; } // If the player has an existing attack configuration, populate the selected unit panel. if (manager.attackConfig != null) { foreach (var species in manager.attackConfig.layout) { var selected = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); var texture = Resources.Load <Texture2D>("Images/" + species.name); selected.transform.SetParent(selectedGroup.transform); selected.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f); selected.transform.localScale = Vector3.one; selected.label.text = species.name; selected.remove.onClick.AddListener(() => { Destroy(selected.gameObject); }); } } }
private void Awake() { bottomButtons = bottomRow.GetComponentsInChildren <CalcButton>(); }
private void SetStarList() { starList = starGrade.GetComponentsInChildren <Image>().ToList(); }
void Start() { this.slots = scoreData.GetComponentsInChildren <Text>(); this.loadScores(); }
void Awake() { manager = GameObject.Find("MainObject").GetComponent <ClashGameManager>(); foreach (var species in manager.availableSpecies) { var item = (Instantiate(shopElementPrefab) as GameObject).GetComponent <ClashShopItem>(); item.displayText.text = species.name; var texture = Resources.Load <Texture2D>("Images/" + species.name); item.displayImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); item.addButton.onClick.AddListener(() => { // If item exists in the list already, don't add. foreach (ClashSelectedUnit existing in selectedGroup.GetComponentsInChildren <ClashSelectedUnit>()) { if (existing.label.text == item.displayText.text) { return; } } // If the user has already selected 5 species, don't add. if (selectedGroup.transform.childCount == 5) { errorCanvas.SetActive(true); errorMessage.text = "A total of 5 units can be selected"; return; } // Instantiated a selected item prefab and configure it. var selected = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); selected.transform.SetParent(selectedGroup.transform); selected.image.sprite = item.displayImage.sprite; selected.transform.localScale = Vector3.one; selected.label.text = item.displayText.text; selected.remove.onClick.AddListener(() => { Destroy(selected.gameObject); }); }); var description = species.description; var stats = species.Stats(); item.previewButton.onClick.AddListener(() => { previewImage.sprite = item.displayImage.sprite; descriptionText.text = description; statsText.text = stats; infoButton.GetComponentInChildren <Text>().text = "Get Stat Info"; descriptionText.gameObject.SetActive(true); statsText.gameObject.SetActive(false); infoButton.interactable = true; textSwitch = true; infoButton.onClick.RemoveAllListeners(); infoButton.onClick.AddListener(() => { textSwitch = !textSwitch; if (textSwitch) { infoButton.GetComponentInChildren <Text>().text = "Get Stat Info"; descriptionText.gameObject.SetActive(true); statsText.gameObject.SetActive(false); } else { infoButton.GetComponentInChildren <Text>().text = "Get Description"; descriptionText.gameObject.SetActive(false); statsText.gameObject.SetActive(true); } }); }); switch (species.type) { case SpeciesType.CARNIVORE: item.transform.SetParent(carnivoreGroup.transform); break; case SpeciesType.HERBIVORE: item.transform.SetParent(herbivoreGroup.transform); break; case SpeciesType.OMNIVORE: item.transform.SetParent(omnivoreGroup.transform); break; case SpeciesType.PLANT: item.transform.SetParent(plantGroup.transform); break; default: break; } item.transform.position = new Vector3(item.transform.position.x, item.transform.position.y, 0.0f); item.transform.localScale = Vector3.one; } // Setup the terrain items list. List <GameObject> terrains = new List <GameObject>(Resources.LoadAll <GameObject>("Prefabs/ClashOfSpecies/Terrains")); foreach (GameObject t in terrains) { var item = (Instantiate(shopElementPrefab) as GameObject).GetComponent <ClashShopItem>(); var texture = Resources.Load <Texture2D>("Images/ClashOfSpecies/" + t.name); item.displayImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); item.displayText.text = t.name; item.addButton.onClick.AddListener(() => { // If a terrain has already been selected, destroy it first. var existing = selectedTerrain.GetComponentInChildren <ClashSelectedUnit>(); if (existing != null) { Destroy(existing.gameObject); } // Add the newly selected terrain object. var selected = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); selected.transform.SetParent(selectedTerrain.transform); selected.transform.position = new Vector3(item.transform.position.x, item.transform.position.y, 0.0f); selected.transform.localScale = Vector3.one; selected.image.sprite = item.displayImage.sprite; selected.label.text = item.displayText.text; selected.remove.onClick.AddListener(() => { Destroy(selected.gameObject); }); }); item.previewButton.onClick.AddListener(() => { previewImage.sprite = item.displayImage.sprite; descriptionText.text = "Terrain"; descriptionText.gameObject.SetActive(true); statsText.gameObject.SetActive(false); infoButton.GetComponentInChildren <Text>().text = "Description"; infoButton.interactable = false; textSwitch = true; infoButton.GetComponentInChildren <Text>().text = "Description"; }); item.transform.SetParent(terrainGroup.transform); item.transform.position = new Vector3(item.transform.position.x, item.transform.position.y, 0.0f); item.transform.localScale = Vector3.one; } // Populate the selected unit and terrain lists if the user has a pending or existing defense configuration. var existingConfig = (manager.pendingDefenseConfig == null) ? (manager.defenseConfig == null) ? null : manager.defenseConfig : manager.pendingDefenseConfig; if (existingConfig != null) { foreach (var pair in existingConfig.layout) { var selected = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); var texture = Resources.Load <Texture2D>("Images/" + pair.Key.name); selected.transform.SetParent(selectedGroup.transform); selected.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); selected.transform.localScale = Vector3.one; selected.label.text = pair.Key.name; selected.remove.onClick.AddListener(() => { Destroy(selected.gameObject); }); } if (existingConfig.terrain != null) { var terrainItem = (Instantiate(selectedUnitPrefab) as GameObject).GetComponent <ClashSelectedUnit>(); var terrainTexture = Resources.Load <Texture2D>("Images/ClashOfSpecies/" + existingConfig.terrain); terrainItem.transform.SetParent(selectedTerrain.transform); terrainItem.transform.position = new Vector3(terrainItem.transform.position.x, terrainItem.transform.position.y, 0.0f); terrainItem.transform.localScale = Vector3.one; terrainItem.image.sprite = Sprite.Create(terrainTexture, new Rect(0, 0, terrainTexture.width, terrainTexture.height), Vector2.one * 0.5f); terrainItem.label.text = existingConfig.terrain; terrainItem.remove.onClick.AddListener(() => { Destroy(terrainItem.gameObject); }); } cancelButton.text = "Return to Main\n(Cancel)"; } }