예제 #1
0
        public static void TestAI()
        {
            var        logger = new ToluaDemo.TestLogger();
            InitConfig cfg    = new InitConfig()
            {
                logger          = logger,
                luaDir          = LuaConst.luaDir,
                toluaDir        = LuaConst.toluaDir,
                osDir           = LuaConst.osDir,
                luaResDir       = LuaConst.luaResDir,
                zbsDir          = LuaConst.zbsDir,
                openToLuaLib    = true,//LuaConst.openToLuaLib,
                openLuaSocket   = LuaConst.openLuaSocket,
                openLuaDebugger = LuaConst.openLuaDebugger
            };

            LuaInterface.Init(cfg);
            Debug.InitLogger(new TestLogger());
            ConfigManager.Init();
            new BattleInterface();
            BattleInterface.Instance.InitBattle(2);
            var unit1 = BattleInterface.Instance.AddUnit(100005, 0, 1);
            var unit2 = BattleInterface.Instance.AddUnit(100002, 1, 1);
            var unit3 = BattleInterface.Instance.AddUnit(100004, 1, 1);

            unit1.position = new Vector3(0, 16);
            unit2.position = new Vector3(-1, 16);
            unit3.position = new Vector3(1, 16);
            float deltaTime = 0.05f;

            while (true)
            {
                Thread.Sleep(50);
                BattleInterface.Instance.Update(deltaTime);
                Debug.Log("time = " + BattleInterface.Instance.GameTimeElapsed);
                LuaEngine.LuaInterface.Update(deltaTime);
                LuaInterface.FixedUpdate(deltaTime);
                LuaInterface.LateUpdate();
                Debug.Log("");
            }
        }
예제 #2
0
        public static void TestLuaEngine()
        {
            var        logger = new ToluaDemo.TestLogger();
            InitConfig cfg    = new InitConfig()
            {
                logger          = logger,
                luaDir          = LuaConst.luaDir,
                toluaDir        = LuaConst.toluaDir,
                osDir           = LuaConst.osDir,
                luaResDir       = LuaConst.luaResDir,
                zbsDir          = LuaConst.zbsDir,
                openToLuaLib    = true,//LuaConst.openToLuaLib,
                openLuaSocket   = LuaConst.openLuaSocket,
                openLuaDebugger = LuaConst.openLuaDebugger
            };

            LuaInterface.Init(cfg);
            LuaClient client = LuaInterface.CreateLuaClient();
            //client.Init();
            LuaState    lua     = client.GetLuaState();
            LuaTable    buff    = lua.Require <LuaTable>("buff/buff001");
            LuaFunction luaFunc = buff["new"] as LuaFunction;

            luaFunc.BeginPCall();
            luaFunc.PCall();
            LuaTable buff1 = (LuaTable)luaFunc.CheckLuaTable();

            luaFunc.EndPCall();
            luaFunc.BeginPCall();
            luaFunc.PCall();
            LuaTable buff2 = (LuaTable)luaFunc.CheckLuaTable();

            luaFunc.EndPCall();
            buff1["id"] = 10;
            buff2["id"] = 20;
            Console.WriteLine(buff1["id"]);
            Console.WriteLine(buff2["id"]);
            string hello = @"coroutine.start(function() 
                    for i = 1, 10 do
                        coroutine.wait(1);
                        print(i);
                    end
                end);
                local test = {};
                test.name = 'testClass';
                function test:func()
                    print('1000'..self.name);
                end
                return test;
            ";

            LuaTable res = lua.DoString <LuaTable>(hello, "Program.cs");

            //lua.CheckTop();
            Console.WriteLine(res["name"]);
            LuaFunction lf = res["func"] as LuaFunction;

            lf.BeginPCall();
            lf.Push(res);
            lf.PCall();
            lf.EndPCall();
            while (true)
            {
                Thread.Sleep(50);
                LuaInterface.Update(0.05f);
                LuaInterface.FixedUpdate(0.05f);
                LuaInterface.LateUpdate();
            }
            //lua.Dispose();
            //lua = null;
        }