Esempio n. 1
0
    private static bool BuildSingleFileToAssetBundleTemp(string exportPath, string assetPath)
    {
        bool buildSingleFileAb = false;

        foreach (var path in BuildSingleFilePaths)
        {
            if (assetPath.StartsWith(path))
            {
                buildSingleFileAb = true;
                break;
            }
        }

        if (buildSingleFileAb)
        {
            var tempPath        = EditorFileUtility.GetPathWithoutExt(assetPath);
            var assetbundlePath = exportPath + "/temp/" + tempPath + ".pkg";
            if (HasBuildAssetBundleMapTemp.Contains(assetbundlePath))
            {
                return(true);
            }
            EditorFileUtility.CreateParentDirecotry(assetbundlePath);

            List <Object> objects    = new List <Object>();
            List <string> assetNames = new List <string>();
            objects.Add(AssetDatabase.LoadMainAssetAtPath(assetPath));
            assetNames.Add(assetPath);

            BuildAssetBundleWithoutCollectDependencies(objects.ToArray(), assetNames.ToArray(), assetbundlePath);
            HasBuildAssetBundleMapTemp.Add(assetbundlePath);
            return(true);
        }

        return(false);
    }
Esempio n. 2
0
    private static bool BuildAllFileToAssetBundleTemp(List <string> allChildDependences, string exportPath, string assetPath)
    {
        bool   isIncludeAllFile = false;
        string includeFilePath  = "";

        foreach (var path in BuildAllFilePaths)
        {
            if (assetPath.StartsWith(path))
            {
                isIncludeAllFile = true;
                includeFilePath  = path;
                break;
            }
        }

        if (isIncludeAllFile)
        {
            var tempPath = includeFilePath.Substring(0, includeFilePath.Length - 1);
            tempPath += "/" + Path.GetFileNameWithoutExtension(tempPath);
            var assetbundlePath = exportPath + "/temp/" + tempPath + ".pkg";
            if (HasBuildAssetBundleMapTemp.Contains(assetbundlePath))
            {
                return(true);
            }
            EditorFileUtility.CreateParentDirecotry(assetbundlePath);

            //收集所有同一个目录下(包括子目录)的asset
            List <string> allPath = new List <string>();
            foreach (var dependencePath in allChildDependences)
            {
                if (dependencePath.StartsWith(includeFilePath))
                {
                    allPath.Add(dependencePath);
                }
            }

            List <Object> objects    = new List <Object>();
            List <string> assetNames = new List <string>();

            foreach (var p in allPath)
            {
                objects.Add(AssetDatabase.LoadMainAssetAtPath(p));
                assetNames.Add(p);
            }

            BuildAssetBundleWithoutCollectDependencies(objects.ToArray(), assetNames.ToArray(), assetbundlePath);
            HasBuildAssetBundleMapTemp.Add(assetbundlePath);
            return(true);
        }
        return(false);
    }
Esempio n. 3
0
    private static bool BuildCurrentDirectoryToAssetBundleTemp(List <string> allChildDependences, string exportPath, string assetPath)
    {
        var tempPath        = EditorFileUtility.GetPath(assetPath);
        var assetBundleName = Path.GetFileName(Path.GetDirectoryName(assetPath));

        var assetBundlePath = exportPath + "/temp/" + tempPath + "/" + assetBundleName + ".pkg";

        if (HasBuildAssetBundleMapTemp.Contains(assetBundlePath))
        {
            return(true);
        }
        EditorFileUtility.CreateParentDirecotry(assetBundlePath);

        //收集和自己同一个目录下的资源(不包括子目录)
        var           currentDir         = Path.GetDirectoryName(assetPath);
        List <string> readyToBuildAssets = new List <string>();

        foreach (var dependence in allChildDependences)
        {
            if (Path.GetDirectoryName(dependence) == currentDir)
            {
                readyToBuildAssets.Add(dependence);
            }
        }

        List <Object> objects    = new List <Object>();
        List <string> assetNames = new List <string>();

        foreach (var asset in readyToBuildAssets)
        {
            objects.Add(AssetDatabase.LoadMainAssetAtPath(asset));
            assetNames.Add(asset);
        }

        BuildAssetBundleWithoutCollectDependencies(objects.ToArray(), assetNames.ToArray(), assetBundlePath);
        HasBuildAssetBundleMapTemp.Add(assetBundlePath);
        return(true);
    }
