Esempio n. 1
0
    /// <summary>
    /// 把制定打包的AB文件移动到streamingAssets文件夹中适当的位置,要先清空文件夹后移动
    /// </summary>
    /// <param name="bt">BuildTarget的类型,一般都是打目标版本的类型</param>
    public static void MoveAssetBundleToStreamingAssets(BuildTarget bt)
    {
        RuntimePlatform runtimePlatform = AssetBundleSettingHelperEditor.BuildTargetToRuntimePlatform(bt);
        string          versionName     = GetABSH().RuntimePlatformToSimplifyName(runtimePlatform);

        //string streamingAssetsPath = AssetBundleHelper.GetStreamingAssetsPath();
        //清理三个文件夹
        ABPInfo[] deleteABPIs = new ABPInfo[3];
        deleteABPIs[0] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.WindowsEditor));
        deleteABPIs[1] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.OSXEditor));
        deleteABPIs[2] = GetABSH().GetStreamingAssetABPath(ABSH.RuntimePlatformToSimplifyName(RuntimePlatform.Android));
        foreach (var abpiTmp in deleteABPIs)
        {
            if (Directory.Exists(abpiTmp.Dir_Relative))
            {
                Directory.Delete(abpiTmp.Dir_Relative, true);
            }
        }
        var abpiTar = GetABSH().GetStreamingAssetABPath(versionName);

        Directory.CreateDirectory(abpiTar.Dir_Relative);
        var abpi = GetABSH().GetAssetBundleOutputPath(versionName);

        CopyFolder(abpi.Dir_Relative, abpiTar.Dir_Relative);

        AssetDatabase.Refresh();
    }
Esempio n. 2
0
    public static void OutputXml()
    {
        if (ABSH == null)
        {
            ABSH = AssetBundleSettingHelperEditor.GetABSH(out ABPHInfo);
            if (ABPHInfo == null)
            {
            }
        }
        Selection.activeObject = ABSH;

        var abpi = ABSH.GetDataAnalysisXmlABPI();

        if (!Directory.Exists(abpi.Dir_Relative))
        {
            Directory.CreateDirectory(abpi.Dir_Relative);
        }
        XmlDocument doc     = new XmlDocument();
        XmlElement  AllRoot = doc.CreateElement(AssetBundleSettingHelper.xmlNode_PhaseRoot);

        doc.AppendChild(AllRoot);
        foreach (var p in PhaseABPreloadInfos_EditorAnalysis)
        {
            p.Value.OutputXMlNode(doc, AllRoot);
        }

        doc.Save(abpi.FullName_RelativePath);
    }
Esempio n. 3
0
    /// <summary>
    /// 打AB包
    /// </summary>
    /// <param name="options">打包选项</param>
    /// <param name="bt">打包类型</param>
    /// <param name="bIncrementalUpdate">是否增量打包,现在还没有什么用</param>
    public static void BuildAssetBundle(BuildAssetBundleOptions options, BuildTarget bt, bool bIncrementalUpdate = true)
    {
        ABSHInitAndSelect();

        //DateTimeString = DateTime.Now.ToString(VersionXmlInfo.DateFormat);
        VersionInfo.version = DateTime.Now;
        MyDic.ClearAllDic();
        ABDependenciesPositive.Clear();
        ABDependenciesReverse.Clear();
        RuntimePlatform runtimePlatform = AssetBundleSettingHelperEditor.BuildTargetToRuntimePlatform(bt);
        string          versionName     = ABSH.RuntimePlatformToSimplifyName(runtimePlatform);
        var             abpi            = ABSH.GetAssetBundleOutputPath(versionName);

        if (!bIncrementalUpdate)
        {
            //不进行增量更新,删除全部文件重新生成
            if (Directory.Exists(abpi.Dir_Relative))
            {
                Directory.Delete(abpi.Dir_Relative, true);
            }
        }
        else
        {
            //增量更新
            //这里并不需要做什么
        }
        if (!Directory.Exists(abpi.Dir_Relative))
        {
            Directory.CreateDirectory(abpi.Dir_Relative);
        }
        //在VersionInfo被覆盖前获得用来在下边做对比使用
        var lastVersionInfo = GetABVersionInfo(versionName);
        //获取所有需要打包的资源
        var buildMap = GetBuildMapByVersion(versionName);
        var manifest = BuildPipeline.BuildAssetBundles(abpi.Dir_Relative, buildMap, options, bt);

        if (manifest != null)
        {
            //生成新的versioninfo
            GenABVersionInfo(manifest, versionName);
            if (lastVersionInfo != null)
            {
                //其实这里的newAB和changedAB并不准备用来干什么,真正有用的只有delAB,这个需要把多余的AssetBundle文件和文件夹删除
                Dictionary <string, string> newAB;
                Dictionary <string, string> delAB;
                Dictionary <string, KeyValuePair <string, string> > changedAB;
                CompareOldInfoAndNewManifest(lastVersionInfo, manifest, versionName, out newAB, out delAB, out changedAB);
                if (delAB != null && delAB.Count > 0)
                {
                    DeleteAssetBundleFilesAndEmptyFolders(versionName, delAB);
                }
            }
            //生成依赖信息
            GenABDependenciesInfo(versionName);

            //最后把一些空的文件夹和新版本不需要的assetbundle
            AssetDatabase.Refresh();
        }
    }
 public static void ABSHInitAndSelect()
 {
     if (ABSH == null)
     {
         ABSH = AssetBundleSettingHelperEditor.GetABSH(out ABPHInfo);
     }
     Selection.activeObject = ABSH;
 }
    void OnDestroy()
    {
        if (bDirty)
        {
            AssetBundleSettingHelperEditor.SaveABSH(ABSH, ABPHInfo);
        }
//      ABSH = null;
//      ABPHInfo = null;
    }