- Home /
Find public assigned values using editor script
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;
}
Answer by Anxo · Sep 24, 2014 at 02:15 PM
Could you not just select all objects in the scene and iterate through them and their children to check their materials? " Selection.gameObjects static GameObject[] gameObjects; Description
Returns the actual game object selection. Includes prefabs, non-modifyable objects.
When working with objects that are primarily in a scene, it is strongly recommended to use Selection.transforms instead. " Then you could create an list that adds the game objects that contain the material you are looking for and selects it after.
That would mean there will be a user interaction to select all objects. I prefer to automate that process. This process is only meant to find residue materials in scenes, such as the NGUI materials, they are only referenced in their script and not statically in prefabs. And as they may be spread over several scenes, having to select each scene manually would be annoying.
If it would be possible to get all those objects in a scene for each scene file without the user interaction of selecting it, then that would be the functionality I am looking for right now .
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C#: Include Custom Editor features for a custom Classes while avoiding dependencies? 0 Answers
Editor Script into .dll(Solved) 1 Answer
How to hide/show serialized class object in the inspector with boolean value change? 1 Answer