U3D对话任务插件 Dialogue System for Unity 研究(二)

在Dialogue System for Unity中,对话编辑器里使用LUA脚本,LUA和C#的交互方式为:

C#调用LUA:C#中通过插件的API使用LUA。

LUA调用C#:C#中注册函数绑定到LUA环境,需要注意,LUA那边只支持double,string,bool。

综合考虑,暂时将所有的数据还是要保存到C#这边,存档使用EasySave3,不使用对话插件带的存档。

一. Lua 调用 C#

1.注册C#函数到LUA

官方模板脚本:Plugins\Pixel Crushers\Dialogue System\Templates\Scripts\TemplateCustomLua

这里我写了一个最简单的,注册函数,让LUA获取和设置time。

using UnityEngine;
using PixelCrushers.DialogueSystem;


public  class RegisterFunctionToLua : MonoBehaviour 
{

    int time = 55;

    void OnEnable()
    {
        //静态方法 this 改为NULL
        Lua.RegisterFunction("GetTime", this, SymbolExtensions.GetMethodInfo(() => GetTime()));
        Lua.RegisterFunction("SetTime", this, SymbolExtensions.GetMethodInfo(() => SetTime((double)0)));
    }

    void OnDisable()
    {
      

猜你喜欢

转载自blog.csdn.net/u012322710/article/details/127009317
今日推荐