Esempio n. 4
0
    private static bool BuildAllFileToAssetBundle(string exportPath, AssetInfo asset)
    {
        bool   isIncludeAllFile = false;
        string includeFilePath  = "";

        foreach (var path in BuildAllFilePaths)
        {
            if (asset.Path.StartsWith(path))
            {
                isIncludeAllFile = true;
                includeFilePath  = path;
                break;
            }
        }

        if (isIncludeAllFile)
        {
            //判断是不是已经生成正常的AssetBundle
            var tempPath = includeFilePath.Substring(0, includeFilePath.Length - 1);
            tempPath += "/" + Path.GetFileNameWithoutExtension(tempPath);
            var assetbundlePath = exportPath + "/" + tempPath + ".pkg";
            if (HasBuildAssetBundleMap.Contains(assetbundlePath))
            {
                return(false);
            }
            EditorFileUtility.CreateParentDirecotry(assetbundlePath);

            //收集所有同一个目录下(包括子目录)的asset
            List <AssetInfo> readyToBuildAssets = new List <AssetInfo>();
            foreach (var gameAsset in GameAssets)
            {
                if (gameAsset.Value.Path.StartsWith(includeFilePath))
                {
                    readyToBuildAssets.Add(gameAsset.Value);
                }
            }

            //收集asset的所有依赖,如果依赖是同一个assetBundle下的跳过
            List <string> allChildDependences = new List <string>();
            foreach (var gameAsset in readyToBuildAssets)
            {
                foreach (var dependence in gameAsset.ChildDependences)
                {
                    if (dependence.StartsWith(includeFilePath))
                    {
                        continue;
                    }
                    allChildDependences.Add(dependence);
                }
            }

            //删除临时目录的AssetBundle
            EditorFileUtility.DeleteDirectory(exportPath + "/temp");
            HasBuildAssetBundleMapTemp.Clear();

            BuildPipeline.PushAssetDependencies();

            foreach (var dependence in allChildDependences)
            {
                if (BuildAllFileToAssetBundleTemp(allChildDependences, exportPath, dependence))
                {
                    continue;
                }

                if (BuildSingleFileToAssetBundleTemp(exportPath, dependence))
                {
                    continue;
                }

                BuildCurrentDirectoryToAssetBundleTemp(allChildDependences, exportPath, dependence);
            }

            List <Object> objects    = new List <Object>();
            List <string> assetNames = new List <string>();

            foreach (var buildAsset in readyToBuildAssets)
            {
                objects.Add(AssetDatabase.LoadMainAssetAtPath(buildAsset.Path));
                assetNames.Add(buildAsset.Path);
            }

            BuildPipeline.PushAssetDependencies();
            BuildAssetBundle(objects.ToArray(), assetNames.ToArray(), assetbundlePath);
            BuildPipeline.PopAssetDependencies();

            BuildPipeline.PopAssetDependencies();

            //配置asset的Assetbundle路径
            foreach (var buildAsset in readyToBuildAssets)
            {
                buildAsset.AssetBundlePath = tempPath + ".pkg";
            }

            HasBuildAssetBundleMap.Add(assetbundlePath);
            return(true);
        }
        return(false);
    }
