Ejemplo n.º 1
0
    static void GenerateSelectEnchantEffect()
    {
        CreateEnchantEffectAssetbundleFolder();

        string targetpath = EditorUtility.OpenFolderPanel("选择需要打包的光效", Application.dataPath + "/Add On Resource/EnchantEffect/", "");

        if (string.IsNullOrEmpty(targetpath))
        {
            return;
        }

        if (!targetpath.Contains("EnchantEffect"))
        {
            EditorUtility.DisplayDialog("文件夹路径错误", "无效的光效文件夹,光效路径必须在[Assets/Add On Resource/EnchantEffect/]文件夹下", "确定");
            return;
        }
        targetpath = "Assets" + targetpath.Replace(Application.dataPath, "");

        BuildPipeline.PushAssetDependencies();

        List <string> shdList = BuildShader.BuildAllShader("all");

        ProcEnchantEffect_Dir(targetpath, shdList);

        BuildPipeline.PopAssetDependencies();
    }
Ejemplo n.º 2
0
    public static void GenerateAllEnchantEffect()
    {
        CreateEnchantEffectAssetbundleFolder();

        BuildPipeline.PushAssetDependencies();

        List <string> shdList = BuildShader.BuildAllShader("all");

        ProcEnchantEffect_Dir(AssetBundlePath.EnchantEffectAssetPath, shdList);

        BuildPipeline.PopAssetDependencies();

        //ProcLightMaterial();
    }
Ejemplo n.º 3
0
    static void GenerateAllMaterials()
    {
        if (!Directory.Exists(MaterialsAssetbundlePath))
        {
            Directory.CreateDirectory(MaterialsAssetbundlePath);
        }

        BuildPipeline.PushAssetDependencies();
        List <string> shdList = BuildShader.BuildAllShader("all");

        BuildPipeline.PushAssetDependencies();

        BuilderDefualtTexture();
        ProcMaterials_Dir(MaterialsSrcDir);

        BuildPipeline.PopAssetDependencies();

        BuildPipeline.PopAssetDependencies();
    }
Ejemplo n.º 4
0
    static void GenerateSelectMaterials()
    {
        string tagpath = EditorUtility.OpenFolderPanel("", Application.dataPath + "/Add On Resource/Characters/Models/", "");

        if (string.IsNullOrEmpty(tagpath) && !tagpath.Contains(MaterialsSrcDir))
        {
            return;
        }
        tagpath = "Assets" + tagpath.Replace(Application.dataPath, "");
        BuildPipeline.PushAssetDependencies();
        List <string> shdList = BuildShader.BuildAllShader("all");

        BuildPipeline.PushAssetDependencies();

        BuilderDefualtTexture();


        ProcMaterials_Dir(tagpath);

        BuildPipeline.PopAssetDependencies();
        BuildPipeline.PopAssetDependencies();
    }
Ejemplo n.º 5
0
    static void XBuildBundle(bool mat)
    {
        CleanOld();

        var objs = Selection.objects;
        List <AssetBundleBuild> builds = new List <AssetBundleBuild>();

        foreach (var it in objs)
        {
            AssetBundleBuild build = new AssetBundleBuild();
            var pat = AssetDatabase.GetAssetPath(it);
            build.assetBundleName = it.name;
            build.assetNames      = new string[] { pat };
            builds.Add(build);
        }
        builds.Add(BuildShader.InnerBuildShader(mat));
        var option = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle;

        BuildPipeline.BuildAssetBundles(dir, builds.ToArray(), option, EditorUserBuildSettings.activeBuildTarget);

        FinishEditor();
    }
