Exemple #1
0
        //select//
        public override object OnSelect(string strFullName)
        {
            //清空当前数据//
            curPack = null;
            //mDep.Reset();

            //读文件//
            GOEPackV5 si = JsonUtil.ReadJsonObject(strFullName) as GOEPackV5;

            if (null != si)
            {
                curPack = si;
            }
            else
            {
                Debug.Log("parse error:");
            }

            return(curPack);
        }
Exemple #2
0
        bool DoPack(bool silent, BuildTarget target, out string error, HashSet <string> excludePackSet, out Dictionary <string, object> extra, out AssetBundleManifest buildManifest)
        {
            extra         = new Dictionary <string, object>();
            buildManifest = null;

            BuildTargetGroup buildTargetGroup = ConvertBuildTarget(target);

            if (!EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, target))
            {
                error = "buildtarget platform : " + target.ToString();
                return(false);
            }

            if (!silent && !UnityEditor.EditorUtility.DisplayDialog("确认打包", "此操作会对所有修改过的资源进行打包,继续吗?", "是", "否"))
            {
                error = null;
                return(true);
            }

            AssetDatabase.SaveAssets();

            string[] files = Directory.GetFiles("Assets/EngineCoreEditor/Editor/PackV5/Definitions/", "*.pack.txt");

            List <AssetBundleBuild> builds       = new List <AssetBundleBuild>();
            List <string>           rawAssetList = new List <string>();

            string outputDir = GetBundleOutputPath(target);

            string currentSceneBeforeBuild = EditorSceneManager.GetActiveScene().path;

            //打开一个空场景
            EditorSceneManager.OpenScene("Assets/EmptyScene.unity");

            foreach (string packConfig in files)
            {
                bool shoudlSkip = excludePackSet != null && excludePackSet.Contains(Path.GetFileName(packConfig));
                if (shoudlSkip)
                {
                    continue;
                }

                //打包选项配置
                GOEPackV5 si = JsonUtil.ReadJsonObject(packConfig) as GOEPackV5;
                string    packingResFolder = si.SrcDir;
                if (!Directory.Exists(packingResFolder))
                {
                    Debug.LogWarningFormat("{0} target resource folder:{1} not exist,ignore build", packConfig, packingResFolder);
                    continue;
                }

                if (si == null)
                {
                    error = "无法读取文件:" + packConfig;
                    if (!silent)
                    {
                        EditorUtility.DisplayDialog("打包错误", error, "确定");
                    }
                    return(false);
                }

                List <AssetBundleBuild> b;
                HashSet <string>        allAssetSet = null;

                if (!si.ConfigureAssetImporter(silent, out error, out b, extra, shoudlSkip, out allAssetSet))
                {
                    return(false);
                }

                if (PackEntry.RawAsset.Contains(Path.GetFileName(packConfig)))
                {
                    rawAssetList.AddRange(allAssetSet);
                }
                else
                {
                    if (!shoudlSkip)
                    {
                        builds.AddRange(b);
                    }
                }
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

            //UnityEditor.Sprites.Packer.SelectedPolicy = "DefaultPackerPolicy1024";

            string currentPackBundleMapPath = Path.Combine(outputDir, BUNDLE_DIR_NAME);         //manifest的bundle没有后缀

            if (builds.Count == 0)
            {
                error = "无打包资源,请检查.pack文件,及.pack文件的Filter";
                return(false);
            }

            buildManifest = BuildPipeline.BuildAssetBundles(outputDir, builds.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, target);

            string rawAssetDir = Path.Combine(outputDir, PathConfig.RAW_ASSET_PATH);

            EngineFileUtil.ClearOrCreateEmptyFolder(rawAssetDir);

            foreach (string rawAssetPath in rawAssetList)
            {
                string fileName = Path.GetFileName(rawAssetPath);
                string dstPath  = Path.Combine(rawAssetDir, fileName);

                File.Copy(rawAssetPath, dstPath, true);
            }

            if (buildManifest == null)
            {
                error = "打包失败,manifest 文件为空";
                return(false);
            }

            DeleteUselessBundleFiles(buildManifest, outputDir);

            //todo:guangze song  2018-9-5 21:45:39:Editor下,切Scene会把堆对象清空(切Scene之后Manifest被清空)
            //if (!string.IsNullOrEmpty(currentSceneBeforeBuild))
            //    EditorSceneManager.OpenScene(currentSceneBeforeBuild, OpenSceneMode.Single);

            error = string.Empty;
            return(true);
        }
Exemple #3
0
        public override void MakeEditUI(object target)
        {
            GOEPackV5 pack = target as GOEPackV5;

            if (null == pack)
            {
                return;
            }

            GUILayout.BeginVertical();

            //打包//
            MakeMultipleActionUI();

            if (GUILayout.Button("打包"))
            {
                string error;
                Dictionary <string, object> e;
                AssetBundleManifest         buildManifest;
                DoPack(false, getBestPackOrder()[0], out error, null, out e, out buildManifest);
            }

            //打包项编辑//
            GUILayout.Label("编辑Bundles");
            for (int i = 0; i < pack.PackItems.Count; i++)
            {
                PackBundleSetting bundle = pack.PackItems[i];
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {//两个宽度30的按钮=一个宽度64的按钮//
                    //删除打包项//
                    pack.PackItems.RemoveAt(i);
                }
                GUILayout.Label(bundle.BundleName);

                //todo:如类型为场景则提供逐个打包选项//
                if (bundle.PackType == "Scene")
                {
                    //if (GUILayout.Button("列举场景", GUILayout.Width(140)))
                    //{
                    //    lastDetailBundle = bundle;
                    //    lastDetailList = bundle.BuildSrcFileList(pack.SrcDir);
                    //}

                    //GUILayout.EndHorizontal();
                    //if (lastDetailBundle == bundle)
                    //{
                    //    foreach (string scn in lastDetailList)
                    //    {
                    //        string scnFN = Path.GetFileName(scn);
                    //        if (GUILayout.Button(scnFN))
                    //        {
                    //            DoPackScene(scn);
                    //        }
                    //    }
                    //}
                }
                else
                {
                    GUILayout.EndHorizontal();
                }
            }
            //添加//
            if (GUILayout.Button("添加Bundle", GUILayout.Width(140)))
            {
                pack.PackItems.Add(new PackBundleSetting());
                //更新属性窗口//
                JsonObjectPropertyWindow wp = EditorWindow.GetWindow(typeof(JsonObjectPropertyWindow), false, "Property") as JsonObjectPropertyWindow;
                wp.Show();
                wp.SetCurStringInterface(pack, this);
            }

            GUILayout.EndVertical();
        }