public static List<Texture> GetAllTexture(this Material mat)
{
List<Texture> textures = new List<Texture>();
List<string> texNames = new List<string>();
mat.GetTexturePropertyNames(texNames);
foreach (var propertyName in texNames)
{
//Debug.Log(propertyName);
Texture tex = mat.GetTexture(propertyName);
if (tex != null)
{
if (!textures.Contains(tex))
{
textures.Add(tex);
}
}
}
return textures;
}
public static List<Material> GetAllMaterial(this GameObject gameObject)
{
SkinnedMeshRenderer[] skinnedMeshes = gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
MeshRenderer[] meshes = gameObject.GetComponentsInChildren<MeshRenderer>();
List<Material> mats = new List<Material>();
foreach (var skin in skinnedMeshes)
{
foreach (var mat in skin.sharedMaterials)
{
if (!mats.Contains(mat))
{
mats.Add(mat);
}
}
}
foreach (var mesh in meshes)
{
foreach (var mat in mesh.sharedMaterials)
{
if (!mats.Contains(mat))
{
mats.Add(mat);
}
}
}
return mats;
}
public static List<Texture> GetAllTexture(this GameObject gameObject)
{
List<Material> mats = gameObject.GetAllMaterial();
List<Texture> textures = new List<Texture>();
foreach (var mat in mats)
{
textures.AddRange(mat.GetAllTexture());
}
return textures;
}