/// <summary> /// Displays the properties of the given MapElement, with the given priority, using as header the given name /// </summary> /// <param name="selectedMapElement">The MapElement to show the needs of </param> /// <param name="groupNeedPriority">The priority of the properties to display in this group</param> /// <param name="groupName">The displayed text in the header of the need group</param> public void Setup(MapElement selectedMapElement, Property.NeedPriority groupNeedPriority, string groupName) { mapElementNameText.text = groupName; List <PropertyOwnership> needs = selectedMapElement.propertyManager.GetPropertiesWithPriority(groupNeedPriority); if (needs == null) { return; } Debug.Log($"Setting up UI for group of needs (Properties) with length {needs.Count}:\n ● {needs.ToStringAllElements("\n ● ")}\n", gameObject); // Instantiate missing UI elements int missingUIElements = needs.Count - propertyUIs.Count; for (int e = 0; e < missingUIElements; e++) { GameObject spawnedPropertyUI = Instantiate(propertyUIPrefab, propertiesArea.transform); PropertyUI propertyUI = spawnedPropertyUI.GetComponentRequired <PropertyUI>(); propertyUIs.Add(propertyUI); } // Configure the UI elements for (int e = 0; e < propertyUIs.Count; e++) { PropertyOwnership propertyOwnershipToDisplay = needs.Count > e ? needs[e] : null; propertyUIs[e].Setup(propertyOwnershipToDisplay); } }
/// <summary> /// Looks for all the Properties that have the same level of priority as the given one /// </summary> /// <param name="priority">The priority that all the returned Properties must have</param> /// <returns>A list of PropertyOwnership where all Properties have the given level of priority</returns> public List <PropertyOwnership> GetPropertiesWithPriority(Property.NeedPriority priority) { List <PropertyOwnership> matchingPropertyOwnerships = new List <PropertyOwnership>(); foreach (PropertyOwnership propertyOwnership in this.propertyOwnerships) { if (propertyOwnership.property.needPriority == priority) { matchingPropertyOwnerships.Add(propertyOwnership); } } return(matchingPropertyOwnerships); }