[Unity] 编辑器创建AssetBundles打包方法(二)

创建XML文件,并添加数据

<?xml version="1.0" encoding="utf-8" ?>
<Root>
    <AssetBundle>
        <Item Name="Role_MainPlayer" Tag="Role" Version="1" Size="0" ToPath="/Role/">
            <Path Value="Resources\RolePrefab\Player\Role_MainPlayer.prefab" />
        </Item>
        <Item Name="GameScene_CunZhuang" Tag="Scene" Version="1" Size="0" ToPath="/Scene/">
            <Path Value="Scene\SceneMap\GameScene_CunZhuang.unity" />
        </Item>
    </AssetBundle>
</Root> 

创建AssetBundle实体类AssetBundleEntity,并创建属性

using UnityEngine;
using System.Collections;
using NUnit.Framework;
using System.Collections.Generic;

/// <summary>
/// AssetBundle实体
/// </summary>
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;

    private List<string> m_PathList = new List<string>();
    /// <summary>
    /// 路径集合
    /// </summary>
    public List<string> PathList
    {
        get { return m_PathList; }
    }
}

创建AssetBundle控制类AssetBundleDAL

using UnityEngine;
using System.Collections;
using NUnit.Framework;
using System.Collections.Generic;
using System.Xml.Linq;

public class AssetBundleDAL
{
    /// <summary>
    /// XML路径
    /// </summary>
    private string m_Path;
    /// <summary>
    /// 返回的数据集合
    /// </summary>
    private List<AssetBundleEntity> m_List = null;

    public AssetBundleDAL(string path)
    {
        m_Path = path;
        m_List = new List<AssetBundleEntity>();
    }

    /// <summary>
    /// 返回XML数据
    /// </summary>
    /// <returns></returns>
    public List<AssetBundleEntity> GetList()
    {
        m_List.Clear();

        return m_List;
    }
}

本文链接:

https://www.eggmo.net/archives/260/

转载请注明文章链接地址!Thanks♪(・ω・)ノ

1 + 7 =
快来做第一个评论的人吧~