Пример #1
0
    /// <summary>
    /// 从项目文件夹下获取所有的prefab
    /// </summary>
    /// <param name="dir">指定的文件夹目录,fullname</param>
    /// <returns></returns>
    public static GameObject[] GetPrefabListUsingFileSys(string dir)
    {
        if (dir == null)
        {
            return(null);
        }
        if (!BobUtils.IsDirectory(dir))
        {
            BobUtils.ShowErrorMessage("请提供一个文件夹地址");
            return(null);
        }
        List <GameObject> prefabList = new List <GameObject>();
        DirectoryInfo     dirRoot    = new DirectoryInfo(dir);

        FileInfo[] allPrefabFiles = dirRoot.GetFiles("*.prefab", SearchOption.AllDirectories);
        string     fullname       = "";

        for (int i = 0; i < allPrefabFiles.Length; i++)
        {
            fullname = allPrefabFiles[i].FullName;
            fullname = BobUtils.GetRelativePath(fullname);
            BobUtils.DisplayProgressBar(i, allPrefabFiles.Length, "收集prefab信息", fullname);
            GameObject obj = (AssetDatabase.LoadAssetAtPath(fullname, typeof(Object))) as GameObject;
            if (obj == null)
            {
                continue;
            }
            prefabList.Add(obj);
        }
        BobUtils.ClearProgressBar();
        return(prefabList.ToArray());
    }
Пример #2
0
 /// <summary>
 /// 添加一组文件路径
 /// </summary>
 /// <param name="filepaths"></param>
 private void AddFileItems(string[] filepaths)
 {
     for (int i = 0; i < filepaths.Length; ++i)
     {
         AddFileItems(filepaths[i]);
     }
     BobUtils.ClearProgressBar();
 }
Пример #3
0
    /// <summary>
    /// 搜集项目中的atlas以及贴图资源显示在文件列表中
    /// </summary>
    public static void CollectAtlas()
    {
        string baseDir = Application.dataPath.Substring(0, Application.dataPath.IndexOf("Assets")) + "Assets/MLDJ";

        GameObject[]      prefabs     = BobShrinker.GetPrefabListUsingFileSys(baseDir);
        List <GameObject> prefabsList = new List <GameObject>(prefabs);

        GameObject[] atlaslist = BobShrinker.GetUIAtlasListFromPrefabList(prefabs);
        for (int i = 0; i < atlaslist.Length; i++)
        {
            BobUtils.DisplayProgressBar(i, atlaslist.Length, "搜集UIAtlas", atlaslist[i].name);
            string atlaspath = AssetDatabase.GetAssetPath(atlaslist[i]);
            if (!BobShrinker.db.ContainsPath(atlaspath))
            {
                AtlasProperty originalAtlasProp = BobShrinker.GetAtlasProperty(atlaslist[i].GetComponent <UIAtlas>(), true);
                BobShrinker.db.SaveAtlasData(atlaspath, originalAtlasProp, originalAtlasProp);
            }
            prefabsList.Remove(atlaslist[i].gameObject);
        }

        BobUtils.ClearProgressBar();
        Object[] dependencies = EditorUtility.CollectDependencies(prefabsList.ToArray());
        for (int i = 0; i < dependencies.Length; i++)
        {
            if (dependencies[i] is Texture2D)
            {
                BobUtils.DisplayProgressBar(i, dependencies.Length, "搜集Textures", dependencies[i].name);
                string texturePath = AssetDatabase.GetAssetPath(dependencies[i]);
                if (!BobShrinker.db.ContainsPath(texturePath))
                {
                    TextureImporter ti = TextureImporter.GetAtPath(texturePath) as TextureImporter;
                    if (ti == null)
                    {
                        Debug.LogError(texturePath);
                        continue;
                    }
                    int maxTextSize          = 0;
                    TextureImporterFormat tf = new TextureImporterFormat();
                    bool ret = ti.GetPlatformTextureSettings("WP8", out maxTextSize, out tf);//获取WP8的平台设置
                    if (ret == false)
                    {
                        maxTextSize = ti.maxTextureSize;
                        ti.SetPlatformTextureSettings("WP8", maxTextSize, ti.textureFormat); //若没有设置WP8平台,则用default的设置来设置
                    }
                    //备份原始属性
                    TextureProperty originalTextureProp = new TextureProperty(maxTextSize, ti.mipmapEnabled);
                    originalTextureProp.isOriginal = true;
                    BobShrinker.db.SaveTextureData(texturePath, originalTextureProp, originalTextureProp);
                }
            }
        }
        BobUtils.ClearProgressBar();
    }