void ProcessXML() { string path = Application.dataPath + "/xml/scene.xml"; // string path = Application.dataPath + "/xml/cars.xml"; if (File.Exists(path)) { Debug.Log("file exits..."); // doc.Load(path); // // XmlElement root = doc.DocumentElement; // XmlNodeList personNodes = root.GetElementsByTagName("AnalyzedFrame"); // // Debug.Log (personNodes.Count); // // frameArray = new AnalyzedFrame[personNodes.Count]; // // int i = 0; // foreach (XmlNode node in personNodes) // { // frameArray [i] = new AnalyzedFrame (); // //// string id = ((XmlElement)node).GetElementsByTagName("Obstacle")[0].Attributes["id"].Value; //获取Name属性值 // XmlNode el = ((XmlElement)node).GetElementsByTagName("Obstacle")[0]; // if (el!=null) { // string id = el.Attributes["id"].Value; // Debug.Log(id); // } // i++; // // } // SceneAnalyzerOutput objs = null; XmlSerializer serializer = new XmlSerializer(typeof(SceneAnalyzerOutput)); StreamReader reader = new StreamReader(path); objs = (SceneAnalyzerOutput)serializer.Deserialize(reader); Debug.Log(objs.AnalyzedFrame [5].Obstacle [1].centralPosition.x); OutPutSVG(50); reader.Close(); } }
public string DrawSVG(float cx, float cy, float radius, float direction) { // string circle = "<circle cx=\"500\" cy=\"250\" r=\"150\" stroke=\"lightgreen\" stroke-width=\"2\" fill=\"none\" stroke-dasharray=\"10 20\" />"; string circle = "<circle cx=" + WrapString(cx.ToString()) + " cy=" + WrapString(cy.ToString()) + " r=" + WrapString(radius.ToString()) + " stroke=" + WrapString("lightgreen") + " stroke-width=" + WrapString("2") + " fill=" + WrapString("none") + " stroke-dasharray=" + WrapString("10 20") + " />"; // string lineLeft = "<line x1=\"500\" y1=\"250\" x2=\"425\" y2=\"120\" style=\"stroke:rgb(255,0,0);stroke-width:2\" stroke-dasharray=\"10 20\" />"; float lineLeft_x2 = cx - Mathf.Cos(Mathf.PI / 3) * radius; float lineLeft_y2 = cy - Mathf.Sin(Mathf.PI / 3) * radius; string lineLeft = "<line x1=" + WrapString(cx.ToString()) + " y1=" + WrapString(cy.ToString()) + " x2=" + WrapString(lineLeft_x2.ToString()) + " y2=" + WrapString(lineLeft_y2.ToString()) + " style=" + WrapString("stroke:rgb(255,0,0);stroke-width:2") + " stroke-dasharray=" + WrapString("10 20") + " />"; float lineRight_x2 = cx + Mathf.Cos(Mathf.PI / 3) * radius; float lineRight_y2 = cy - Mathf.Sin(Mathf.PI / 3) * radius; string lineRight = "<line x1=" + WrapString(cx.ToString()) + " y1=" + WrapString(cy.ToString()) + " x2=" + WrapString(lineRight_x2.ToString()) + " y2=" + WrapString(lineRight_y2.ToString()) + " style=" + WrapString("stroke:rgb(255,0,0);stroke-width:2") + " stroke-dasharray=" + WrapString("10 20") + " />"; // string degree = "<text x=\"500\" y=\"80\" fill=\"red\">0°</text>"; string degree = "<text x=" + WrapString(cx.ToString()) + " y=" + WrapString((cy - radius - 20).ToString()) + " fill=" + WrapString("red") + ">" + direction + "°" + "</text>"; string objs = null; if (direction > 30 && direction < 330) { foreach (DictionaryEntry de in absoluteDirection) //ht为一个Hashtable实例 { Debug.Log(de.Key); //de.Key对应于key/value键值对key Debug.Log(de.Value); //de.Key对应于key/value键值对value if (((float)(de.Value) - direction) >= 0) { float x = cx + Mathf.Cos((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)focusedObstacles [de.Key]).distance * radius / 2; objs += DrawCircle(x, y); } else { float x = cx - Mathf.Cos((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; objs += DrawCircle(x, y); } } } else if (direction >= 330) { foreach (DictionaryEntry de in absoluteDirection) //ht为一个Hashtable实例 { if (((float)(de.Value) - direction) >= 0) { float x = cx + Mathf.Cos((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)focusedObstacles [de.Key]).distance * radius / 2; objs += DrawCircle(x, y); } else { if (Mathf.Abs(((float)(de.Value) - direction)) > 30) { float x = cx + Mathf.Cos((90 - 360 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((90 - 360 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)focusedObstacles [de.Key]).distance * radius / 2; objs += DrawCircle(x, y); } else { float x = cx - Mathf.Cos((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; objs += DrawCircle(x, y); } } } } else { foreach (DictionaryEntry de in absoluteDirection) { if (((float)(de.Value) - direction) <= 0) { float x = cx - Mathf.Cos((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((((float)(de.Value) - direction) + 90) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; objs += DrawCircle(x, y); } else { if (Mathf.Abs(((float)(de.Value) - direction)) > 30) { float x = cx - Mathf.Cos((((float)(de.Value) - direction) + 90 - 360) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((((float)(de.Value) - direction) + 90 - 360) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; objs += DrawCircle(x, y); } else { float x = cx + Mathf.Cos((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)(focusedObstacles [de.Key])).distance * radius / 2; float y = cy - Mathf.Sin((90 + direction - (float)(de.Value)) * Mathf.PI / 180) * ((Obstacle)focusedObstacles [de.Key]).distance * radius / 2; objs += DrawCircle(x, y); } } } } // return circle+lineLeft+lineRight+degree+DrawCircle(500, 200)+DrawRect(520, 150, 7, 7)+DrawTriangle(10,20); return(circle + lineLeft + lineRight + degree + objs); }