Ejemplo n.º 6
0
    public static void  GenerateDynamicPrefab()
    {
        string bundleParentPath = AssetBundlePath.PrefabAssetRootPath + "/";

        if (!Directory.Exists(bundleParentPath))
        {
            Directory.CreateDirectory(bundleParentPath);
        }

        BuildPipeline.PushAssetDependencies();
        BuildShader.BuildAllShader("all");

        List <string> prefabSrcDirList = new List <string>();

        prefabSrcDirList.Add(AssetBundlePath.DynamicPrefabBasicAssetDir);
#if !PACKAGE_BASIC
        prefabSrcDirList.Add(AssetBundlePath.DynamicPrefabAssetDir);
#endif

        ProcDynamicPrefab_All(prefabSrcDirList);

        BuildPipeline.PopAssetDependencies();
    }
Ejemplo n.º 7
0
    public static void ProcUIScene(List <string> specialList, List <string> uiScenePrefabList, List <string> prefabList)
    {
        AssetBundleConfig uiConfig     = new AssetBundleConfig();                                            //UI配置文件
        AssetBundleConfig prefabConfig = new AssetBundleConfig();                                            //动态Prefab配置文件

        Dictionary <string, AssetBundleType> allAssetBundleMap = new Dictionary <string, AssetBundleType>(); //记录所有打包的Asset
        List <string> comAssetList     = new List <string>();                                                //记录所有公共资源
        List <string> ignoreBundleList = new List <string>();                                                //需要删除的资源

#if PACKAGE_BASIC
        //添加小包过滤操作
        Dictionary <string, string> extendAssetMap = new Dictionary <string, string>();
        List <string> basicAssetList = new List <string>();
#endif

        //开始打包资源
        BuildPipeline.PushAssetDependencies();

        //打包部分指定Shader
        List <string> shdList = BuildShader.BuildAllShader("all");

        //打包Special Texture
        foreach (string texturePath in specialList)
        {
            string sTemp       = texturePath.Replace('\\', '/');
            int    startIndex  = sTemp.LastIndexOf('/') + 1;
            int    endIndex    = sTemp.LastIndexOf('.') - 1;
            string textureName = sTemp.Substring(startIndex, endIndex - startIndex + 1);

            if (!allAssetBundleMap.ContainsKey(textureName))
            {
                string parentPath = GetParentPath(texturePath);
                if (!Directory.Exists(parentPath))
                {
                    Directory.CreateDirectory(parentPath);
                }

                if (!BuildAssetBundle.IsLegalAsset(textureName))
                {
                    Debug.LogError("Build ui error, asset name is not all lower," + texturePath);
                    EditorUtility.DisplayDialog("Error", "Build ui error, asset name is not all lower,Please try again!" + texturePath, "OK");
                    return;
                }

                Texture2D tex2D = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D;
                string    path  = parentPath + textureName + "." + AssetBundleType.Texture.ToString().ToLower();

                BuildAssetBundle.Build(tex2D, null, path, true);

                allAssetBundleMap.Add(textureName, AssetBundleType.Texture);
            }
        }

        //获取依赖关系
        Dictionary <string, List <DependencyAsset> > prefabAssetRefMap = BuildAssetBundle.GetAssetDependencieRefs(prefabList.ToArray());        //获取动态Prefab依赖关系
        Dictionary <string, List <DependencyAsset> > uiAssetRefMap     = BuildAssetBundle.GetAssetDependencieRefs(uiScenePrefabList.ToArray()); //获取UI依赖关系

        Dictionary <string, List <DependencyAsset> > allAssetRefMap = new Dictionary <string, List <DependencyAsset> >(uiAssetRefMap);
        if (prefabAssetRefMap != null && prefabAssetRefMap.Count > 0)
        {
            foreach (string prefabPath in prefabAssetRefMap.Keys)
            {
                if (!allAssetRefMap.ContainsKey(prefabPath))
                {
                    allAssetRefMap.Add(prefabPath, prefabAssetRefMap[prefabPath]);
                }
            }
        }

        //排序
        List <string> allAssetRefKeyList = null;
        if (allAssetRefMap != null && allAssetRefMap.Count > 0)
        {
            allAssetRefKeyList = new List <string>(allAssetRefMap.Keys);
            allAssetRefKeyList.Sort(new UICompare());
        }

        //获取所有脚本
        if (allAssetRefKeyList != null && allAssetRefKeyList.Count > 0)
        {
            foreach (string uiscenePath in allAssetRefKeyList)
            {
                List <DependencyAsset> val = allAssetRefMap[uiscenePath];
                foreach (DependencyAsset dasset in val)
                {
                    string          sceneDepPath = dasset.AssetPath;
                    AssetBundleType assetType    = dasset.AssetType;

                    if (assetType == AssetBundleType.Script)
                    {
                        if (!comAssetList.Contains(sceneDepPath))
                        {
                            comAssetList.Add(sceneDepPath);
                        }
                    }
                    else if (assetType == AssetBundleType.ScriptDLL)
                    {
                        string dllPath = AssetBundlePath.DLLPrefabAssetDir + dasset.AssetName + ".prefab";
                        if (File.Exists(dllPath))
                        {
                            if (!comAssetList.Contains(dllPath))
                            {
                                comAssetList.Add(dllPath);
                            }
                        }
                        else
                        {
                            Debug.LogError("Build UI failed. Can not find dll file prefab, path=" + dllPath);
                        }
                    }
                }
            }
        }

        //打包公共资源
        if (comAssetList != null && comAssetList.Count > 0)
        {
            //创建界面目录
            string comParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/";               //场景目录
            if (!Directory.Exists(comParentPath))
            {
                Directory.CreateDirectory(comParentPath);
            }

            List <Object> comObjectList = new List <Object>();
            for (int i = 0; i < comAssetList.Count; ++i)
            {
                comObjectList.Add(AssetDatabase.LoadAssetAtPath(comAssetList[i], typeof(Object)));
            }

            BuildAssetBundle.Build(null, comObjectList.ToArray(), comParentPath + "ui_common" + "." + AssetBundleType.Scene.ToString().ToLower(), true);

            comObjectList.Clear();
        }

        //打包其他资源
        if (allAssetRefKeyList != null && allAssetRefKeyList.Count > 0)
        {
            foreach (string rootAssetPath in allAssetRefKeyList)
            {
                AssetBundleConfig bundleConfig  = null;
                string            rootAssetName = BuildAssetBundle.GetAssetName(rootAssetPath);
                AssetBundleType   rootAssetType = BuildAssetBundle.GetAssetType(rootAssetPath);

                //确定配置文件
                if (uiScenePrefabList.Contains(rootAssetPath))
                {
                    bundleConfig = uiConfig;
                }
                else if (prefabList.Contains(rootAssetPath))
                {
                    bundleConfig = prefabConfig;
                }
                else
                {
                    Debug.LogError("Build ui error, can not find current assetType," + rootAssetType + "," + rootAssetPath);
                }

                List <DependencyAsset> depList = allAssetRefMap[rootAssetPath];
                for (int i = 0; i < depList.Count; ++i)
                {
                    DependencyAsset dasset           = depList[i];
                    AssetBundleType arType           = dasset.AssetType;
                    string          assetName        = dasset.AssetName;
                    string          assetFullName    = dasset.AssetName + "." + dasset.AssetSuffix;
                    string          assetPath        = dasset.AssetPath;
                    string          bundleParentPath = AssetBundlePath.UIAssetRootPath + arType + "/";
                    string          bundlePath       = bundleParentPath + assetName + "." + arType.ToString().ToLower();
                    bool            popDependence    = false;

                    if (arType == AssetBundleType.Max)
                    {
                        Debug.LogError("BuildUI error, unSupport assetBundle," + rootAssetPath);
                    }

                    if (IgnoreAssetList.Contains(assetFullName))
                    {
                        if (!ignoreBundleList.Contains(bundlePath))
                        {
                            ignoreBundleList.Add(bundlePath);
                        }
                    }
                    else
                    {
                        if (rootAssetName.Equals(assetName))
                        {
                            popDependence = true;
                        }
                        else if (dasset.IsLeaf || assetPath.Replace('\\', '/').Contains(AssetBundlePath.ArtUIDir))
                        {
                            if (arType == AssetBundleType.Script || arType == AssetBundleType.ScriptDLL)
                            {
                                continue;
                            }
                            else if (arType == AssetBundleType.Shd && shdList.Contains(assetFullName))
                            {
                                //忽略已经打包的Shader,此操作为了兼容旧版本
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }

                        bundleConfig.AddConfig(rootAssetName, arType, assetName, i);
                    }

                    if (!allAssetBundleMap.ContainsKey(assetName))
                    {
                        if (!BuildAssetBundle.IsLegalAsset(assetName))
                        {
                            Debug.LogError("Build ui error, asset name is not all lower," + assetPath);
                            EditorUtility.DisplayDialog("Error", "Build ui error, asset name is not all lower,Please try again!" + assetPath, "OK");
                            return;
                        }

                        BuildBundle(assetPath, bundleParentPath, bundlePath, dasset.IsLeaf, popDependence);

                        allAssetBundleMap.Add(assetName, arType);
#if PACKAGE_BASIC
                        //记录扩展包资源
                        if (IsExtendPackageScene(rootAssetPath) && !extendAssetMap.ContainsKey(assetPath))
                        {
                            if (specialList.Contains(assetPath))
                            {                            //Check it again.
                                Debug.LogError("Special texture dictionary has same texture,TexturePath=" + assetPath + ".UIScenePath=" + rootAssetPath);
                            }
                            else
                            {
                                extendAssetMap.Add(assetPath, bundlePath);
                            }
                        }
                        //记录小包资源
                        if (IsBasicPackageScene(rootAssetPath) && !basicAssetList.Contains(assetPath))
                        {
                            basicAssetList.Add(assetPath);
                        }
#endif
                    }
                    else
                    {
                        AssetBundleType usedType = allAssetBundleMap[assetName];
                        if (usedType != arType)
                        {
                            Debug.LogError("Build UI error, same asset name has been found.AssetName=" +
                                           assetName + "." + arType + "," + assetName + "." + usedType
                                           + ".UIPath=" + rootAssetPath);
                        }
                    }
                }
            }
        }

        //保存UI界面配置文件
        if (uiScenePrefabList != null && uiScenePrefabList.Count > 0)
        {
            string uisceneParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/";                   //场景目录
            if (!Directory.Exists(uisceneParentPath))
            {
                Directory.CreateDirectory(uisceneParentPath);
            }

            uiConfig.SaveConfig(uisceneParentPath + "uiconfig.txt");
        }
        else
        {
            Debug.Log("Build UI tips:no scene found.");
        }

        //保存Prefab配置文件
        if (prefabList != null && prefabList.Count > 0)
        {
            string prefabconfigParentPath = AssetBundlePath.UIAssetRootPath + AssetBundleType.Scene + "/";
            if (!Directory.Exists(prefabconfigParentPath))
            {
                Directory.CreateDirectory(prefabconfigParentPath);
            }
            prefabConfig.SaveConfig(prefabconfigParentPath + "uiprefabconfig.txt");
        }
        else
        {
            Debug.Log("Build UI tips:no dynamic prefab found.");
        }

        //删除忽略的资源
        foreach (string delPath in ignoreBundleList)
        {
            if (!string.IsNullOrEmpty(delPath))
            {
                File.Delete(delPath);
            }
        }

#if PACKAGE_BASIC
        //过滤小包中用到的资源
        foreach (string basicAssetPath in basicAssetList)
        {
            if (extendAssetMap.ContainsKey(basicAssetPath))
            {
                extendAssetMap.Remove(basicAssetPath);
            }
        }

        //删除扩展包资源
        foreach (string path in extendAssetMap.Values)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Build basic package error, can not delete unuse texture");
            }
            else
            {
                File.Delete(path);
            }
        }
#endif

        //结束打包资源
        BuildPipeline.PopAssetDependencies();

        AssetDatabase.Refresh();
    }