How can i create List of maps from each Map class ?
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using UnityEngine;
public class SvgMapReader
{
public void ParseMaps()
{
StreamWriter w = new StreamWriter(@"c:\temp\Rectangles.txt");
//XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawingtest.svg");
XDocument document = XDocument.Load(@"C:\Users\t\Documents\drawing.svg");
Map.Rectangles = document.Descendants().Where(x => x.Name.LocalName == "rect").Select(x => new Map()
{
style = Map.GetStyle((string)x.Attribute("style")),
id = (string)x.Attribute("id"),
width = (double)x.Attribute("width"),
height = (double)x.Attribute("height"),
x = (double?)x.Attribute("x"),
y = (double?)x.Attribute("y"),
matrix = x.Attribute("transform") == null ? "" : (string)x.Attribute("transform")
}).ToList();
for (int i = 0; i < Map.Rectangles.Count; i++)
{
if (Map.Rectangles[i].matrix != null && Map.Rectangles[i].matrix != "")
{
var regex = new Regex(@"matrix\((?<num>-?(?:\d|\.)+)(?:,(?<num>-?(?:\d|\.)+))*\)");
List<double> values = regex.Matches(Map.Rectangles[i].matrix)
.Cast<Match>()
.SelectMany(m => m.Groups["num"]
.Captures
.Cast<Capture>()
.Select(c => c.Value))
.Select(double.Parse)
.ToList();
Map.Rectangles[i].degree = values[0];//degree;
}
w.WriteLine("Rectangle" + i);
w.WriteLine("Degree ===> " + Map.Rectangles[i].degree);
w.WriteLine("Height ===> " + Map.Rectangles[i].height);
w.WriteLine("Width ===> " + Map.Rectangles[i].width);
w.WriteLine("X ===> " + Map.Rectangles[i].x);
w.WriteLine("Y ===> " + Map.Rectangles[i].y);
w.WriteLine("Matrix ===> " + Map.Rectangles[i].matrix);
w.WriteLine(" ");
}
w.Close();
}
public float FindDegree(double a, double b)
{
float value = (float)((System.Math.Atan2(a, b) / System.Math.PI) * 180f);
if (value < 0) value += 360f;
return value;
}
public class Map
{
public static List<Map> Rectangles { get; set; }
public Dictionary<string, string> style { get; set; }
public string id { get; set; }
public double width { get; set; }
public double height { get; set; }
public double? x { get; set; }
public double? y { get; set; }
public string matrix { get; set; }
public double degree { get; set; }
public static Dictionary<string, string> GetStyle(string styles)
{
string pattern = @"(?'name'[^:]+):(?'value'.*)";
string[] splitArray = styles.Split(new char[] { ';' });
Dictionary<string, string> style = splitArray.Select(x => Regex.Match(x, pattern))
.GroupBy(x => x.Groups["name"].Value, y => y.Groups["value"].Value)
.ToDictionary(x => x.Key, y => y.FirstOrDefault());
return style;
}
}
}
In the end i see in the List Rectangles that it have 133 items. But each item is a rectangle.
What i want to do is to create another List and call it Maps. This List should contain each Map and each Map should have Rectangles and when i will look with a break point on each Map Rectangles List it should show me for example on the first item:
[0] {Rectangle 1}
[1] {Rectangle 2}
But now it show me each item name like this:
[0] {SvgMapReader+Map}
[1] {SvgMapReader+Map}
So in the end what i want is to have List of Maps and the list should be build like this example: The first item will be:
[0] {Map 1}
Then inside Map 1:
[0] {Rectangles}
[1] {Triangles}
[2] {Boxes}
....
And inside Rectangles:
[0] {Rectangle 1}
[1] {Rectangle 2}
....
Same inside Triangles or boxes....
This is how the Maps List should be as hierarchy.
Your answer
Follow this Question
Related Questions
I create material with script but it does not render right 0 Answers
Creating Splines from empties in script 0 Answers
How can i rotate all the child objects together at the same time ? 1 Answer
How can i give another name/number to the created Plane object name ? 0 Answers
how to ask if something is not true for an amount of time 2 Answers