Loading Xml to unity3d Editor at startup for editorWindow script problem

Hello,
Thank you for spending your time. Right now i am trying to make an rts game. So i thought i need to code some little editors which will help me to make a complex game. I dont have a very good c# background i think thats why i am having troubles with these kind of stuff. Now i have a xml file which holds race, subcultures and name data in it. I have make it to load the information in xml file to c# List<> in runtime. But i want it to be loaded at Unity editor startup then whenever i change the xml file i want it to be update the data in the editor.

Here are the scripts i wrote.
LoadResourcesToEditor.cs:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Text;



[System.Serializable]
public class xmlCharacterNames{
	public List<string> names = new List<string>();
	public List<string> familyNames = new List<string>();
}
[System.Serializable]
public class RomanSubCultures {
	public xmlCharacterNames latin = new xmlCharacterNames();
	public xmlCharacterNames greek= new xmlCharacterNames();
	public xmlCharacterNames samnite= new xmlCharacterNames();
	public xmlCharacterNames iberian= new xmlCharacterNames();
	public xmlCharacterNames etruscan= new xmlCharacterNames();
}
[System.Serializable]
public class BarbarSubCultures {
	public xmlCharacterNames Gaul= new xmlCharacterNames();	
	public xmlCharacterNames german= new xmlCharacterNames();
	public xmlCharacterNames dacian= new xmlCharacterNames();	
	public xmlCharacterNames scythean= new xmlCharacterNames();
	public xmlCharacterNames breton= new xmlCharacterNames();	
}

[System.Serializable]
public class Nations {
	public RomanSubCultures roman= new RomanSubCultures();
	public BarbarSubCultures barbar= new BarbarSubCultures();

}
[InitializeOnLoad]
public class LoadResourcesToEditor {
   	public static Nations nations = new Nations();
	static LoadResourcesToEditor()
    {
	
	LoadResource("CharacterNamesDataBase", @"/Resources/CharacterNames.txt");
	
	LoadNames();
	Debug.Log(nations.roman.latin.names.Count);
    }
	static void LoadResource(string name, string path)
	{
		Debug.Log(name +" " + "Loading...");
		XmlDocument characterNamesDb = new XmlDocument();
 		characterNamesDb.Load(Application.dataPath + path);
		Debug.Log(name +" " + "Loaded.");
	}
	
	static void LoadNames()
	{
		XmlDocument characterNamesDb = new XmlDocument();
		XmlNodeList  tableList = characterNamesDb.GetElementsByTagName("table");
	
		
		foreach(XmlNode currentTable in tableList)
		{
		
			foreach(XmlNode currentChild in currentTable.ChildNodes)
			{
				if(currentChild.Name == "SubCulture")
				{
					XmlNode subCulture = currentChild;
					
					Debug.Log(currentChild.Attributes["name"].Value);
					if(currentChild.Attributes["name"].Value == "Latin")
					{
						
						foreach(XmlNode currentSubCultureChild in subCulture)
						{
							if(currentSubCultureChild.Name == "Name")
							{
								string currentNameStr = currentSubCultureChild.InnerText;
								nations.roman.latin.names.Add(currentNameStr);
								Debug.Log(currentNameStr +" " + "Loaded.");
							}
							else if(currentSubCultureChild.Name == "FamilyName")
							{
								string currentFamilyNameStr = currentSubCultureChild.InnerText;
								nations.roman.latin.familyNames.Add(currentFamilyNameStr);
							}
							else
							{

							}
						}						
					}
					if(currentChild.Attributes["name"].Value == "Greek")
					{
						
						foreach(XmlNode currentSubCultureChild in subCulture)
						{
							if(currentSubCultureChild.Name == "Name")
							{
								string currentNameStr = currentSubCultureChild.InnerText;
								nations.roman.greek.names.Add(currentNameStr);
							}
							else if(currentSubCultureChild.Name == "FamilyName")
							{
								string currentFamilyNameStr = currentSubCultureChild.InnerText;
								nations.roman.greek.familyNames.Add(currentFamilyNameStr);
							}
							else
							{

							}
						}						
					}
					if(currentChild.Attributes["name"].Value == "Samnite")
					{
						
						foreach(XmlNode currentSubCultureChild in subCulture)
						{
							if(currentSubCultureChild.Name == "Name")
							{
								string currentNameStr = currentSubCultureChild.InnerText;
								nations.roman.samnite.names.Add(currentNameStr);
							}
							else if(currentSubCultureChild.Name == "FamilyName")
							{
								string currentFamilyNameStr = currentSubCultureChild.InnerText;
								nations.roman.samnite.familyNames.Add(currentFamilyNameStr);
							}
							else
							{

							}
						}						
					}
					if(currentChild.Attributes["name"].Value == "Iberian")
					{
						
						foreach(XmlNode currentSubCultureChild in subCulture)
						{
							if(currentSubCultureChild.Name == "Name")
							{
								string currentNameStr = currentSubCultureChild.InnerText;
								nations.roman.iberian.names.Add(currentNameStr);
							}
							else if(currentSubCultureChild.Name == "FamilyName")
							{
								string currentFamilyNameStr = currentSubCultureChild.InnerText;
								nations.roman.iberian.familyNames.Add(currentFamilyNameStr);
							}
							else
							{

							}
						}						
					}
					if(currentChild.Attributes["name"].Value == "Etruscan")
					{
						
						foreach(XmlNode currentSubCultureChild in subCulture)
						{
							if(currentSubCultureChild.Name == "Name")
							{
								string currentNameStr = currentSubCultureChild.InnerText;
								nations.roman.etruscan.names.Add(currentNameStr);
							}
							else if(currentSubCultureChild.Name == "FamilyName")
							{
								string currentFamilyNameStr = currentSubCultureChild.InnerText;
								nations.roman.etruscan.familyNames.Add(currentFamilyNameStr);
							}
							else
							{

							}
						}						
					}
					

					
				}
			}
		}
		
		Debug.Log("Names Loaded");
	}
}

