Пример #1
0
    private static BundleData CreateBundleData(string path)
    {
        BundleData data = new BundleData();

        data.assetPath = path;
        data.name      = Path.GetFileNameWithoutExtension(path);
        data.guid      = AssetDatabase.AssetPathToGUID(path);
        data.depends   = BuildHelp.GetDependencies(path);
        return(data);
    }
Пример #2
0
    private static void NewBuildAssetBundle()
    {
        List <BundleData> bundleDatas = GetAllSelectBundleDatas();


        //  all shader

        var shaderList = BuildHelp.GetDependencies("Assets/LocalResources/Shader.prefab", s => s.EndsWith(".shader"));
        AssetBundleBuild buildShader = new AssetBundleBuild();

        buildShader.assetBundleName = "shader";
        buildShader.assetNames      = new string[shaderList.Count];
        int index = 0;

        foreach (string shaderPath in shaderList)
        {
            buildShader.assetNames[index] = shaderPath;
            SetBundleName(shaderPath, buildShader.assetNames[index]);
            ++index;
        }

        HashSet <string>        filterStr    = new HashSet <string>();
        List <AssetBundleBuild> allListBuild = new List <AssetBundleBuild>();

        allListBuild.Clear();
        allListBuild.Add(buildShader);

        for (int i = 0; i < bundleDatas.Count; i++)
        {
            if (!filterStr.Contains(bundleDatas[i].name))
            {
                allListBuild.Add(CreateBundleBuild(bundleDatas[i].assetPath, bundleDatas[i].name));
                filterStr.Add(bundleDatas[i].name);
            }
            foreach (var dependPath in bundleDatas[i].depends)
            {
                string name = Path.GetFileNameWithoutExtension(dependPath);
                if (!filterStr.Contains(name))
                {
                    allListBuild.Add(CreateBundleBuild(dependPath, name));
                    filterStr.Add(name);
                }
            }
        }

        if (Directory.Exists(BundleSetting.PlatformOutputPathNew) == false)
        {
            Directory.CreateDirectory(BundleSetting.PlatformOutputPathNew);
        }

        BuildPipeline.BuildAssetBundles(BundleSetting.PlatformOutputPathNew, allListBuild.ToArray(), BuildAssetBundleOptions.None, BundleSetting.UnityBuildTarget);
        Debug.Log(BundleSetting.PlatformOutputPathNew);
    }
Пример #3
0
    private static List <string> GetObjectPathByConfig()
    {
        List <string> result = new List <string>();

        var defaultPath = BundleSetting.SelectDefaultPath;

        //  do somethings
        for (int i = 0; i < defaultPath.Count; i++)
        {
            result.AddRange(BuildHelp.FindAllSuffixAssetToFile(defaultPath[i].path, defaultPath[i].suffix));
        }

        return(result);
    }
Пример #4
0
    private static void InitState()
    {
        if (DependsData == null)
        {
            DependsData = new List <BundleDependsData>();
        }
        else
        {
            DependsData.Clear();
        }

        BundleManager.ClearBundleData();
        Debug.ClearDeveloperConsole();
        BuildHelp.CreateOutputPath();
    }
Пример #5
0
    public static void LogFilterDependsInfo()
    {
        StringBuilder sb = new StringBuilder(1024);

        Object[] selectObjects = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
        foreach (var iter in selectObjects)
        {
            sb.Length = 0;
            var ownerObj = AssetDatabase.GetAssetPath(iter);
            var depends  = BuildHelp.GetDependencies(ownerObj);
            sb.AppendLine(ownerObj);
            sb.AppendLine("[");
            for (int i = 0; i < depends.Count; i++)
            {
                sb.AppendFormat("\t{0}\n", depends[i]);
            }
            sb.AppendLine("]");
            Debug.Log(sb.ToString());
        }
    }
Пример #6
0
    private static void BuildAll()
    {
        InitState();

        LoadShaderList();

        List <string> buildList = GetObjectPathByConfig();

        List <BundleData> bundles = new List <BundleData>();

        for (int i = 0; i < buildList.Count; i++)
        {
            bundles.Add(AddRootBundleData(buildList[i]));
        }


        for (int i = 0; i < bundles.Count; i++)
        {
            if (BuildHelp.BuildRootBundle(bundles[i]))
            {
                DependsData.Add(CreateDependsData(bundles[i]));
            }
        }
        //BuildPipeline.BuildAssetBundles()
        //
        if (DependsData.Count > 0)
        {
            string dependsConfigPath = BuildHelp.GenerateOutputDependsPath();
            BMDataAccessor.SaveBundleBuildeStates();
            BMDataAccessor.SaveObjectToJsonFile <List <BundleDependsData> >(DependsData, dependsConfigPath);
            BMDataAccessor.SaveReleaseDependsData(DependsData, BundleSetting.PlatformOutputPath + "/DependsData.release");
            BMDataAccessor.ClearBundleBuildStates(DependsData);
            DependsData.Clear();
        }
        else
        {
            Debug.Log("There is no written DependsData.txt!");
        }
    }
Пример #7
0
    private static AssetBundleBuild[] GetCommonBuilds()
    {
        AssetBundleBuild[] result = new AssetBundleBuild[1];

        //  common shader
        var shaderList = BuildHelp.GetDependencies("Assets/LocalResources/Shader.prefab", s => s.EndsWith(".shader"));
        AssetBundleBuild buildShader = new AssetBundleBuild();

        buildShader.assetBundleName = "shader";
        buildShader.assetNames      = new string[shaderList.Count];
        int index = 0;

        foreach (string shaderPath in shaderList)
        {
            buildShader.assetNames[index] = shaderPath;
            SetBundleName(shaderPath, buildShader.assetNames[index]);
            ++index;
        }
        result[0] = buildShader;


        return(result);
    }
Пример #8
0
    public static void BuildAloneSelectObject()
    {
        Object[] objs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets);
        if (objs.Length == 0)
        {
            return;
        }

        InitState();

        List <BundleData> bundles = Objects2Bundles(objs);

        for (int i = 0; i < bundles.Count; i++)
        {
            if (BuildHelp.BuildRootBundle(bundles[i]))
            {
                DependsData.Add(CreateDependsData(bundles[i]));
            }
        }

        string dependsConfigPath = BuildHelp.GenerateOutputDependsPath();

        if (File.Exists(dependsConfigPath))
        {
            List <BundleDependsData> diskConfigData = BMDataAccessor.LoadObjectFromJsonFile <List <BundleDependsData> >(dependsConfigPath);
            for (int i = 0; i < DependsData.Count; i++)
            {
                InsertBundleData(DependsData[i], ref diskConfigData);
            }
            BMDataAccessor.SaveObjectToJsonFile <List <BundleDependsData> >(diskConfigData, dependsConfigPath);
        }
        else
        {
            BMDataAccessor.SaveObjectToJsonFile <List <BundleDependsData> >(DependsData, dependsConfigPath);
        }
    }