I am trying to find out if certain scripts have a material assigned, and if they do if those scripts are used in a scene. If those scripts are used in a scene I would like to find out if they have material publicly assigned .
Is it possible to obtain the publicly assigned materials through editor script? Right now I am using the following script to determine if it contains a material, and if a scene depends on it. But I am not sure on how to approach the read out of public variables over several scenes.
//finds all monobehaviour scripts (c# java boo)
foreach (MonoScript m in GetScriptAssetsOfType<MonoBehaviour>())
{
//regex for c# array/list/variable
bool containsmaterial = Regex.IsMatch(m.text, @"\bMaterial\b");
bool containsmateriallist = Regex.IsMatch(m.text, @"\bList<Material>\b");
bool containsmaterialarray = Regex.IsMatch(m.text, @"\bMaterial[]\b");
if (containsmaterial || containsmaterialarray || containsmateriallist)
{
Object currentObject = m as Object;
//check if it has dependencies
List<Object> results = S_collectDependencies(currentObject);
if (results.Count >= 1)
{
string currentName = currentObject.name;
foreach (Object o in results)
{
//if one of the dependencies is a scene
if (o.name.EndsWith(".unity"))
{
//find the public variables for M here
}
else
continue;
}
}
else
continue;
}