Exemplo n.º 1
0
 // Start is called before the first frame update
 void Start()
 {
     DontDestroyOnLoad(this);
     try
     {
         main = Application.dataPath + "/Lua/" + "Main.lua";
         Clua.InitCSharpDelegate(Clua.LogMessageFromCpp); //c++ log委托绑定
         Debug.Log(Clua.myAdd(10, 8));
         L = Clua.luaL_newstate();
         Clua.luaL_openlibs(L);
         Clua.LuaLogerInit(L);
         UnityEngine_GameObjectWrap.Register(L);
         int index = Clua.luaL_dofile(L, main);
         Debug.Log("执行dofile的返回值 " + index);
         double xx = Clua.CallLuaFunc(L, "main", 10, 18);
         Clua.luaCall(L, "Start");
         Debug.Log("-------------" + xx);
         Debug.Log("-------------");
         foreach (var item in LuaManager.Instance.luaObjectDic)
         {
             Debug.Log("xxx " + item.Key + ":" + item.Value);
         }
     }
     catch (Exception e)
     {
         Debug.LogError(e.Message);
     }
 }
Exemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     Clua.luaCall(L, "Update");
     if (Input.GetKeyDown(KeyCode.Space))
     {
         Debug.Log("调用c函数结果是: " + Clua.myAdd(20, 19));
     }
 }
Exemplo n.º 3
0
    static int GameObject_Find(IntPtr L)
    {
        string name = Clua.lua_tostring(L, -1);

        UnityEngine.GameObject go = UnityEngine.GameObject.Find(name);
        if (go)
        {
            //Clua.lua_pushlightuserdata(L, go);
        }
        else
        {
            UnityEngine.Debug.LogError("go is null");
            return(0);
        }
        return(1);
    }
Exemplo n.º 4
0
    public static void Register(IntPtr L)
    {
        Clua.lua_newtable(L);
        int spaceIdx = Clua.lua_gettop(L);

        Clua.luaL_newmetatable(L, typeof(UnityEngine.GameObject).Name);
        int metatableIdx = Clua.lua_gettop(L);

        Clua.lua_pushvalue(L, metatableIdx);
        Clua.lua_setfield(L, metatableIdx, typeof(UnityEngine.GameObject).Name);
        Clua.lua_pushstring(L, "create");
        LuaCSFunction lcf = new LuaCSFunction(create_GameObject);

        Clua.lua_pushcsfunction(L, lcf);
        Clua.lua_rawset(L, metatableIdx);
        Clua.lua_pushstring(L, "Find");
        LuaCSFunction lcff = new LuaCSFunction(GameObject_Find);

        Clua.lua_pushcsfunction(L, lcff);
        Clua.lua_rawset(L, metatableIdx);
        Clua.lua_setfield(L, spaceIdx, typeof(UnityEngine.GameObject).Name);
        Clua.lua_setglobal(L, typeof(UnityEngine.GameObject).Namespace);
    }
Exemplo n.º 5
0
    static int create_GameObject(IntPtr L)
    {
        try
        {
            int count = Clua.lua_gettop(L);
            //UnityEngine.Debug.Log("创建物体的名字是参数个数 "+count);
            string name = Clua.lua_tostring(L, -1);
            //UnityEngine.Debug.Log("创建物体的名字 :" + name);

            UnityEngine.GameObject go = new UnityEngine.GameObject(name);

            //Clua.lua_pushstring(L,"创建gameobject成功 "+go.name);
            IntPtr data = Clua.lua_newuserdata(L, go);

            LuaManager.Instance.luaObjectDic.Add(data.ToInt64(), go);
            //Clua.lua_pushlightuserdata(L, data);
        }
        catch (IOException message)
        {
            UnityEngine.Debug.LogError(message.Message);
        }

        return(1);
    }
Exemplo n.º 6
0
 private void OnApplicationQuit()
 {
     Clua.luaCall(L, "OnApplicationQuit");
     Clua.lua_close(L);
 }
Exemplo n.º 7
0
 private void FixedUpdate()
 {
     Clua.luaCall(L, "FixedUpdate");
 }