Unity 检查带有默认贴图的shader

步骤:
1.拿到所有shader资源路径
2、用AssetDatabase.GetDenpendencies(path)拿到shader依赖文件路径
3、判断这些路径有没有是图片格式的 png tga bit jmp
4、如果有说明这个shader带有默认贴图 应该去掉 贴图应该加在Material上

代码:

using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

public class FindShaderWithTextureWindow : EditorWindow {

    [MenuItem("Tools/检查/检查带有默认贴图的shader")]
    private static void FindShaderWithTexture()
    {
        GetWindow<FindShaderWithTextureWindow>().Show();
        Find();
    }

    private static List<UnityEngine.Object> res = new List<UnityEngine.Object>();

    private static void Find()
    {
        res.Clear();
        var allfiles = Directory.GetFiles("Assets/", "*.shader", SearchOption.AllDirectories);
        foreach (var file in allfiles)
        {
            foreach (var item in AssetDatabase.GetDependencies(file).Where(s => s.IsTexture()))
            {
                res.Add(AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(file));
                break;
            }
        }
        EditorUtility.DisplayDialog("", "就绪", "OK");
    }

    private Vector2 scro = Vector2.zero;
    private void OnGUI()
    {
        scro = EditorGUILayout.BeginScrollView(scro);
        EditorGUILayout.BeginVertical();
        foreach (var item in res)
        {
            EditorGUILayout.ObjectField(item, typeof(UnityEngine.Object), true);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndScrollView();
    }



}

public static class Extension
{
 public  static bool IsTexture(this string s)
    {
        return s.EndsWith("tga", true, System.Globalization.CultureInfo.CurrentCulture) ||
            s.EndsWith("png", true, System.Globalization.CultureInfo.CurrentCulture) ||
            s.EndsWith("jpg", true, System.Globalization.CultureInfo.CurrentCulture) ||
            s.EndsWith("bmp", true, System.Globalization.CultureInfo.CurrentCulture);
    }

    public static void Addd(this Dictionary<object,List<object>> dic,object o1,object o2)
    {
        if (dic.ContainsKey(o1))
        {
            if (!dic[o1].Contains(o2))
            {
                dic[o1].Add(o2);
            }
        }else
        {
            dic.Add(o1, new List<object>() { o2 });
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值