[游戏开发][Unity]Assetbundle加载篇(2)中间层API

文章介绍了用于游戏开发的资源管理框架,中间层API旨在简化开发代码与ResourceManager的交互。该框架支持C#和Lua的多平台重载,提供了一系列如加载预设、纹理、文本、音频等资源的方法,并通过回调处理加载结果。
摘要由CSDN通过智能技术生成

目录

打包与资源加载框架目录

正文

中间层API的作用时,让开发代码和ResourceManager之间的交互更加清晰,所有API的返回值一定是个资源Loader

非常重要的一点是,同一类型的加载也要支持C#和Lua的多平台重载,例如LoadTextAsset

    //加载文本
    //加载bytes/xml等文本文件也用该接口
    public static TextFileLoader LoadTextAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetTextFileLoader(_url, callback, AutoRelease);
    }

    //加载文本
    //Lua接口
    public static TextFileLoader LoadTextAsset(string _url, Action<LuaTable,AssetLoaderBase, bool> callback,LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetTextFileLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller,loader, result);
            }
            , AutoRelease);
    }

LoadAssetUtility代码如下 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
public delegate void OnLoadCallback(AssetLoaderBase loader, bool state);

public class LoadAssetUtility
{
    // 加载预设
    public static GameObjectLoader LoadGameObject(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetGameObjectLoader(_url, callback, AutoRelease);
    }
    
    加载2D贴图
    public static TextureLoader LoadTexture2D(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetTextureLoader(_url, callback, AutoRelease);
    }

    //加载文本
    //加载bytes/xml等文本文件也用该接口
    public static TextFileLoader LoadTextAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetTextFileLoader(_url, callback, AutoRelease);
    }

    //加载文本
    //Lua接口
    public static TextFileLoader LoadTextAsset(string _url, Action<LuaTable,AssetLoaderBase, bool> callback,LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetTextFileLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller,loader, result);
            }
            , AutoRelease);
    }

    //加载文本
    //加载bytes/xml等文本文件也用该接口
    public static ByteLoader LoadByteAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetByteLoader(_url, callback, AutoRelease);
    }

    //加载Byte
    //Lua接口
    public static ByteLoader LoadByteAsset(string _url, Action<LuaTable,AssetLoaderBase, bool> callback, LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetByteLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller,loader, result);
            }
            , AutoRelease);
    }

    //加载图集
    public static AtlasLoader LoadAtlasAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetAtlasLoader(_url, callback, AutoRelease);
    }

    //加载图集
    //Lua接口
    public static AtlasLoader LoadAtlasAsset(string _url, Action<LuaTable, AssetLoaderBase, bool> callback, LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetAtlasLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller, loader, result);
            }
            , AutoRelease);
    }

    //加载音频
    public static AudioLoader LoadAudioAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetAudioLoader(_url, callback, AutoRelease);
    }

    加载音频
    //public static void LoadVedio(string _url, Action<string, VideoClip> callback)
    //{
    //    AA.LoadAsset<VideoClip>(_url, callback, _binded = null);
    //}

    //加载材质
    public static MaterialLoader LoadMaterialAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetMaterialLoader(_url, callback, AutoRelease);
    }

    //加载材质
    //Lua接口
    public static MaterialLoader LoadMaterialAsset(string _url, Action<LuaTable, AssetLoaderBase, bool> callback, LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetMaterialLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller, loader, result);
            }
            , AutoRelease);
    }

    //加载材质
    public static SceneLoader LoadSceneAsset(string _url, OnLoadCallback callback,bool isAdd, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetSceneLoader(_url, callback, isAdd, AutoRelease);
    }

    //加载材质
    //Lua接口
    public static SceneLoader LoadSceneAsset(string _url, Action<LuaTable, AssetLoaderBase, bool> callback, LuaTable caller, bool isAdd, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetSceneLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller, loader, result);
            },
            isAdd, AutoRelease);
    }

    //加载UnityAsset
    public static ConfigLoader LoadConfigAsset(string _url, OnLoadCallback callback, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetConfigLoader(_url, callback, AutoRelease);
    }

    //加载UnityAsset
    //Lua接口
    public static ConfigLoader LoadConfigAsset(string _url, Action<LuaTable, AssetLoaderBase, bool> callback, LuaTable caller, bool AutoRelease = false)
    {
        return ResourceManager.Instance.GetConfigLoader(_url,
            delegate (AssetLoaderBase loader, bool result)
            {
                callback(caller, loader, result);
            }
            , AutoRelease);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Little丶Seven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值