void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerAbilities = player.GetComponent <PlayerAbilities>(); abilityImage = this.gameObject.GetComponent <Image>(); selectedAbility = GameObject.Find("SelectedAbility").GetComponent <UIAbility>(); }
public static UIAbility CreateAbilityUI(string key) { uiAbilityPrefab = (uiAbilityPrefab) ? uiAbilityPrefab : Resources.Load <GameObject>(PrefabFileDir.UI_ABILITY_RESOURCE_PATH); // UIAbility newAbility = GameObject.Instantiate(uiAbilityPrefab, UILinks.instance.abilityGridParent).GetComponent <UIAbility>(); newAbility.Initialize(key); return(newAbility); //The above line is creating an object from a prefab, then getting the component from it caleld UIAbility, and returning it, remember this is a static function. }
UILinks ui; //still the same ui links. just a shortcut for less typing public void Initialize(PlayerController _player) { ui = UILinks.instance; player = _player; for (int i = 0; i < player.stats.abilities.Count; i++) { UIAbility.CreateAbilityUI(player.stats.abilities[i].ToString()); } }
public void Load() { foreach (DamageType domain in m_domains) { GameObject domainObject = Instantiate(m_domainPrefab, m_contentParent); domainObject.transform.Find("Icon").GetComponent <Image>().sprite = domain.m_icon; Transform contentParent = domainObject.transform.Find("Scroll View").GetChild(0).GetChild(0); List <AbilityWrapper> sortedDomainAbilities = new List <AbilityWrapper>(m_entity.m_abilities.FindAll(a => a.GetAbility().m_domain == domain.m_name)); sortedDomainAbilities.Sort(new AbilityComparer()); sortedDomainAbilities.Reverse(); foreach (AbilityWrapper wrapper in sortedDomainAbilities) { GameObject abilityObject = Instantiate(m_abilityPrefab, contentParent); Image abilityIcon = abilityObject.GetComponent <Image>(); TextMeshProUGUI trainingLevel = abilityObject.GetComponentInChildren <TextMeshProUGUI>(); Ability ability = wrapper.GetAbility(); abilityIcon.sprite = ability.m_icon; trainingLevel.text = wrapper.TrainingLevel.ToString(); if (!wrapper.Learned) { trainingLevel.text = ""; abilityIcon.color = new Color(1, 1, 1, m_nonLearnedAlpha / 255f); } UIAbility uiAbility = abilityObject.GetComponent <UIAbility>(); uiAbility.m_ability = wrapper; uiAbility.m_loader = this; uiAbility.Init(); m_loadedAbilities.Add(uiAbility); } } }