Example #1
0
        static void MakeVersionConfig(string version, string url)
        {
            AssetBundle         manifestBundle = AssetBundle.LoadFromFile(outputPath + "/" + outputName);
            AssetBundleManifest manifest       = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");

            string[] allBundle = manifest.GetAllAssetBundles();
            manifestBundle.Unload(false);

            VersionRes ver = new VersionRes();

            ver.version = version;
            ver.url     = url;

            {
                VersionResFile file = new VersionResFile();
                file.name      = bundleInfoFileName;
                file.signature = FileChecker.GetFileSignature(outputPath + "/" + bundleInfoFileName);
                file.compress  = "none";
                ver.versionResFile.Add(file);
            }

            {
                VersionResFile file = new VersionResFile();
                file.name      = assetInfoFileName;
                file.signature = FileChecker.GetFileSignature(outputPath + "/" + assetInfoFileName);
                file.compress  = "none";
                ver.versionResFile.Add(file);
            }

            for (int i = 0; i < allBundle.Length; ++i)
            {
                EditorUtility.DisplayProgressBar("MakeVersionConfig config", "handle...", (float)i / allBundle.Length);

                VersionResFile file = new VersionResFile();
                file.name      = allBundle[i];
                file.signature = FileChecker.GetFileSignature(outputPath + "/" + allBundle[i]);
                file.compress  = "none";
                ver.versionResFile.Add(file);
            }
            EditorUtility.ClearProgressBar();
            string persistentPath = Application.dataPath + "/../PersistentData/";

            SerializeHelper.SaveToFile(ver, persistentPath + "version.json", true);
        }
Example #2
0
        public static void MakeAssetConfig()
        {
            try
            {
                AssetInfoConfig  assetInfoCfg  = new AssetInfoConfig();
                BundleInfoConfig bundleInfoCfg = new BundleInfoConfig();

                AssetBundle         manifestBundle = AssetBundle.LoadFromFile(outputPath + "/" + outputName);
                AssetBundleManifest manifest       = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest");
                string[]            allBundle      = manifest.GetAllAssetBundles();
                manifestBundle.Unload(false);

                for (int i = 0; i < allBundle.Length; ++i)
                {
                    EditorUtility.DisplayProgressBar("make asset config", "handle...", (float)i / allBundle.Length);

                    string[]   depBundle  = manifest.GetAllDependencies(allBundle[i]);
                    BundleInfo bundleInfo = new BundleInfo();
                    bundleInfoCfg.bundleInfo.Add(bundleInfo);
                    bundleInfo.name         = allBundle[i];
                    bundleInfo.dependBundle = new List <string>();
                    for (int k = 0; k < depBundle.Length; ++k)
                    {
                        bundleInfo.dependBundle.Add(depBundle[k]);
                    }

                    AssetBundle bundle = AssetBundle.LoadFromFile(outputPath + "/" + allBundle[i]);
                    if (bundle == null)
                    {
                        Debug.LogError("assetbundle can not find!");
                        continue;
                    }
                    string[] allAsset = bundle.GetAllAssetNames();
                    bundle.Unload(false);
                    for (int k = 0; k < allAsset.Length; ++k)
                    {
                        AssetInfo assetInfo = new AssetInfo();
                        assetInfoCfg.assetInfo.Add(assetInfo);
                        string assetName    = allAsset[k].Replace("assets/resources/", "");
                        string strExtension = Path.GetExtension(assetName);
                        assetInfo.name         = assetName.Replace(strExtension, "");
                        assetInfo.extName      = strExtension;
                        assetInfo.dependBundle = allBundle[i];
                    }
                }

                EditorUtility.ClearProgressBar();
                string persistentPath = Application.dataPath + "/../PersistentData/";
                SerializeHelper.SaveToFile(bundleInfoCfg, persistentPath + bundleInfoFileName, true);
                SerializeHelper.SaveToFile(assetInfoCfg, persistentPath + assetInfoFileName, true);

                MakeVersionConfig("1.2.3.1111", "http://10.0.0.252:8080/oppo_ver_cfg/");

                Debug.Log("打包结束!");
            }
            catch (System.Exception ex)
            {
                EditorUtility.ClearProgressBar();
                Debug.Log("打包失败!");
            }
        }
