示例#1
0
    public VerInfo BuildFileTxt(List <AssetBundleBuild> list)
    {
        //string filePath = outPath + "/"+m_BuildResInfo.ResName+".txt";
        VerInfo infos = new VerInfo();

        infos.ver = ProjectBuild.version;
        foreach (AssetBundleBuild ab in list)
        {
            for (int i = infos.files.Count - 1; i >= 0; i--)
            {
                if (infos.files[i].fileName == ab.assetBundleName)
                {
                    infos.files.RemoveAt(i);
                }
            }
            ABInfo info = new ABInfo();
            info.fileName = ab.assetBundleName;
            info.sha1     = BuildAB.GenHashOne(outPath + "/" + ab.assetBundleName, ref info.length);
            infos.files.Add(info);
            foreach (string str in ab.assetNames)
            {
                info.assets.Add(Path.GetFileName(str));
            }
        }
        return(infos);
        //File.WriteAllText(filePath , JsonUtility.ToJson(infos, true));
    }
示例#2
0
    public void OnGUI()
    {
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("选择路径"))
        {
            _defaultPath = EditorUtility.OpenFolderPanel("选择路径", "", "");
            _defaultPath = _defaultPath.Replace(Application.dataPath + "/", "");
        }

        //输入框控件
        GUILayout.TextField(_defaultPath);

        GUILayout.EndHorizontal();

        for (int i = 0; i < 4; ++i)
        {
            EditorGUILayout.Space();
        }

        if (GUILayout.Button("开始打包"))
        {
            BuildAB.InitConfig();

            BuildAB.BuildPartCore("Assets/" + _defaultPath);
        }


        EditorGUILayout.Space();
        EditorGUILayout.Space();
    }
