Untitled
unknown
plain_text
2 days ago
2.1 kB
8
Indexable
using System.Collections.Generic; using UnityEngine; public class SkillNode : MonoBehaviour { public char nodeName; public List<SkillNode> previousNode; public List<SkillNode> nextNode; public bool isActive; public List<LineRenderer> lineRenderers; private void Start() { DrawEdges(); } private void DrawEdges() { // DRAWS EDGES BETWEEN EACH NODE lineRenderers = new List<LineRenderer>(); for (int i = 0; i < nextNode.Count; i++) { GameObject lineObject = new GameObject(nextNode[i].name); lineObject.transform.SetParent(transform); LineRenderer line = lineObject.AddComponent<LineRenderer>(); lineRenderers.Add(line); line.startWidth = 1f; line.endWidth = 1f; line.material = new Material(Shader.Find("Unlit/Color")) { color = Color.white }; line.positionCount = 2; line.SetPosition(0, transform.position); line.SetPosition(1, nextNode[i].transform.position); } } public bool CanBeActivated() { if (PreviousNodeIsActive() || NextNodeIsActive()) { return true; } else { return false; } } /* * If any of the previous nodes are active, through the structure of the graph * this node should also be able to be activated by default */ private bool PreviousNodeIsActive() { // If the node has no previous nodes, this node is a master node if(previousNode.Count == 0) return false; foreach(SkillNode node in previousNode) { if (node.isActive) return true; } return false; } private bool NextNodeIsActive() { // If the node has no next nodes, this node is a leaf node if(nextNode.Count == 0) return false; foreach(SkillNode node in nextNode) { if(node.isActive) return true; } return false; } }
Editor is loading...
Leave a Comment