调用通用的C#方法,使用NLua的语法

我在使用NLua将Lua调用C#的通用函数的正确语法方面遇到了一些麻烦。

我试图从Lua调用以下C#XNA函数

GameWorld.Instance.Content.Load<Texture2D>("player");

但我在通用部分<T>上遇到了一些语法问题。我的当前Lua调用看起来像这样,显然是不正确的,因为我收到了一个LuaScriptException。

GameWorld.Instance.Content:Load<Texture2D>("player")
点赞
用户88888888
用户88888888

我正在创建一个名为 AssetManager 的类,并为每种资源类型配对了一对 Load/Get 方法。

class AssetManager
{
    private ContentManager content;
    private Dictionary<string, Texture2D> textures; // 字体、精灵、模型等

    AssetManager(ContentManager  pContent)
    {
        this.content = pContent;
        this.textures = new Dictionary<string, Texture2D>();
    }

    public void LoadTexture(string pName, string pAssetName)
    {
        this.textures.Add(pName, this.content.Load<Texture2D>(pAssetName));
    }
    public Texture2D GetTexture(stirng pName)
    {
        return this.textures.ContainsKey(pName) ? this.textures[pName] : null;
    }
}

可以从 C# 和 Lua 中简单使用。

2015-03-06 12:31:44