示例#1
0
    public static void ItemCheck(AssetFilter filter)
    {
        ICheck checkTypd = (ICheck)Activator.CreateInstance(Type.GetType(filter.CheckTagString));

        string[]      guids   = AssetDatabase.FindAssets(checkTypd.SearchTag, new string[] { filter.path });
        float         count   = guids.Length;
        float         index   = 1;
        List <string> fixList = new List <string>();

        foreach (string guid in guids)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string info      = String.Format("{0}/{1} {2}", index, count, assetPath);
            ICheck _check    = (ICheck)Activator.CreateInstance(Type.GetType(filter.CheckTagString));
            EditorUtility.DisplayProgressBar(_check.GetType().Name + " Check", info, (float)(index / count));

            if (!string.IsNullOrEmpty(assetPath))
            {
                if (!_check.Check(AssetDatabase.GUIDToAssetPath(guid)))
                {
                    fixList.Add(assetPath);
                    mDictionaryCheck[filter.CheckTagString].Add(_check);
                    if (!_check.CanFix)
                    {
                        Debug.LogError(info + " can not auto fix");
                    }
                }
            }
            else
            {
                Debug.LogError(info + " error" + _check.GetType().Name);
            }

            index++;
        }
        List <ICheck> list = mDictionaryCheck[filter.CheckTagString];

        if (checkTypd.CanFix)
        {
            index = 1;
            count = fixList.Count;
            foreach (var assetPath in fixList)
            {
                string info = String.Format("{0}/{1} {2}", index, count, assetPath);
                EditorUtility.DisplayProgressBar(checkTypd.GetType().Name + " Fix", info, (float)(index / count));
                if (checkTypd.Fix(assetPath))
                {
                    Debug.Log(info + " Fixed");
                }
                else
                {
                    Debug.LogError(info + "auto fix fail");
                }
                index++;
            }
        }
        EditorUtility.ClearProgressBar();
    }