So I need to try and figure out how to get a reference too all the classes in a script so far example…
Health.cs
public int hp;
public int maxHp;
Enemy.cs
public Health health;
How could I write something to check Enemy.cs and see that I need Health.cs in order for Enemy.cs to work? Any ideas…
If Health is a MonoBehaviour then annotating Enemy with [RequireComponent(typeof(Health))] would do that for you.
Thanks for the reply KelsoMRK but I should of stated better what I am doing.
I am writing something that will get a list of all the used scripts in your project. I am going through each scene and getting all references to scripts being used. If a script is being referenced like Health.cs is inside of Enemy, there is no way to tell that Enemy needs Health unless Health is added as a component to something else inside of the scene.
Without fully understanding it sounds like you just need to use reflection to get all of the public fields in a class.
I’ll look into Reflections, thanks.
I use something like this for the editor extension I’m writing at the moment…
MonoScript scripts = Resources.FindObjectsOfTypeAll(typeof(MonoScript)).Cast<MonoScript>().Where(c=>c.hideFlags == 0).Where(c=>c.GetClass() != null).ToList();
foreach( MonoScript script in scripts )
{
foreach(FieldInfo varInfo in script.GetClass().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
{
Debug.Log(varInfo.FieldType.ToString() + "\t" + varInfo.Attributes.ToString().Replace(",","") + "\t" + varInfo.Name);
}
}