public GameObject ReplaceNodeWithNewPrefab(WMG_Node theNode, Object prefabNode) { // Used to swap prefabs of a node GameObject newNode = CreateNode(prefabNode, theNode.transform.parent.gameObject); WMG_Node newNode2 = newNode.GetComponent <WMG_Node>(); newNode2.numLinks = theNode.numLinks; newNode2.links = theNode.links; newNode2.linkAngles = theNode.linkAngles; newNode2.SetID(theNode.id); newNode2.name = theNode.name; newNode.transform.position = theNode.transform.position; // Update link from / to node references for (int i = 0; i < theNode.numLinks; i++) { WMG_Link aLink = theNode.links[i].GetComponent <WMG_Link>(); WMG_Node fromN = aLink.fromNode.GetComponent <WMG_Node>(); if (fromN.id == theNode.id) { aLink.fromNode = newNode; } else { aLink.toNode = newNode; } } nodesParent.Remove(theNode.gameObject); Destroy(theNode.gameObject); return(newNode); }
public GameObject CreateNode(Object prefabNode, GameObject parent) { // Creates a node from a prefab, gives a default parent to this object, and adds the node to the manager's list GameObject curObj = Instantiate(prefabNode) as GameObject; Vector3 origScale = curObj.transform.localScale; Vector3 origRot = curObj.transform.localEulerAngles; GameObject theParent = parent; if (parent == null) { theParent = this.gameObject; } changeSpriteParent(curObj, theParent); curObj.transform.localScale = origScale; curObj.transform.localEulerAngles = origRot; WMG_Node curNode = curObj.GetComponent <WMG_Node>(); curNode.SetID(nodesParent.Count); nodesParent.Add(curObj); return(curObj); }
public void DeleteNode(WMG_Node theNode) { // Deleting a node also deletes all of its link and swaps IDs with the largest node ID in the list int idToDelete = theNode.id; foreach (GameObject node in nodesParent) { WMG_Node aNode = node.GetComponent <WMG_Node>(); if (aNode != null && aNode.id == nodesParent.Count - 1) { aNode.SetID(idToDelete); while (theNode.numLinks > 0) { WMG_Link aLink = theNode.links[0].GetComponent <WMG_Link>(); DeleteLink(aLink); } nodesParent.Remove(theNode.gameObject); DestroyImmediate(theNode.gameObject); return; } } }