I figured out how to do this its using Unity's Asset Database and saving the scripts name as well as the Gameobjects name in order to retrieve them.
keep in mind that AssetDatabase is UnityEditor only so to load assets during game time you need to put them in Resources and use Resources.Load
I save the Inspectors data in a XML File on a button click and then Load the data on button click and OnEnable.
Here is the doc for XML Writing and Reading
Here is my Load and Save code just so you get an Idea:
Loading Data:
private void LoadItems(){
var Path = Application.persistentDataPath + "//XMLSaves/data.xml";
XmlDocument Document = new XmlDocument();
Document.Load(Path);
List<string> NamesL = new List<string>();
Names.Clear();
Prefabs.Clear();
Script.Clear();
isDropNormal.Clear();
XmlNodeList XmlItems = Document.DocumentElement.SelectNodes("//Items/Item");
foreach (XmlNode Node in XmlItems){
Names.Add(Node.SelectSingleNode("Name").InnerText);
string Prefab = Node.SelectSingleNode("Prefab").InnerText;
string[] Folders = new string[]{"Assets/Scripts/Drops/Prefabs"};
string AssetPath = GetAssetPath(Prefab, Folders);
GameObject Asset = (GameObject)AssetDatabase.LoadAssetAtPath(AssetPath,typeof(GameObject));
Prefabs.Add(Asset);
string ScriptName = Node.SelectSingleNode("Script").InnerText;
string ScriptPath = GetAssetPath(ScriptName + " t:MonoScript");
MonoScript MonoScriptPath = (MonoScript)AssetDatabase.LoadAssetAtPath(ScriptPath, typeof(MonoScript));
Script.Add(MonoScriptPath);
Methods.Add(Node.SelectSingleNode("Methods").InnerText);
bool isDropNormalT = bool.Parse(Node.SelectSingleNode("isDropNormal").InnerText);
isDropNormal.Add(isDropNormalT);
}
SizeProp = XmlItems.Count;
}
Saving Data:
private void WriteItemsToFile(){
var Path = Application.persistentDataPath + "//XMLSaves";
System.IO.Directory.CreateDirectory(Path);
if (System.IO.File.Exists(Path + "//data.xml")){
System.IO.File.Delete(Path + "//data.xml");
}
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = " ",
NewLineChars = "\r\n",
NewLineHandling = NewLineHandling.Replace
};
XmlWriter Writer = XmlWriter.Create(Path + "//data.xml", settings);
Writer.WriteStartDocument();
Writer.WriteStartElement("Items");
for (int I = 0;I < SizeProp; I++){
Writer.WriteStartElement("Item");
Writer.WriteElementString("Name", Names[I]);
Writer.WriteElementString("Prefab", Prefabs[I].name);
Writer.WriteElementString("Script", Script[I].name);
Writer.WriteElementString("Methods", Methods[I]);
Writer.WriteElementString("isDropNormal", isDropNormal[I].ToString());
Writer.WriteEndElement();
}
Writer.WriteEndElement();
Writer.WriteEndDocument();
Writer.Close();
}