Exemplo n.º 1
0
        // 会将目录下的每个prefab引用的资源强制打成一个包,不分析共享资源
        private static void SetIndependentBundleAndAtlas(string dir)
        {
            List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir);

            foreach (string path in paths)
            {
                string path1 = path.Replace('\\', '/');
                Object go    = AssetDatabase.LoadAssetAtPath <Object>(path1);

                AssetImporter importer = AssetImporter.GetAtPath(path1);
                if (importer == null || go == null)
                {
                    Debug.LogError("error: " + path1);
                    continue;
                }
                importer.assetBundleName = $"{go.name}";

                List <string> pathes = CollectDependencies(path1);

                foreach (string pt in pathes)
                {
                    if (pt == path1)
                    {
                        continue;
                    }

                    SetBundleAndAtlas(pt, go.name, true);
                }
            }
        }
Exemplo n.º 2
0
        // 分析共享资源
        private void SetShareBundleAndAtlas(string dir)
        {
            this.dictionary.Clear();
            List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir);

            foreach (string path in paths)
            {
                string path1 = path.Replace('\\', '/');
                Object go    = AssetDatabase.LoadAssetAtPath <Object>(path1);

                SetBundle(path1, go.name);

                List <string> pathes = CollectDependencies(path1);
                foreach (string pt in pathes)
                {
                    if (pt == path1)
                    {
                        continue;
                    }

                    // 不存在则记录下来
                    if (!this.dictionary.ContainsKey(pt))
                    {
                        // 如果已经设置了包
                        if (GetBundleName(pt) != "")
                        {
                            continue;
                        }
                        Debug.Log($"{path1}----{pt}");
                        BundleInfo bundleInfo = new BundleInfo();
                        bundleInfo.ParentPaths.Add(path1);
                        this.dictionary.Add(pt, bundleInfo);

                        SetAtlas(pt, go.name);

                        continue;
                    }

                    // 依赖的父亲不一样
                    BundleInfo info = this.dictionary[pt];
                    if (info.ParentPaths.Contains(path1))
                    {
                        continue;
                    }
                    info.ParentPaths.Add(path1);

                    DirectoryInfo dirInfo = new DirectoryInfo(dir);
                    string        dirName = dirInfo.Name;

                    SetBundleAndAtlas(pt, $"{dirName}-share", true);
                }
            }
        }
Exemplo n.º 3
0
        private static void ClearPackingTagAndAssetBundle()
        {
            //List<string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/Bundles/", true);
            //foreach (string bundlePath in bundlePaths)
            //{
            //	SetBundle(bundlePath, "", true);
            //}

            List <string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true);

            foreach (string pt in paths)
            {
                SetBundleAndAtlas(pt, "", true);
            }
        }
Exemplo n.º 4
0
        private static void SetNoAtlas(string dir)
        {
            List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir);

            foreach (string path in paths)
            {
                List <string> pathes = CollectDependencies(path);

                foreach (string pt in pathes)
                {
                    if (pt == path)
                    {
                        continue;
                    }

                    SetAtlas(pt, "", true);
                }
            }
        }
Exemplo n.º 5
0
        private static void SetBundleAndAtlasWithoutShare(string dir, string dirPath, bool subDir = false, string bundleName = null)
        {
            List <string> paths = EditorResHelper.GetAllResourcePath(dir, subDir);

            foreach (string path in paths)
            {
                string path1 = path.Replace('\\', '/');
                Object go    = AssetDatabase.LoadAssetAtPath <Object>(path1);

                SetBundle(path1, bundleName == null ? Path.Combine(dirPath, go.name) : bundleName);

                //List<string> pathes = CollectDependencies(path1);
                //foreach (string pt in pathes)
                //{
                //	if (pt == path1)
                //	{
                //		continue;
                //	}
                //
                //	SetBundleAndAtlas(pt, go.name);
                //}
            }
        }
Exemplo n.º 6
0
        // 会将目录下的每个prefab引用的资源强制打成一个包,不分析共享资源
        //private static void SetBundles(string dir)
        //{
        //	List<string> paths = EditorResHelper.GetPrefabsAndScenes(dir);
        //	foreach (string path in paths)
        //	{
        //		string path1 = path.Replace('\\', '/');
        //		Object go = AssetDatabase.Instance.LoadAssetAtPath<Object>(path1);

        //		SetBundle(path1, go.name);
        //	}
        //}

        // 会将目录下的每个prefab引用的资源打成一个包,只给顶层prefab打包
        //private static void SetRootBundleOnly(string dir)
        //{
        //	List<string> paths = EditorResHelper.GetPrefabsAndScenes(dir);
        //	foreach (string path in paths)
        //	{
        //		string path1 = path.Replace('\\', '/');
        //		Object go = AssetDatabase.Instance.LoadAssetAtPath<Object>(path1);

        //		SetBundle(path1, go.name);
        //	}
        //}

        private static void SetFairyGUI()
        {
            string        end   = "_fui.bytes";
            List <string> paths = EditorResHelper.GetPrefabsAndScenes("Assets/" + PathHelper.UIPath);

            foreach (var path in paths)
            {
                if (path.EndsWith(end))
                {
                    string start = path.Substring(0, path.Length - end.Length);
                    //Debug.Log(start);
                    foreach (var path0 in paths)
                    {
                        if (path0.StartsWith(start))
                        {
                            string path1 = path0.Replace('\\', '/');
                            Object go    = AssetDatabase.LoadAssetAtPath <Object>(path1);

                            SetBundle(path1, Path.Combine(PathHelper.UIPath, Path.GetFileNameWithoutExtension(start) + (path0 == path ? "desc" : "res")));
                        }
                    }
                }
            }
        }