public void OnSceneGUI() { Event e = Event.current; bool elementClicked = false; if (creator.displayNet) { #region ProcessClickEvent DrawNodeNet(ref elementClicked); if (e.type == EventType.MouseDown && e.button == 0 && !elementClicked) { if (!e.shift) { selectedNode = null; } transformingNode = false; selectedStretch = null; if (e.shift) { Vector3 mouseClickPos = MouseUtility.MouseToFloorRaycast(); Undo.RecordObject(creator, "stretch created"); Node newNode = creator.CreateNode(mouseClickPos); if (selectedNode != null) { Undo.RecordObject(creator, "stretch created"); creator.CreateStretch(selectedNode, newNode); } Undo.RegisterCreatedObjectUndo(newNode.gameObject, "node created" + newNode.name); selectedNode = newNode; } else { selectedNode = null; } } else if (e.type == EventType.Layout) { HandleUtility.AddDefaultControl(0); } #endregion if (selectedNode != null && !transformingNode) { Ray mouseRay = HandleUtility.GUIPointToWorldRay(e.mousePosition); Vector3 rayEnd = mouseRay.GetPoint(Camera.current.nearClipPlane); Handles.DrawLine(selectedNode.Pos, rayEnd); SceneView.RepaintAll(); } } }
public XmlDeserialization(/*string path, */ NodeNetCreator net) { string path = EditorUtility.OpenFilePanel("Open Nodenet xml", Application.dataPath, "xml"); if (File.Exists(path)) { XmlDocument doc = new XmlDocument(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); doc.Load(fs); //"net" node XmlNode netNode = doc.ChildNodes[1]; XmlNode nodesNode = netNode.FirstChild; XmlNode stretchesNode = netNode.LastChild; int nNodes = nodesNode.ChildNodes.Count; int nStretches = stretchesNode.ChildNodes.Count; net.DeleteAllNodes(); List <Stretch> stretches = new List <Stretch>(nStretches); //Nodes for (int n = 0; n < nNodes; n++) { XmlNode node = nodesNode.ChildNodes[n]; float x = float.Parse(node.Attributes["x"].Value); float y = float.Parse(node.Attributes["y"].Value); float z = float.Parse(node.Attributes["z"].Value); net.CreateNode(new Vector3(x, y, z)); } //Stretches for (int s = 0; s < nStretches; s++) { XmlNode stretch = stretchesNode.ChildNodes[s]; int anchorA = int.Parse(stretch.Attributes["a"].Value); int anchorB = int.Parse(stretch.Attributes["b"].Value); Vector3 controlARelativePos; Vector3 controlBRelativePos; //ControlA { XmlNode controlA = stretch.ChildNodes[0]; float x = float.Parse(controlA.Attributes["x"].Value); float y = float.Parse(controlA.Attributes["y"].Value); float z = float.Parse(controlA.Attributes["z"].Value); controlARelativePos = new Vector3(x, y, z); } //ControlB { XmlNode controlB = stretch.ChildNodes[1]; float x = float.Parse(controlB.Attributes["x"].Value); float y = float.Parse(controlB.Attributes["y"].Value); float z = float.Parse(controlB.Attributes["z"].Value); controlBRelativePos = new Vector3(x, y, z); } stretches.Add(new Stretch(anchorA, anchorB, controlARelativePos, controlBRelativePos)); } net.stretches = stretches; fs.Close(); } }