示例#3
0
    /// <summary>
    /// 清除ab文件名
    /// </summary>
    /// <param name="path"></param>
    private static void ClearAssetBundleName(string path)
    {
        Caching.CleanCache();
        try
        {
            if (Directory.Exists(path))
            {
                string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    //后缀名
                    string ext = Path.GetExtension(path);
                    if (!BuildAB.IsNoPack(ext))
                    {
                        string filePath = BuildAB.ConvertPath(file);

                        AssetImporter importer = AssetImporter.GetAtPath(filePath);
                        if (importer)
                        {
                            if (importer.assetBundleName != "")
                            {
                                importer.assetBundleName = "";
                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message + ",清除AB名字出错");
        }
    }
示例#4
0
    public VerInfo BuildRes(string rootPath, BuildTarget traget, BuildAssetBundleOptions options)
    {
        if (string.IsNullOrEmpty(m_BuildResInfo.ResParentPath))
        {
            return(null);
        }
        Dictionary <string, AssetBundleBuild> maps = new Dictionary <string, AssetBundleBuild>();

        BuildAB.HandleBundleAB(AppConst.ABPath + m_BuildResInfo.ResParentPath, ref maps);
        List <AssetBundleBuild> list = new List <AssetBundleBuild>();
        ResCfg resCfg = null;

        if (File.Exists(AppConst.CoreDef.EditorResCfgPath))
        {
            TextAsset resCfgtext = AssetDatabase.LoadAssetAtPath <TextAsset>(AppConst.CoreDef.EditorResCfgPath);
            resCfg = JsonUtility.FromJson <ResCfg>(resCfgtext.text);
        }
        foreach (string abName in maps.Keys)
        {
            AssetBundleBuild abb   = maps[abName];
            List <string>    files = new List <string>();
            foreach (string file in abb.assetNames)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (name == "defaultres" || (resCfg != null && resCfg.GetResInfo(name) != null))
                {
                    files.Add(file);
                }
                else
                {
                    Debug.LogError("有文件放在ab文件夹下  但是没有加入到配置表" +
                                   ",可能是无效的资源将不被打包到ab abName=" + name);
                }
            }
            abb.assetNames = files.ToArray();
            list.Add(abb);
        }

        BuildPipeline.BuildAssetBundles(rootPath, list.ToArray(), options, traget);
        CompressFiles(list);
        return(BuildFileTxt(list));
    }
示例#5
0
    //[UnityEditor.MenuItem("Tools/bulid")]
    public static void BuildProjected()
    {
        Debug.LogError("生成AB");
        string assetName = Trans ? (int)currentCollection + "Trans" : (int)currentCollection + "";

        assetName += ".asset";
        BuildCollectionResInfo builfCfg = null;
        string buildCfgpath             = "Assets/YKFramwork/Editor/BuildAbInfo/Collections/"
                                          + assetName;

        builfCfg = AssetDatabase.LoadAssetAtPath <BuildCollectionResInfo>(buildCfgpath);
        if (builfCfg == null)
        {
            Debug.LogError("加载不到builfCfg" + buildCfgpath + "/ccc=" + currentCollection);
            return;
        }

        if (builfCfg)
        {
            SetIconAndBg(builfCfg);
            SetUmengXinXI(builfCfg);
            builfCfg.Build();
        }

        Debug.Log("生成ab完成");
        BuildAB.BuildResIni();
        Debug.Log("准备生成APK");
        //BuildAB.BuildAb();
        if (CurrenBuildTarget == BuildTargetGroup.Android)
        {
            BuildForAndroid(builfCfg);
        }
        else if (CurrenBuildTarget == BuildTargetGroup.iOS)
        {
            BuildForIos(builfCfg);
        }
        else if (CurrenBuildTarget == BuildTargetGroup.Standalone)
        {
        }
    }
示例#6
0
    //[UnityEditor.MenuItem("Tools/bulid")]
    public static void BuildProjected()
    {
        //AssetDatabase.FindAssets(currentCollection +"t:"+ BuildCollectionResInfo.)

        BuildCollectionResInfo builfCfg = BuildCollectionResInfo.Find((int)currentCollection);

        if (builfCfg == null)
        {
            Debug.LogError("加载不到builfCfg    " + currentCollection);
            return;
        }

        if (builfCfg)
        {
            builfCfg.Build();
            SetLocalGameCfg(builfCfg);
        }
        Debug.Log("生成ab完成");
        BuildAB.BuildResIni();
        Debug.Log("准备生成APK");
        EditorPrefs.SetInt(savecollection, (int)currentCollection);
        //BuildAB.BuildAb();
        BuildPlayer(builfCfg, CurrenBuildTarget);
    }
示例#7
0
 public void Build()
 {
     BuildAB.BuildCollectionsResByInfo(this);
 }
示例#8
0
 public void Build()
 {
     ProjectBuild.currentCollection = (ProjectBuild.CollectionType)CollectionID;
     BuildAB.BuildCollectionsResByInfo(this);
 }
示例#9
0
    public static void Json2Prefab(string outPath, string dirName)
    {
        string[] jsonPaths = Directory.GetFiles(outPath, "*.json", SearchOption.AllDirectories);


        List <Model> modelList = new List <Model>();

        foreach (string jsonPath in jsonPaths)
        {
            // if(!PSD2UI.isMD5Change(jsonPath))
            // {
            //  continue;
            // }
            StreamReader jsonReader = File.OpenText(jsonPath);
            if (jsonReader != null)
            {
                string jsonStr = jsonReader.ReadToEnd();
                Model  model   = JsonUtility.FromJson <Model> (jsonStr);
                modelList.Add(model);
            }
        }

        if (modelList.Count <= 0)
        {
            return;
        }

        PSD2UI.curBaseAssetsDir = outPath;

        for (var i = 0; i < modelList.Count; i++)
        {
            var model = modelList[i];

            for (var j = model.children.Length - 1; j >= 0; j--)
            {
                oneCopyImgToTmpPath(model.children[j], dirName);
            }
        }
        copyImgToTmpPathFromPNGExport(dirName);


        //打包临时文件的图集
        Debug.Log("######开始打图集######");
        string srcPath = PSD2UI.texturePackerTempPath + dirName;
        string tarPath = PSDConst.GUI_PATH + dirName + "/" + dirName + ".png";

        AtlasManager.InitAtlasForTextureP(srcPath, tarPath);

        Debug.Log("######图集打完,开始加载UI######");
        string path1 = PSDConst.GetPrefabPathByName("Canvas");
        Canvas temp1 = AssetDatabase.LoadAssetAtPath(path1, typeof(Canvas)) as Canvas;
        // 实例化显示prefab(要另外用个对象保存避免被释放)
        Canvas canvas = GameObject.Instantiate(temp1) as Canvas;


        for (var i = 0; i < modelList.Count; i++)
        {
            var        model   = modelList[i];
            string     path3   = PSDConst.GetPrefabPathByName("GameObject");
            GameObject temp    = AssetDatabase.LoadAssetAtPath(path3, typeof(GameObject)) as GameObject;
            GameObject gameobj = GameObject.Instantiate(temp) as GameObject;
            gameobj.name = model.name + "Prefab";
            gameobj.transform.SetParent(canvas.gameObject.transform, false);
            RectTransform rect = gameobj.GetComponent <RectTransform>();
            // 总预设锚点再左上角(父锚点,锚点)
            Vector2 anchorP = PSDConst.PIVOTPOINT1;
            rect.anchorMin = anchorP;
            rect.anchorMax = anchorP;
            rect.pivot     = anchorP;
            rect.offsetMin = new Vector2(0.0f, 0.0f);
            rect.offsetMax = new Vector2(0.0f, 0.0f);
            rect.sizeDelta = new Vector2(model.options.width, model.options.height);
            for (int j = model.children.Length - 1; j >= 0; j--)
            {
                initComponent(model.children[j], gameobj, dirName);
            }

            string prefabPath = PSDConst.GUI_PATH + dirName + "/" + model.name + "Prefab.prefab";
            Debug.Log("######创建预设:" + prefabPath + "######");
            PrefabUtility.CreatePrefab(prefabPath, gameobj, ReplacePrefabOptions.ReplaceNameBased);
        }


        SetAssetBundleName();
        BuildAB.BuildAllAssetBundles();

        AssetDatabase.Refresh();
    }
示例#10
0
 /// <summary>
 /// 生成这个资源包
 /// </summary>
 public void Build(int flag)
 {
     BuildAB.BuildResByInfo(this, flag);
 }