/// <summary> /// Adds a node to the nodemap /// If no object is selected it adds it and makes it a neighbor of the last node in the map /// If an object is selected, but that object is not a node it does the same as above /// If an object is selected and it is a node it adds the node as a neighbor to the selected node /// </summary> private void OnAddNode() { if (GUILayout.Button("Add Node")) { map.UpdateAllNodes(false); spawnPoint = map.transform.position; spawnOffset = new Vector3(5f, 0f, 0); Node newNode; // If the user is not selecting a node when adding a node then it will be neighbored to the last node added to the list if (selectedNodes == null || selectedNodes.Count == 0) { Debug.Log("A node is not selected"); if (map.NodeList.Count > 0) { spawnPoint = map.NodeList[map.NodeList.Count - 1].transform.position; newNode = map.AddNode(spawnPoint + spawnOffset); } else { spawnPoint = map.transform.position; newNode = map.AddNode(spawnPoint + spawnOffset); } if (map.NodeList.Count > 1) { map.AddNeighbor(newNode, map.NodeList[map.NodeList.Count - 2]); } } else { Debug.Log("A node is selected"); // If the user is selecting a node when adding a node then make the new node the neighbor of the currently selected node spawnPoint = selectedNodes[0].transform.position; newNode = map.AddNode(spawnPoint + spawnOffset); map.AddNeighbor(newNode, selectedNodes[0]); } } }