void link() { linked = true; List <GameObject> li = new List <GameObject> () { }; bool success = all_links_input.TryGetValue(gameObject, out li); if (success) { Debug.Log(li.Count); foreach (GameObject obj in li) { Debug.Log("I am here"); Debug.Log(obj); Debug.Log(this.gameObject); Debug.Log(this.GetComponent <GraphController> ()); Link o = graphControl_link.GenerateLink("specific_src_tgt", gameObject, obj); //LAG IS FROM HERE. if (o != null) { links.Add(o); } } } }
//Method for loading the GraphML layout file private IEnumerator LoadInputFile(string sourceFile) { gameCtrlUI.PanelStatusText.text = "Loading file: " + sourceFile; gameCtrlUI.ProgressBarSetActive(true); gameCtrlUI.ProgressBarValue(0F); //determine which platform to load for string xml = null; if (Application.isWebPlayer) { WWW www = new WWW(sourceFile); yield return(www); xml = www.text; } else { StreamReader sr = new StreamReader(sourceFile); xml = sr.ReadToEnd(); sr.Close(); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); gameCtrlUI.PanelStatusText.text = "Loading Topology"; XmlElement root = xmlDoc.FirstChild as XmlElement; for (int i = 0; i < root.ChildNodes.Count; i++) { XmlElement xmlGraph = root.ChildNodes[i] as XmlElement; int myNodeCount = 0; int myLinkCount = 0; int childCount = xmlGraph.ChildNodes.Count; for (int j = 0; j < childCount; j++) { gameCtrlUI.ProgressBarValue((float)j / (float)childCount * 100F); XmlElement xmlNode = xmlGraph.ChildNodes[j] as XmlElement; //create nodes gameCtrlUI.PanelStatusText.text = "Loading: " + xmlNode.Attributes["id"].Value; if (xmlNode.Name == "node" && myNodeCount < 250) { myNodeCount++; nodesList.Add(new nodeListObj { id = xmlNode.Attributes["id"].Value, name = xmlNode.Attributes["name"].Value, type = xmlNode.Attributes["type"].Value, x = float.Parse(xmlNode.Attributes["x"].Value), y = float.Parse(xmlNode.Attributes["y"].Value), z = float.Parse(xmlNode.Attributes["z"].Value) }); } //create links if (xmlNode.Name == "edge" && myLinkCount < 250) { myLinkCount++; linksList.Add(new linkListObj { id = xmlNode.Attributes["id"].Value, name = xmlNode.Attributes["label"].Value, source = xmlNode.Attributes["source"].Value, target = xmlNode.Attributes["target"].Value }); } //every 100 cycles return control to unity if (j % 100 == 0) { yield return(true); } } } gameCtrlUI.ProgressBarValue(100F); gameCtrlUI.PanelStatusText.text = "Loading done."; gameCtrlUI.ProgressBarValue(0F); gameCtrlUI.ProgressBarSetActive(false); gameCtrlUI.PanelStatusText.text = "Generating graph..."; foreach (nodeListObj genNode in nodesList) { // Create a node on random Coordinates, but with labels graphControl.GenerateNode(genNode.name, genNode.id, genNode.type); } foreach (linkListObj genLink in linksList) { graphControl.GenerateLink("specific_src_tgt", GameObject.Find(genLink.source), GameObject.Find(genLink.target)); } gameCtrlUI.PanelStatusText.text = "Graph done."; }
public void PaintModeController() { // Paint only if not over Panel if (!gameCtrlUI.PanelIsPointeroverPanel(Input.mousePosition)) { // Check what was clicked on when MouseButtonDown if (Input.GetMouseButtonDown(0)) { btnDownPointerPos = Input.mousePosition; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Detected MouseButtonDown. mousePosition: x: " + btnDownPointerPos.x + " y: " + btnDownPointerPos.y + " z: " + btnDownPointerPos.z); } if (graphControl.PaintMode) { //Ray ray = Camera.main.ScreenPointToRay(btnDownPointerPos); //hitObjBtnDown = null; //if (Physics.Raycast(ray, out hitInfoBtnDown)) btnDownHitGo = null; btnDownHitGo = gameCtrlHelper.ScreenPointToRaySingleHitWrapper(Camera.main, btnDownPointerPos); if (btnDownHitGo != null) { //hitObjBtnDown = hitInfoBtnDown.collider.gameObject; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonDown: Ray did hit. On Object: " + btnDownHitGo); } paintedLinkObject = Instantiate(paintedLinkPrefab, new Vector3(0, 0, 0), Quaternion.identity) as paintedLink; paintedLinkObject.name = "paintedLink"; //paintedLinkObject.sourceObj = hitObjBtnDown; //paintedLinkObject.targetVector = hitObjBtnDown.transform.position; paintedLinkObject.sourceObj = btnDownHitGo; paintedLinkObject.targetVector = btnDownHitGo.transform.position; } } } if (Input.GetMouseButton(0) && paintedLinkObject != null && graphControl.PaintMode) { if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Entered GetMouseButton, about to start paintlink()"); } float lazyZ = Camera.main.nearClipPlane + 28; Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, lazyZ)); if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Painting Link. Current mousePosition is: (" + Input.mousePosition.x + ", " + Input.mousePosition.y + ", " + lazyZ + "). Converted worldPosition is: " + mousePosWorld); } paintedLinkObject.targetVector = mousePosWorld; } if (Input.GetMouseButtonUp(0)) { btnUpPointerPos = Input.mousePosition; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Detected MouseButtonUp. mousePosition: x: " + btnUpPointerPos.x + " y: " + btnUpPointerPos.y + " z: " + btnUpPointerPos.z); } if (graphControl.PaintMode) { // Ray ray = Camera.main.ScreenPointToRay(btnUpPointerPos); // hitObjBtnUp = null; // if (Physics.Raycast(ray, out hitInfoBtnUp)) btnUpHitGo = null; btnUpHitGo = gameCtrlHelper.ScreenPointToRaySingleHitWrapper(Camera.main, btnUpPointerPos); if (btnUpHitGo != null) { //hitObjBtnUp = hitInfoBtnUp.collider.gameObject; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonUp: Ray did hit. On Object: " + btnUpHitGo); } // If on ButtonDown a node was rayhit, and on ButtonUp a different nodes, we just want to link these nodes together if (btnDownHitGo != null && (btnDownHitGo != btnUpHitGo)) { if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonUp: ButtonDown node and a differing ButtonUp was selected. This linking the ButtonDown node: " + btnDownHitGo + " with the ButtonUp node: " + btnUpHitGo); } graphControl.GenerateLink("specific_src_tgt", btnDownHitGo, btnUpHitGo); } // if on ButtonDown no node was rayhit, only on ButtonUp, we create new random node, which is connected to the node that was rayhit on ButtonUp else { if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonUp: No ButtonUp node found. Creating new random node connected to this ButtonUp node: " + btnUpHitGo); } //paintNewLinkedNode(hitObjBtnUp); paintNewLinkedNode(btnUpHitGo); } } else { float lazyZ = Camera.main.nearClipPlane + 28; Vector3 clickPosWorld = Camera.main.ScreenToWorldPoint(new Vector3(btnUpPointerPos.x, btnUpPointerPos.y, lazyZ)); if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonDown: Ray did not hit. Creating a node on position: x: " + clickPosWorld.x + " y: " + clickPosWorld.y + " z: " + lazyZ); } // Create a node on specific Coordinates GameObject yetFreeNode = graphControl.GenerateNode(clickPosWorld); if (paintedLinkObject != null) { //graphControl.GenerateLink("specific_src_tgt", hitObjBtnDown, yetFreeNode); graphControl.GenerateLink("specific_src_tgt", btnDownHitGo, yetFreeNode); } } if (paintedLinkObject != null) { GameObject.Destroy(paintedLinkObject.gameObject); } } } } }