void Start() { // Clear out test categories foreach (Transform child in categoryContainer) { Destroy(child.gameObject); } // Populate categories SkillCategoryBase[] skillCategories = skillTree.GetCategories(); foreach (SkillCategoryBase category in skillCategories) { GameObject go = Instantiate(categoryButtonPrefab); go.transform.SetParent(categoryContainer); go.transform.localScale = Vector3.one; Text txt = go.GetComponentInChildren <Text>(); txt.text = category.displayName; // Dump in a tmp variable to force capture the variable by the event SkillCategoryBase tmpCat = category; go.GetComponent <Button>().onClick.RemoveAllListeners(); go.GetComponent <Button>().onClick.AddListener(() => { ShowCategory(tmpCat); }); } if (skillCategories.Length > 0) { ShowCategory(skillCategories[0]); } }
public void ShowCategory (SkillCategoryBase category) { skillNodes = new List<SkillNode>(); nodeRef = new Dictionary<SkillCollectionBase, SkillNode>(); categoryName.text = string.Format("{0}: Level {1}", category.displayName, category.skillLv); ClearDetails(); CreateGrid(category, cellSize); StartCoroutine(ConnectNodes()); }
public void ShowCategory(SkillCategoryBase category) { skillNodes = new List <SkillNode>(); nodeRef = new Dictionary <SkillCollectionBase, SkillNode>(); categoryName.text = string.Format("{0}: Level {1}", category.displayName, category.skillLv); ClearDetails(); CreateGrid(category, cellSize); StartCoroutine(ConnectNodes()); }
void CreateGrid(SkillCategoryBase category, Vector2 cellSize) { // Clean up pre-existing data foreach (Transform child in nodeContainer) { Destroy(child.gameObject); } foreach (Transform child in lineContainer) { Destroy(child.gameObject); } SkillCollectionGrid grid = category.GetComponentInParent <SkillTreeBase>().GetGrid(category); // Generate container with width and height based on cellSize nodeInnerContainer.sizeDelta = new Vector2(grid.Width * cellSize.x, grid.Height * cellSize.y); // Adjust the container position based on padding, resulting in perfectly aligned grid items RectTransform nodeRect = nodePrefab.GetComponent <RectTransform>(); Vector2 cellPadding = new Vector2((cellSize.x - nodeRect.sizeDelta.x) / 2f, (cellSize.y - nodeRect.sizeDelta.y) / 2f); nodeRef = new Dictionary <SkillCollectionBase, SkillNode>(); // Place all grid items foreach (SkillCollectionGridItem gridItem in grid.GetAllCollections()) { GameObject node = Instantiate(nodePrefab); node.transform.SetParent(nodeContainer); node.transform.localScale = Vector3.one; node.GetComponentInChildren <Text>().text = gridItem.collection.displayName; node.GetComponent <RectTransform>().anchoredPosition = new Vector2((gridItem.x * cellSize.x) + cellPadding.x, (gridItem.y * cellSize.y * -1f) - cellPadding.y); SkillNode skillNode = node.GetComponent <SkillNode>(); skillNode.menu = this; skillNode.skillCollection = gridItem.collection; skillNodes.Add(skillNode); nodeRef.Add(gridItem.collection, skillNode); } }
void CreateGrid (SkillCategoryBase category, Vector2 cellSize) { // Clean up pre-existing data foreach (Transform child in nodeContainer) { Destroy(child.gameObject); } foreach (Transform child in lineContainer) { Destroy(child.gameObject); } SkillCollectionGrid grid = category.GetComponentInParent<SkillTreeBase>().GetGrid(category); // Generate container with width and height based on cellSize nodeInnerContainer.sizeDelta = new Vector2(grid.Width * cellSize.x, grid.Height * cellSize.y); // Adjust the container position based on padding, resulting in perfectly aligned grid items RectTransform nodeRect = nodePrefab.GetComponent<RectTransform>(); Vector2 cellPadding = new Vector2((cellSize.x - nodeRect.sizeDelta.x) / 2f, (cellSize.y - nodeRect.sizeDelta.y) / 2f); nodeRef = new Dictionary<SkillCollectionBase, SkillNode>(); // Place all grid items foreach (SkillCollectionGridItem gridItem in grid.GetAllCollections()) { GameObject node = Instantiate(nodePrefab); node.transform.SetParent(nodeContainer); node.transform.localScale = Vector3.one; node.GetComponentInChildren<Text>().text = gridItem.collection.displayName; node.GetComponent<RectTransform>().anchoredPosition = new Vector2((gridItem.x * cellSize.x) + cellPadding.x, (gridItem.y * cellSize.y * -1f) - cellPadding.y); SkillNode skillNode = node.GetComponent<SkillNode>(); skillNode.menu = this; skillNode.skillCollection = gridItem.collection; skillNodes.Add(skillNode); nodeRef.Add(gridItem.collection, skillNode); } }