void DrawRef(TextRefMaterial m) { using (new AutoBeginHorizontal()) { if (GUILayout.Button(m.expand ? EditorGUIUtility.IconContent("Icon Dropdown") : new GUIContent("›"), EditorStyles.toolbarButton, GUILayout.Width(15))) { m.expand = !m.expand; } EditorGUILayout.ObjectField(m.mat, typeof(Material)); if (GUILayout.Button("场景选中")) { EditorUtil.SelectMaterial(m.mat); } } if (m.expand) { using (new AutoEditorIndentLevel()) { foreach (var p in m.prefabs) { EditorGUILayout.ObjectField(p, typeof(GameObject)); } } } }
void FindTextureRef() { if (m_texFindRef == null) { return; } m_refMats.Clear(); EditorUtility.DisplayProgressBar("查找贴图引用", string.Format("正在收集预制体"), 0); List <GameObject> prefabs = new List <GameObject>(); EditorUtil.GetAssetAtPath("Effect/Resources", ref prefabs); EditorUtil.GetAssetAtPath("UI/fx_ui/Resources", ref prefabs); EditorUtility.DisplayProgressBar("查找贴图引用", string.Format("正在查找"), 0.5f); foreach (var p in prefabs) { Renderer[] rs = p.GetComponentsInChildren <Renderer>(true); foreach (var r in rs) { Material[] ms = r.sharedMaterials; if (ms == null || ms.Length == 0) { continue; } foreach (Material m in ms) { if (m == null) { continue; } if (m.mainTexture != m_texFindRef) { continue; } TextRefMaterial refMat; if (!m_refMats.TryGetValue(m, out refMat)) { refMat = new TextRefMaterial(); m_refMats[m] = refMat; refMat.mat = m; } if (!refMat.prefabs.Contains(p)) { refMat.prefabs.Add(p); } } } } EditorUtility.ClearProgressBar(); }