/// <summary> /// Regular start function, enabling the usage of parsing buttons. /// </summary> /// <remarks> /// It obtains all graphnames from the respective resources folder and maps the provided parsers /// over them. For each file with a fileextension for which a parser exists, it generates a button. /// If there are more then one parser for a fileextension, the graph button opens a selection of available parsers, /// showing the description of the parser as button name. /// </remarks> void Start() { List <string> graphs = GlobalVariables.GetFullFilesFrom("Graphs", ""); Hashtable graphExtensions = new Hashtable(); List <string> extensions = new List <string>(); Hashtable instances = new Hashtable(); ContainerViewPort cv = inheritor; // Sortiere Graphen nach extensions for (int k = 0; k < graphs.Count; k++) { string extension = graphs[k].Split('.')[graphs[k].Split('.').Length - 1]; if (graphExtensions.ContainsKey(extension)) { ((List <string>)graphExtensions[extension]).Add(graphs[k]); } else { List <string> tmpGraphs = new List <string> { graphs[k] }; graphExtensions.Add(extension, tmpGraphs); } } // Ermittle Parser var type = typeof(Pipe); var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p) && p != typeof(Pipe)).ToList(); // Generiere Instanzen der Parser mit mapping auf fileextensions for (int k = 0; k < types.Count; k++) { Pipe instance = (Pipe)Activator.CreateInstance(types[k]); extensions.Add(instance.FileExtension); if (instances.ContainsKey(instance.FileExtension)) { ((List <Pipe>)instances[instance.FileExtension]).Add(instance); } else { List <Pipe> tmpPipes = new List <Pipe> { instance }; instances.Add(instance.FileExtension, tmpPipes); } } // Hole alle Graphen foreach (DictionaryEntry graphList in graphExtensions) { string currentFileextension = (string)graphList.Key; List <string> currentGraphs = (List <string>)graphList.Value; // Pro Graph, hole alle parser if (instances.ContainsKey(currentFileextension)) { foreach (string currentGraph in currentGraphs) { List <Pipe> currentParsers = (List <Pipe>)instances[currentFileextension]; GameObject graphButton = NewGameObject(ContentGraphFiles, LookOfButtons); graphButton.transform.GetChild(0).GetComponent <Text>().text = currentGraph; if (currentParsers.Count == 1) { // Wenn #parser == 1 Pipe currentParser = currentParsers[0]; graphButton.GetComponent <Button>().onClick.AddListener(() => { if (GlobalVariables.Graphnodes.Count > 0) { clearButton.ClearScene(); } cv.StatusText.text = "Graphfile " + currentGraph + " was chosen"; GlobalVariables.NewGraphLoaded = !GlobalVariables.NewGraphLoaded; currentParser.NodesAndLinksToList(currentGraph); currentParser.InsertGraph(currentParser.Nodes, currentParser.Links); }); } else if (currentParsers.Count > 1) { // Wenn #parser > 1 GameObject thisGraphsContainer = NewGameObject(inheritor, parserContainer); graphButton.GetComponent <Button>().onClick.AddListener(() => { cv.ShowPanel(thisGraphsContainer); GlobalVariables.ChosenGraph = graphButton.transform.GetChild(0).GetComponent <Text>().text; cv.StatusText.text = "Graphfile " + GlobalVariables.ChosenGraph + " was chosen"; }); foreach (Pipe currentParser in currentParsers) { GameObject chooseParserButton = NewGameObject(thisGraphsContainer, LookOfButtons); chooseParserButton.transform.GetChild(0).GetComponent <Text>().text = currentParser.Description; chooseParserButton.GetComponent <Button>().onClick.AddListener(() => { if (GlobalVariables.Graphnodes.Count > 0) { clearButton.ClearScene(); } GlobalVariables.NewGraphLoaded = !GlobalVariables.NewGraphLoaded; currentParser.NodesAndLinksToList(GlobalVariables.ChosenGraph); currentParser.InsertGraph(currentParser.Nodes, currentParser.Links); }); } } } } } }