使用UnityEditor制作可视化打包AssetBundle(一)

本文介绍如何使用UnityEditor创建可视化打包AssetBundle的过程。首先,通过XML文件和解析类来管理资源信息,然后在UnityEditor窗口展示这些信息。接着,实现AssetBundle的打包和不同平台的路径设置。最后展示了打包界面的最终效果,并预告了接下来关于AssetBundle的加载内容。
摘要由CSDN通过智能技术生成

Unity版本:Unity 5.6.6f2

基本流程

  • 创建xml文件,将xml内容解析到实体类中
  • 绘制UnityEditor窗口,将xml内容绘制到窗口中
  • 打包AssetBundle
  • 加载AssetBundle(异步和同步)

准备原材料:xml和entity实体类

<?xml version="1.0" encoding="utf-8"?>
<!-- AssetBundleConfig.xml -->
<Root>
  <AssetBundle>
    <Item Name="MainCity_Role_Cike" Tag="Role" Version="1" Size="0" ToPath="/Role/">
      <Path Value="Resources\RolePrefab\RolePlayer\MainCity_Role_Cike.prefab" />
    </Item>
    <Item Name="Scene_Main" Tag="Scene" Version="1" Size="0" ToPath="/Scene/">
      <Path Value="Scene\SceneMap\Scene_Main.unity" />
    </Item>
  </AssetBundle>
</Root>
// AssetBundleEntity.cs
using System.Collections.Generic;

public class AssetBundleEntity
{
    /// <summary>
    /// 打包指定专用Key(唯一性)
    /// </summary>
    public string Key;

    /// <summary>
    /// 名称
    /// </summary>
    public string Name;

    /// <summary>
    /// 标记
    /// </summary>
    public string Tag;

    /// <summary>
    /// 版本号
    /// </summary>
    public int Version;

    /// <summary>
    /// 大小(K)
    /// </summary>
    public long Size;

    /// <summary>
    /// 将要存放的文件夹
    /// </summary>
    public string ToPath;

    /// <summary>
    /// 资源存放路径集合
    /// </summary>
    private List<string> m_PathList = new List<string>();

    public List<string> PathList
    {
        get
        {
            return m_PathList;
        }
    }
}

PathList: 后面会使用到这个属性,通过这个属性将所有资源打包Assetbundle,保存在自己定义的路径/ToPath/下

XML读取类的编写

// AssetBundleDAL.cs
using System.Collections.Generic;
using System.Xml.Linq; 

public class AssetBundleDAL
{
    /// <summary>
    /// xml路径
    /// </summary>
    private string m_XMLPath;

    /// <summary>
    /// 返回的AssetBundle实体集合
    /// </summary>
    private List<AssetBundleEntity> m_List = null;

    public AssetBundleDAL(string xmlPath)
    {
        this.m_XMLPath = xmlPath;
        m_List = new List<AssetBundleEntity>();
    }

    #region 读取xml文件 GetList
    /// <summary>
    /// 读取xml文件  存储到实体集合中
    /// </summary> 
    public List<AssetBundleEntity> GetList()
    {
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值