Esempio n. 5
0
    private static bool BuildSingleFileToAssetBundle(string exportPath, AssetInfo asset)
    {
        bool buildSingleFile = false;

        foreach (var path in BuildSingleFilePaths)
        {
            if (asset.Path.StartsWith(path))
            {
                buildSingleFile = true;
                break;
            }
        }

        if (buildSingleFile)
        {
            //判断是不是已经生成正常的AssetBundle
            var tempPath        = EditorFileUtility.GetPathWithoutExt(asset.Path);
            var assetbundlePath = exportPath + "/" + tempPath + ".pkg";
            if (HasBuildAssetBundleMap.Contains(assetbundlePath))
            {
                return(false);
            }
            EditorFileUtility.CreateParentDirecotry(assetbundlePath);

            //收集asset的所有依赖
            List <string> allChildDependences = new List <string>();
            foreach (var dependence in asset.ChildDependences)
            {
                if (asset.Path == dependence)
                {
                    continue;
                }
                allChildDependences.Add(dependence);
            }

            //删除临时目录的AssetBundle
            EditorFileUtility.DeleteDirectory(exportPath + "/temp");
            HasBuildAssetBundleMapTemp.Clear();

            BuildPipeline.PushAssetDependencies();

            foreach (var dependence in allChildDependences)
            {
                if (BuildAllFileToAssetBundleTemp(allChildDependences, exportPath, dependence))
                {
                    continue;
                }

                if (BuildSingleFileToAssetBundleTemp(exportPath, dependence))
                {
                    continue;
                }

                BuildCurrentDirectoryToAssetBundleTemp(allChildDependences, exportPath, dependence);
            }

            List <Object> objects    = new List <Object>();
            List <string> assetNames = new List <string>();

            objects.Add(AssetDatabase.LoadMainAssetAtPath(asset.Path));
            assetNames.Add(asset.Path);

            BuildPipeline.PushAssetDependencies();
            BuildAssetBundle(objects.ToArray(), assetNames.ToArray(), assetbundlePath);
            BuildPipeline.PopAssetDependencies();

            BuildPipeline.PopAssetDependencies();

            //配置asset的Assetbundle路径
            asset.AssetBundlePath = tempPath + ".pkg";
            HasBuildAssetBundleMap.Add(assetbundlePath);
            return(true);
        }

        return(false);
    }
Esempio n. 6
0
    private static void BuildCurrentDirectoryToAssetBundle(string exportPath, AssetInfo asset)
    {
        //判断是不是已经生成正常的AssetBundle
        var tempPath        = EditorFileUtility.GetPath(asset.Path);
        var assetBundleName = Path.GetFileName(Path.GetDirectoryName(asset.Path));
        var assetBundlePath = exportPath + "/" + tempPath + "/" + assetBundleName + ".pkg";

        if (HasBuildAssetBundleMap.Contains(assetBundlePath))
        {
            return;
        }
        EditorFileUtility.CreateParentDirecotry(assetBundlePath);

        //收集和自己同一个目录下的资源(不包括子目录)
        var currentDir = Path.GetDirectoryName(asset.Path);
        List <AssetInfo> readyToBuildAssets = new List <AssetInfo>();

        foreach (var gameAsset in GameAssets)
        {
            if (Path.GetDirectoryName(gameAsset.Value.Path) == currentDir)
            {
                readyToBuildAssets.Add(gameAsset.Value);
            }
        }

        //收集asset的所有依赖,如果依赖是同一个assetBundle下的跳过
        List <string> allChildDependences = new List <string>();

        foreach (var gameAsset in readyToBuildAssets)
        {
            foreach (var dependence in gameAsset.ChildDependences)
            {
                if (Path.GetDirectoryName(dependence) != currentDir)
                {
                    allChildDependences.Add(dependence);
                }
            }
        }

        //删除临时目录的AssetBundle
        EditorFileUtility.DeleteDirectory(exportPath + "/temp");
        HasBuildAssetBundleMapTemp.Clear();

        BuildPipeline.PushAssetDependencies();

        foreach (var dependence in allChildDependences)
        {
            if (BuildAllFileToAssetBundleTemp(allChildDependences, exportPath, dependence))
            {
                continue;
            }

            if (BuildSingleFileToAssetBundleTemp(exportPath, dependence))
            {
                continue;
            }

            BuildCurrentDirectoryToAssetBundleTemp(allChildDependences, exportPath, dependence);
        }

        List <Object> objects    = new List <Object>();
        List <string> assetNames = new List <string>();

        foreach (var buildAsset in readyToBuildAssets)
        {
            objects.Add(AssetDatabase.LoadMainAssetAtPath(buildAsset.Path));
            assetNames.Add(buildAsset.Path);
        }

        BuildPipeline.PushAssetDependencies();
        BuildAssetBundle(objects.ToArray(), assetNames.ToArray(), assetBundlePath);
        BuildPipeline.PopAssetDependencies();

        BuildPipeline.PopAssetDependencies();

        //配置asset的Assetbundle路径
        foreach (var buildAsset in readyToBuildAssets)
        {
            buildAsset.AssetBundlePath = tempPath + "/" + assetBundleName + ".pkg";
        }
        HasBuildAssetBundleMap.Add(assetBundlePath);
    }