Example xml that i used
CharacterNames.xml

<?xml version="1.0" encoding="utf-8"?>
<database name="CharacterNames">
<table name = "Nations">
		<SubCulture name = "Latin">
			<Name>Cassius</Name>
			<Name>Augustus</Name>
			<Name>Julius</Name>
			<Name>Marcus</Name>
			<Name>Maximus</Name>
			<Name>Pompeius</Name>
			<Name>Seneca</Name>
			<Name>Tiberius</Name>
			<Name>Octavius</Name> 
			<FamilyName>Lucia</FamilyName>
			<FamilyName>Marcellius</FamilyName>
			<FamilyName>Maximo</FamilyName>
			<FamilyName>Severinus</FamilyName>
			<FamilyName>Tatius</FamilyName>
			<FamilyName>Valeria</FamilyName>
			<FamilyName>Vita</FamilyName>
			<FamilyName>Junia</FamilyName>
			<FamilyName>Valentia</FamilyName>
		</SubCulture>
		<SubCulture name = "Greek">
			<Name>Abydos</Name>                          
			<Name>Achilles</Name>                          
			<Name>Ambrose</Name>                          
			<Name>Calais</Name>                          
			<Name>Alexander</Name>                          
			<Name>Apollon</Name>                          
			<Name>Castor</Name>                          
			<Name>Hector</Name>                          
			<Name>Kyros</Name>
			<FamilyName>Ladon</FamilyName>
			<FamilyName>Oenomaus</FamilyName>
			<FamilyName>Paris</FamilyName>
			<FamilyName>Perseus</FamilyName>
			<FamilyName>Timon</FamilyName>
			<FamilyName>Xeno</FamilyName>
			<FamilyName>Ercole</FamilyName>
			<FamilyName>Daedalus</FamilyName>
			<FamilyName>Athan</FamilyName>
		</SubCulture>
		<SubCulture name = "Samnite">
			<Name>Serra</Name>
			<Name>Secra</Name>
			<Name>Ronal</Name>
			<Name>Vegitus</Name>
			<Name>Octes</Name>
			<Name>Calatius</Name>
			<Name>Pontius</Name>
			<Name>Illatius</Name>
			<Name>Herenius</Name>
			<FamilyName>Thelaus</FamilyName>
			<FamilyName>Canusius</FamilyName>
			<FamilyName>Gnathius</FamilyName>
			<FamilyName>Horatius</FamilyName>
			<FamilyName>Sarcantius</FamilyName>
			<FamilyName>Naboratius</FamilyName>
			<FamilyName>Vogeratius</FamilyName>
			<FamilyName>Dimatea</FamilyName>
			<FamilyName>Enormertea</FamilyName>
		</SubCulture>
		<SubCulture name = "Iberian">
			<Name>Eder</Name>
			<Name>Amusacae</Name>
			<Name>Ambor</Name>
			<Name>Balcabar</Name>
			<Name>Cara</Name>
			<Name>Ilder</Name>
			<Name>Albon</Name>
			<Name>Belas</Name>
			<Name>Sinabar</Name>
			<FamilyName>Varca</FamilyName>
			<FamilyName>Umar</FamilyName>
			<FamilyName>Verba</FamilyName>
			<FamilyName>Tamiral</FamilyName>
			<FamilyName>Bargonte</FamilyName>
			<FamilyName>Baracure</FamilyName>
			<FamilyName>Ultan</FamilyName>
			<FamilyName>Damores</FamilyName>
			<FamilyName>Sakaman</FamilyName>
		</SubCulture>
		<SubCulture name = "Etruscan">	
			<Name>Arria</Name>
			<Name>Ati</Name>
			<Name>Sethra</Name>		
			<Name>Vela</Name>		
			<Name>Rasce</Name>		
			<Name>Velthur</Name>		
			<Name>Thucer</Name>		
			<Name>Vulca</Name>		
			<Name>Arnza</Name>		
			<FamilyName>Fulni</FamilyName>		
			<FamilyName>Apucu</FamilyName>		
			<FamilyName>Cala</FamilyName>		
			<FamilyName>Karkana</FamilyName>		
			<FamilyName>Marcena</FamilyName>		
			<FamilyName>Pursenna</FamilyName>		
			<FamilyName>Sucisna</FamilyName>		
			<FamilyName>Unata</FamilyName>		
			<FamilyName>Zertna</FamilyName>
			<FamilyName>Venete</FamilyName>
		</SubCulture> 
	</table>
</database>

The result is the names and family names Lists.count returns “0”. Whats wrong with this? code. Why it does not fill the List<> with the xml. I have already done it in runtime. Whats different with the editor scripting?

Thanks for your helps.

If I had to guess, I would say that you don’t have any code in your constructor. The “InitializeOnLoad” flag is correctly used in this instance. As long as this source file is in an “Editor” folder, it should be creating an instance of the class in question. But the rest of the static functions defined in that class don’t run automatically. The only function that gets run automatically when an object is created is the object’s constructor. And your constructor is empty. If you put a function call to LoadResourcesToEditor.LoadNames() in your LoadResourcesToEditor constructor, that should do the trick.

Hi richardKain thanks for your reply. I tried what you said above. But there is no changes. I inserted the “LoadResourcesToEditor.LoadNames();”. Also i added the Debug.Log(…) lines to check if it runs the LoadNames(); method and its going into the method. Still trying to solve what else can i try??

Ok i solved the problem. Just merged the methods together.