/// <summary> /// Add a new entry into the dictionary and create a new ResourceUIPrefab to manage /// </summary> /// <param name="resource">Resource to add</param> public void AddResourceUI(Mod_Resource resource) { if (!resource) { return; } // Check if already in the dictionary if (!resourceUIDict.ContainsKey(resource.ResourceName)) { // Check that the parent and prefab being used are valid if (ResourceUIPrefab && ResourceUIOwner) { // Create a new prefab and set the parent resourcePrefab = Instantiate(ResourceUIPrefab, ResourceUIOwner.transform); resourceDisplay = Helper.GetComponent <UIDisplay>(resourcePrefab); // Add the display to the dictionary if (resourceDisplay) { resourceDisplay.InitialiseUI(resource.ResourceIcon, ""); resourceUIDict.Add(resource.ResourceName, resourceDisplay); } } } }
/// <summary> /// Create and set up a UI prefab for displaying an AIAction /// </summary> /// <param name="parent">The parent GameObject to bind to</param> /// <param name="prefab">The prefab to instantiate</param> /// <param name="action">The AIAction to display</param> /// <param name="text">The text to display</param> void CreateActionUI(GameObject parent, GameObject prefab, AIAction action, string text = "") { if (Helper.IsNullOrDestroyed <GameObject>(parent) || Helper.IsNullOrDestroyed <GameObject>(prefab) || Helper.IsNullOrDestroyed <AIAction>(action)) { return; } // Create prefab instance prefab = Instantiate(prefab, parent.transform); // Get the ActionUI component from the prefab instance UIDisplay actionUI = Helper.GetComponent <UIDisplay>(prefab); // Add the prefab instance to the list to display DisplayedActions.Add(prefab); if (actionUI) { actionUI.InitialiseUI(action.ActionIcon, action.ActionName, text); } }