using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
public class GetAllObject : MonoBehaviour
{
[MenuItem("Wpw/Assets/ChangeAll")]
static void Test_Compoent()
{
//OK
//这个不好用~
//Debug.Log(AssetDatabase.LoadAllAssetsAtPath("Assets/Models/21/21000001/21000001.prefab").Length);
//粒子列表
List<Renderer> parList = new List<Renderer>();
List<MeshRenderer> parList2 = new List<MeshRenderer>();
//AI材质球列表
Dictionary<Material, FileInfo> aiMaterialDict = new Dictionary<Material, FileInfo>();
//其他材质球列表
Dictionary<Material, FileInfo> otherMaterialDict1 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict2 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict3 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict4 = new Dictionary<Material, FileInfo>();
//AIShader列表
Dictionary<Shader, FileInfo> aiShaderDict = new Dictionary<Shader, FileInfo>();
//其他Shader列表
Dictionary<Shader, FileInfo> otherShaderDict1 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict2 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict3 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict4 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict5 = new Dictionary<Shader, FileInfo>();
设置进度条
EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0.50f);
EditorUtility.ClearProgressBar();
//路径
string fullPath1 = "Assets/AI" + "/";
string fullPath2 = "Assets/ProjectRes" + "/";
string fullPath3 = "Assets/Resources" + "/";
string fullPath4 = "Assets/ArtRes" + "/";
LoadAssetByAllChildren(ref parList, ref parList2, fullPath1);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath2);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath3);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath4);
LoadAssetByAllChildren(ref parList, ref parList2, "Assets/Plugins");
LoadAsset<Material>(ref aiMaterialDict, fullPath1, "mat");
Debug.Log(aiMaterialDict.Count);
LoadAsset<Material>(ref otherMaterialDict1, fullPath2, "mat");
LoadAsset<Material>(ref otherMaterialDict2, fullPath3, "mat");
LoadAsset<Material>(ref otherMaterialDict3, fullPath4, "mat");
LoadAsset<Material>(ref otherMaterialDict4, "Assets/Plugins" + "/", "mat");
LoadAsset<Shader>(ref aiShaderDict, fullPath1, "shader");
LoadAsset<Shader>(ref otherShaderDict1, fullPath2, "shader");
LoadAsset<Shader>(ref otherShaderDict2, fullPath3, "shader");
LoadAsset<Shader>(ref otherShaderDict3, fullPath4, "shader");
LoadAsset<Shader>(ref otherShaderDict4, "Assets/Script" + "/", "shader");
LoadAsset<Shader>(ref otherShaderDict5, "Assets/Plugins" + "/", "shader");
List<Shader> removeList2 = new List<Shader>(otherShaderDict1.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict1[removeList2[i]]);
otherShaderDict1.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict2.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict2[removeList2[i]]);
otherShaderDict2.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict3.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict3[removeList2[i]]);
otherShaderDict3.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict4.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict4[removeList2[i]]);
otherShaderDict4.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict5.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict5[removeList2[i]]);
otherShaderDict5.Remove(removeList2[i]);
}
}
List<Material> removeList = new List<Material>(otherMaterialDict1.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict1[removeList[i]]);
otherMaterialDict1.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict2.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict2[removeList[i]]);
otherMaterialDict2.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict3.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict3[removeList[i]]);
otherMaterialDict3.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict4.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict4[removeList[i]]);
otherMaterialDict4.Remove(removeList[i]);
}
}
Debug.Log(aiShaderDict.Count);
Dictionary<Material, string> shaderNameDict = new Dictionary<Material, string>();
//更换shader
foreach (Material item in aiMaterialDict.Keys)
{
shaderNameDict.Add(item, item.shader.name);
}
foreach (FileInfo item in otherShaderDict1.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict2.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict3.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict4.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict5.Values)
{
File.Delete(item.FullName);
}
AssetDatabase.Refresh();
//更换shader
foreach (Material item in shaderNameDict.Keys)
{
bool ishave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (item1.name == shaderNameDict[item])
{
ishave = true;
item.shader = item1;
}
}
if (!ishave)
{
//Debug.Log("IsNoHaveShader == " + item.shader.name);
}
}
AssetDatabase.Refresh();
for (int i = 0; i < parList.Count; i++)
{
if (parList[i].sharedMaterial == null)
{
continue;
}
bool isHave = false;
foreach (Material item in aiMaterialDict.Keys)
{
if (item.name == parList[i].sharedMaterial.name)
{
parList[i].sharedMaterial = item;
isHave = true;
break;
}
}
if (!isHave)
{
//Debug.Log("noHave!! == " + parList[i].name);
}
}
for (int i = 0; i < parList2.Count; i++)
{
if (parList2[i].sharedMaterial == null)
{
continue;
}
bool isHave = false;
foreach (Material item in aiMaterialDict.Keys)
{
if (parList2[i].sharedMaterial == null)
{
break;
}
if (item.name == parList2[i].sharedMaterial.name)
{
parList2[i].sharedMaterial = item;
isHave = true;
break;
}
}
if (!isHave)
{
//Debug.Log("noHave!! == " + parList[i].name);
}
}
AssetDatabase.Refresh();
//Debug.Log("otherMaterialDict1.count == " + otherMaterialDict1.Count);
foreach (FileInfo item in otherMaterialDict1.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict2.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict3.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict4.Values)
{
File.Delete(item.FullName);
}
AssetDatabase.Refresh();
}
static T LoadAsset<T>(ref Dictionary<T, FileInfo> outList, string fullPath, string pattern) where T : Object
{
//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
for (int i = 0; i < files.Length; i++)
{
if (files[i].Name.EndsWith(".meta"))
{
continue;
}
if (files[i].FullName.Split('.')[1] == pattern)
{
string ss = files[i].FullName.Replace("D:\\ClientMainProject\\Assets\\", "");
T mat = AssetDatabase.LoadAssetAtPath("Assets/" + ss, typeof(T)) as T;
if (mat != null)
{
outList.Add(mat, files[i]);
}
}
}
}
return null;
}
static void LoadAssetByAllChildren(ref List<Renderer> parList, ref List<MeshRenderer> parList2, string fullPath)
{
//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
//Debug.Log(files.Length);
for (int i = 0; i < files.Length; i++)
{
//Debug.Log("i === " + i.ToString() + " == " + files[i].Name);
if (files[i].Name.EndsWith(".meta"))
{
continue;
}
if (files[i].Name.EndsWith(".prefab") || files[i].Name.EndsWith(".FBX"))
{
string ss = files[i].FullName.Replace("D:\\ClientMainProject\\Assets\\", "");
GameObject gobj = AssetDatabase.LoadAssetAtPath("Assets/" + ss, typeof(GameObject)) as GameObject;
List<MeshRenderer> matList = new List<MeshRenderer>();
List<Renderer> list2 = new List<Renderer>();
gobj.GetComponentsInChildren<MeshRenderer>(true, matList);
gobj.GetComponentsInChildren<Renderer>(true, list2);
for (int j = 0; j < matList.Count; j++)
{
if (matList[j] != null)
{
parList2.Add(matList[j]);
}
}
for (int j = 0; j < list2.Count; j++)
{
if (list2[j] != null)
{
parList.Add(list2[j]);
}
}
}
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
public class GetAllObject : MonoBehaviour
{
[MenuItem("Wpw/Assets/ChangeAll")]
static void Test_Compoent()
{
//OK
//这个不好用~
//Debug.Log(AssetDatabase.LoadAllAssetsAtPath("Assets/Models/21/21000001/21000001.prefab").Length);
//粒子列表
List<Renderer> parList = new List<Renderer>();
List<MeshRenderer> parList2 = new List<MeshRenderer>();
//AI材质球列表
Dictionary<Material, FileInfo> aiMaterialDict = new Dictionary<Material, FileInfo>();
//其他材质球列表
Dictionary<Material, FileInfo> otherMaterialDict1 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict2 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict3 = new Dictionary<Material, FileInfo>();
Dictionary<Material, FileInfo> otherMaterialDict4 = new Dictionary<Material, FileInfo>();
//AIShader列表
Dictionary<Shader, FileInfo> aiShaderDict = new Dictionary<Shader, FileInfo>();
//其他Shader列表
Dictionary<Shader, FileInfo> otherShaderDict1 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict2 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict3 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict4 = new Dictionary<Shader, FileInfo>();
Dictionary<Shader, FileInfo> otherShaderDict5 = new Dictionary<Shader, FileInfo>();
设置进度条
EditorUtility.DisplayProgressBar("设置AssetName名称", "正在设置AssetName名称中...", 0.50f);
EditorUtility.ClearProgressBar();
//路径
string fullPath1 = "Assets/AI" + "/";
string fullPath2 = "Assets/ProjectRes" + "/";
string fullPath3 = "Assets/Resources" + "/";
string fullPath4 = "Assets/ArtRes" + "/";
LoadAssetByAllChildren(ref parList, ref parList2, fullPath1);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath2);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath3);
LoadAssetByAllChildren(ref parList, ref parList2, fullPath4);
LoadAssetByAllChildren(ref parList, ref parList2, "Assets/Plugins");
LoadAsset<Material>(ref aiMaterialDict, fullPath1, "mat");
Debug.Log(aiMaterialDict.Count);
LoadAsset<Material>(ref otherMaterialDict1, fullPath2, "mat");
LoadAsset<Material>(ref otherMaterialDict2, fullPath3, "mat");
LoadAsset<Material>(ref otherMaterialDict3, fullPath4, "mat");
LoadAsset<Material>(ref otherMaterialDict4, "Assets/Plugins" + "/", "mat");
LoadAsset<Shader>(ref aiShaderDict, fullPath1, "shader");
LoadAsset<Shader>(ref otherShaderDict1, fullPath2, "shader");
LoadAsset<Shader>(ref otherShaderDict2, fullPath3, "shader");
LoadAsset<Shader>(ref otherShaderDict3, fullPath4, "shader");
LoadAsset<Shader>(ref otherShaderDict4, "Assets/Script" + "/", "shader");
LoadAsset<Shader>(ref otherShaderDict5, "Assets/Plugins" + "/", "shader");
List<Shader> removeList2 = new List<Shader>(otherShaderDict1.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict1[removeList2[i]]);
otherShaderDict1.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict2.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict2[removeList2[i]]);
otherShaderDict2.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict3.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict3[removeList2[i]]);
otherShaderDict3.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict4.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict4[removeList2[i]]);
otherShaderDict4.Remove(removeList2[i]);
}
}
removeList2.Clear();
removeList2 = new List<Shader>(otherShaderDict5.Keys);
for (int i = 0; i < removeList2.Count; i++)
{
bool isHave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (removeList2[i].name == item1.name)
{
isHave = true;
break;
}
}
if (!isHave)
{
aiShaderDict.Add(removeList2[i], otherShaderDict5[removeList2[i]]);
otherShaderDict5.Remove(removeList2[i]);
}
}
List<Material> removeList = new List<Material>(otherMaterialDict1.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict1[removeList[i]]);
otherMaterialDict1.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict2.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict2[removeList[i]]);
otherMaterialDict2.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict3.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict3[removeList[i]]);
otherMaterialDict3.Remove(removeList[i]);
}
}
removeList.Clear();
removeList = new List<Material>(otherMaterialDict4.Keys);
for (int i = 0; i < removeList.Count; i++)
{
bool isHave = false;
foreach (Material item1 in aiMaterialDict.Keys)
{
if (removeList[i].name == item1.name)
{
if (item1.shader.name == "Hidden/InternalErrorShader" && removeList[i].shader.name != "Hidden/InternalErrorShader")
{
Debug.Log("ChangeShader!! == " + removeList[i].shader.name);
foreach (Shader itemx in aiShaderDict.Keys)
{
if (removeList[i].shader.name == itemx.name)
{
item1.shader = itemx;
}
}
}
isHave = true;
break;
}
}
if (!isHave)
{
aiMaterialDict.Add(removeList[i], otherMaterialDict4[removeList[i]]);
otherMaterialDict4.Remove(removeList[i]);
}
}
Debug.Log(aiShaderDict.Count);
Dictionary<Material, string> shaderNameDict = new Dictionary<Material, string>();
//更换shader
foreach (Material item in aiMaterialDict.Keys)
{
shaderNameDict.Add(item, item.shader.name);
}
foreach (FileInfo item in otherShaderDict1.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict2.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict3.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict4.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherShaderDict5.Values)
{
File.Delete(item.FullName);
}
AssetDatabase.Refresh();
//更换shader
foreach (Material item in shaderNameDict.Keys)
{
bool ishave = false;
foreach (Shader item1 in aiShaderDict.Keys)
{
if (item1.name == shaderNameDict[item])
{
ishave = true;
item.shader = item1;
}
}
if (!ishave)
{
//Debug.Log("IsNoHaveShader == " + item.shader.name);
}
}
AssetDatabase.Refresh();
for (int i = 0; i < parList.Count; i++)
{
if (parList[i].sharedMaterial == null)
{
continue;
}
bool isHave = false;
foreach (Material item in aiMaterialDict.Keys)
{
if (item.name == parList[i].sharedMaterial.name)
{
parList[i].sharedMaterial = item;
isHave = true;
break;
}
}
if (!isHave)
{
//Debug.Log("noHave!! == " + parList[i].name);
}
}
for (int i = 0; i < parList2.Count; i++)
{
if (parList2[i].sharedMaterial == null)
{
continue;
}
bool isHave = false;
foreach (Material item in aiMaterialDict.Keys)
{
if (parList2[i].sharedMaterial == null)
{
break;
}
if (item.name == parList2[i].sharedMaterial.name)
{
parList2[i].sharedMaterial = item;
isHave = true;
break;
}
}
if (!isHave)
{
//Debug.Log("noHave!! == " + parList[i].name);
}
}
AssetDatabase.Refresh();
//Debug.Log("otherMaterialDict1.count == " + otherMaterialDict1.Count);
foreach (FileInfo item in otherMaterialDict1.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict2.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict3.Values)
{
File.Delete(item.FullName);
}
foreach (FileInfo item in otherMaterialDict4.Values)
{
File.Delete(item.FullName);
}
AssetDatabase.Refresh();
}
static T LoadAsset<T>(ref Dictionary<T, FileInfo> outList, string fullPath, string pattern) where T : Object
{
//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
for (int i = 0; i < files.Length; i++)
{
if (files[i].Name.EndsWith(".meta"))
{
continue;
}
if (files[i].FullName.Split('.')[1] == pattern)
{
string ss = files[i].FullName.Replace("D:\\ClientMainProject\\Assets\\", "");
T mat = AssetDatabase.LoadAssetAtPath("Assets/" + ss, typeof(T)) as T;
if (mat != null)
{
outList.Add(mat, files[i]);
}
}
}
}
return null;
}
static void LoadAssetByAllChildren(ref List<Renderer> parList, ref List<MeshRenderer> parList2, string fullPath)
{
//获取指定路径下面的所有资源文件
if (Directory.Exists(fullPath))
{
DirectoryInfo direction = new DirectoryInfo(fullPath);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
//Debug.Log(files.Length);
for (int i = 0; i < files.Length; i++)
{
//Debug.Log("i === " + i.ToString() + " == " + files[i].Name);
if (files[i].Name.EndsWith(".meta"))
{
continue;
}
if (files[i].Name.EndsWith(".prefab") || files[i].Name.EndsWith(".FBX"))
{
string ss = files[i].FullName.Replace("D:\\ClientMainProject\\Assets\\", "");
GameObject gobj = AssetDatabase.LoadAssetAtPath("Assets/" + ss, typeof(GameObject)) as GameObject;
List<MeshRenderer> matList = new List<MeshRenderer>();
List<Renderer> list2 = new List<Renderer>();
gobj.GetComponentsInChildren<MeshRenderer>(true, matList);
gobj.GetComponentsInChildren<Renderer>(true, list2);
for (int j = 0; j < matList.Count; j++)
{
if (matList[j] != null)
{
parList2.Add(matList[j]);
}
}
for (int j = 0; j < list2.Count; j++)
{
if (list2[j] != null)
{
parList.Add(list2[j]);
}
}
}
}
}
}
}