Example #3
0
        public static void AnalysisEffect()
        {
            s_AssetInfo.Clear();

            List <PrefabInfo>        prefabInfos = new List <PrefabInfo>();
            Dictionary <string, int> refCount    = new Dictionary <string, int>();

            string        path    = Application.dataPath + "/resources/effect/";
            List <string> files   = new List <string>();
            List <string> prefabs = new List <string>();

            PathUtils.GetFileList(ref files, path, true);
            PathUtils.GetFileListByEnds(ref files, ".prefab", ref prefabs);

            for (int i = 0; i < prefabs.Count; ++i)
            {
                string assets   = "/assets/";
                int    idx      = prefabs[i].ToLower().IndexOf(assets);
                int    startPos = idx + 1;// assets.Length;
                prefabs[i] = prefabs[i].Substring(startPos, prefabs[i].Length - startPos);
            }

            List <GameObject> allPrefab = new List <GameObject>();

            for (int i = 0; i < prefabs.Count; ++i)
            {
                EditorUtility.DisplayProgressBar("load prefab", "handle...", (float)i / prefabs.Count);

                GameObject prefab = AssetDatabase.LoadAssetAtPath(prefabs[i], typeof(GameObject)) as GameObject;
                allPrefab.Add(prefab);

                UnityEngine.Object[] roots      = new UnityEngine.Object[] { prefab };
                UnityEngine.Object[] dependObjs = EditorUtility.CollectDependencies(roots);

                PrefabInfo info = new PrefabInfo();
                info.name = prefabs[i];

                for (int k = 0; k < dependObjs.Length; ++k)
                {
                    string p = AssetDatabase.GetAssetPath(dependObjs[k]);
                    info.dependAsset.Add(p);

                    int count = 0;
                    if (dependObjs[k] == null)
                    {
                        continue;
                    }
                    if (refCount.TryGetValue(p, out count))
                    {
                        refCount[p] += 1;
                    }
                    else
                    {
                        refCount[p] = 1;
                    }
                }
                prefabInfos.Add(info);
            }
            EditorUtility.ClearProgressBar();

            UnityEngine.Object[] all           = allPrefab.ToArray();
            UnityEngine.Object[] allDependObjs = EditorUtility.CollectDependencies(all);
            for (int k = 0; k < allDependObjs.Length; ++k)
            {
                EditorUtility.DisplayProgressBar("foreach dependobjs", "handle...", (float)k / allDependObjs.Length);

                UnityEngine.Object obj = allDependObjs[k];
                string             p   = AssetDatabase.GetAssetPath(obj);

                MeshFilter meshFilter = obj as MeshFilter;
                if (meshFilter != null)
                {
                    Mesh     meshObj = meshFilter.sharedMesh;
                    MeshInfo info    = new MeshInfo();
                    info.name       = p;
                    info.meshFilter = meshFilter.name;
                    info.refCount   = refCount[p];
                    if (meshObj != null)
                    {
                        info.subMeshCount  = meshObj.subMeshCount;
                        info.vertexCount   = meshObj.vertexCount;
                        info.triangleCount = meshObj.triangles.Length;
                    }
                    s_AssetInfo.meshInfo.Add(info);
                }

                Texture2D texObj = obj as Texture2D;
                if (texObj != null)
                {
                    TextureInfo info = new TextureInfo();
                    info.name     = p;
                    info.refCount = refCount[p];
                    info.size.x   = texObj.width;
                    info.size.y   = texObj.height;
                    info.mipmap   = texObj.mipmapCount;
                    info.format   = texObj.format;
                    s_AssetInfo.textureInfo.Add(info);
                }

                Shader shaderObj = obj as Shader;
                if (shaderObj != null)
                {
                    ShaderInfo info = new ShaderInfo();
                    info.name     = p;
                    info.refCount = refCount[p];
                    s_AssetInfo.shaderInfo.Add(info);
                }
            }
            EditorUtility.ClearProgressBar();
            EditorUtility.UnloadUnusedAssetsImmediate();

            string outputFile = Application.dataPath + "AssetAnalysis.json";

            SerializeHelper.SaveToFile(s_AssetInfo, outputFile, true);


            {
                string fileName = Application.dataPath + "texture.csv";
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                FileStream   file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter sw   = new StreamWriter(file);
                string       line = "path,width,height,format,mipmap,refCount";
                sw.WriteLine(line);
                for (int i = 0; i < s_AssetInfo.textureInfo.Count; ++i)
                {
                    TextureInfo info = s_AssetInfo.textureInfo[i];
                    //if(info.size.x > 128 || info.size.y > 128)
                    {
                        line = info.name + "," + info.size.x + "," + info.size.y + "," + info.format.ToString() + "," + info.mipmap + "," + info.refCount;
                        sw.WriteLine(line);
                    }
                }

                sw.Flush();
                file.Flush();
                file.Close();
            }

            Debug.Log("分析完毕!");
        }