I have a lot of duplicated objects, and I need in editor, not in the game, apply some changes to the objectsremove specific (remove specific material18) material slot. Of course I can do this manuallyRemove not material in slot 18, but there are a lot of themremove slot 18. Manually, by hands, it can be done using this button:
All objects that I need to remove slot from has the next mutuals:
- Contain "_lod" in the name;
- Have the same mesh, with the same GUID
I did not find how to get GUID of Javascriptthe given object, you can just open consoleso the search, and get all stuff Youprobably need to go by methods like getElementsByClassName. It would be perfect if some similar functionality exist (at least as addons) in Unityname.
I do not need some UI for using script currentlyhave never scripted Unity, and I also doeven did not need to run it on Unity launch.write in C# (although I want to call it every time by pressing some keywrite in editorC++).
So, seems thatWhat I have to enumarate alldone so far: I created an empty game objects, get their meshes, check GUID,object and if it equalsassign cs script below to it as a component. DestroyImmediate(myMaterials[18]), works almost that I need, then enumarete object's materials listbut it removes not the slot, find by GUIDbut the material on it (and automatically creates default material). I need, and call some remove method to itremove exactly the slot.
Point me where I should look, and should learn to achive that.LookAtPoint.cs:
using UnityEngine.SceneManagement;
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEditor;
[ExecuteInEditMode]
public class LookAtPoint : MonoBehaviour
{
void Iter(GameObject gameObject) // Itterate children
{
for (int j = 0; j < gameObject.transform.childCount; j++)
{
GameObject a = (GameObject)gameObject.transform.GetChild(j).gameObject;
MeshFilter viewedModelFilter = (MeshFilter)a.GetComponent("MeshFilter");
if(viewedModelFilter && viewedModelFilter.mesh && a.name.IndexOf("_lod") != -1) // check if object has mesh and it's name contains "_lod"
{
Material[] myMaterials = a.GetComponent<Renderer>().materials;
if(myMaterials[18].name.IndexOf("Подоконник")!=-1) // not neccesary check if 18s slot has "Подоконник" name (actually now it is already "Default-Material")
{
DestroyImmediate(myMaterials[18]);
}
}
Iter(a);
}
}
void Start()
{
List<GameObject> rootObjects = new List<GameObject>();
Scene scene = SceneManager.GetActiveScene();
scene.GetRootGameObjects( rootObjects );
for (int i = 0; i < rootObjects.Count; ++i)
{
GameObject gameObject = rootObjects[ i ]; // get root objects
for (int j = 0; j < gameObject.transform.childCount; j++) // enumarate them
{
Iter(gameObject); // iteratevely process the children
}
}
}
}
