Ejemplo n.º 1
0
 //重加载一个脚本文件,变量的值会全部恢复.
 public void CallScript(string script)
 {
     try
     {
         if (!string.IsNullOrEmpty(script))
         {
             if (File.Exists(Application.persistentDataPath + "/" + script))
             {
                 svr.start(Application.persistentDataPath + "/" + script);
             }
             else
             {
                 svr.start(script);
             }
         }
         else
         {
             Debug.Log("script file is null or empty");
         }
     }
     catch (Exception exp)
     {
         Debug.LogError(exp.Message + ":" + exp.StackTrace);
     }
 }
Ejemplo n.º 2
0
    void Start()
    {
        lua  = new LuaSvr();
        self = (LuaTable)lua.start("LuaFiles/building_txt");
        //self = (LuaTable)lua.luaState.getObject("data");
        //object o = lua.luaState.getFunction("GetData").call();
        Debug.Log("table " + ((LuaTable)self[1])["name"]);


        LuaFunction dataFunction = ((LuaFunction)self["GetData"]);
        LuaTable    dataTable    = (LuaTable)dataFunction.call();
        LuaFunction callFunction = (LuaFunction)self["CallBack"];

        callFunction.call(222);
        //lua.luaState.getFunction("CallBack").call();
        lua.luaState.getFunction("Call").call(2);
        Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + "   is Null " + (callFunction == null));


        LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call();

        Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]);
        LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1");

        test2 = (LuaFunction)self["test"];
        object o = test2.call(self, 9, 1);

        Debug.Log("add function :" + o);

        SetTransform = (LuaFunction)self["SetTransform"];
        SetTransform.call(self, tr);
        //tr.localPosition = new Vector3(2, 2, 2);
    }
Ejemplo n.º 3
0
 //主状态上.加载脚本后,运行以main为名称的函数
 public void CallScript(string script)
 {
     try
     {
         if (!string.IsNullOrEmpty(script))
         {
             string p = string.Format("{0}/{1}", Application.persistentDataPath, script);
             if (File.Exists(p))
             {
                 svr.start(p);
             }
             else
             {
                 svr.start(script);
             }
         }
         else
         {
             Debug.Log("script file is null or empty");
         }
     }
     catch (Exception exp)
     {
         Debug.LogError(string.Format("{0}:{1}", exp.Message, exp.StackTrace));
     }
 }
Ejemplo n.º 4
0
    void complete()
    {
        if (LGameConfig.GetInstance().isShowFps)
        {
            LFPSView.Show();
        }

        if (!LGameConfig.GetInstance().isDebug) //生产环境
        {
            if (LGameConfig.GetInstance().isHotFix)
            {
                GameObject canvas    = GameObject.Find("Canvas");
                Text       lab_unzip = null;
                if (canvas.transform.Find("prog"))
                {
                    canvas.transform.Find("prog").gameObject.SetActive(true);
                    lab_unzip = canvas.transform.Find("prog/lab_unzip").GetComponent <Text>();
                }

                GameObject obj = new GameObject();
                obj.name = "ResUpdate";
                LResUpdate resUpdate = obj.AddComponent <LResUpdate> ();
                resUpdate.onUnzipProgressHandler = (int step) => {
                    if (lab_unzip)
                    {
                        lab_unzip.text = step.ToString();
                    }
                    Debug.Log(" unzip " + step);
                };
                resUpdate.onCompleteHandler = () => {
                    Destroy(obj);
                    LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () =>
                    {
                        _l.start("main");
                    });
                };
                resUpdate.checkUpdate();
            }
            else
            {
                LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () =>
                {
                    _l.start("main");
                });
            }
        }
        else //PC端开发
        {
            _l.start("main");
        }
    }
Ejemplo n.º 5
0
        void OnLaunched()
        {
            m_launched = true;
            SLua.Logger.Log("OnSvrLaunched");

            DoBind(m_luaState.L);

            LuaEvtCenter.Enable = true;

            //入口文件可以不叫main,但要有一个global的main方法, 其返回一个含有luaSvr_update等方法的一个表
            m_luaTable = m_luaSvr.start("main") as LuaTable;

            m_luaUpdate     = ((LuaFunction)m_luaTable["luaSvr_update"]).cast <LuaDelegate_Update>();
            m_luaLateUpdate = ((LuaFunction)m_luaTable["luaSvr_lateUpdate"]).cast <LuaDelegate_Update>();
            m_luaNotify     = ((LuaFunction)m_luaTable["luaSvr_notify"]).cast <LuaDelegate_Notify>();
            //m_luaNotify = (LuaFunction)m_luaTable["luaSvr_notify"];
            m_luaNotifyError = ((LuaFunction)m_luaTable["luaSvr_notifyCsError"]).cast <LuaDelegate_NotifyError>();

            Application.logMessageReceived += UnityLogCallback; //监听unitys的log


            LuaFunction luaLaunch = (LuaFunction)m_luaTable["luaSvr_launch"];

            if (luaLaunch != null)
            {
                luaLaunch.call();
            }
        }
Ejemplo n.º 6
0
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () => {
         luaSvr.start("useLua");
     }, LuaSvrFlag.LSF_DEBUG);
 }
Ejemplo n.º 7
0
    void LuaVMReady()
    {
        lua.start("HelloLua.lua");

        /*
         * if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
         * {
         *  // 注意: 当在editor下运行时,直接使用 ROOT/lua 目录下的原始文件,不会使用更新下来的文件
         *  lua.luaState.doString("package.path = '" + Application.dataPath + "/Lua/?.lua'");
         *  // StartGameLogic();
         *
         *  lua.luaState.doString("require 'HelloLua'");
         * }
         * else
         * {
         *  // string cachePath = Application.temporaryCachePath;
         *  // lua.luaState.doString("package.path = '" + cachePath + "/lua/?.lua'");
         *  // if (!Directory.Exists(cachePath + "/lua"))
         *  // {
         *  //     MyLogger.Info("首次运行,正在准备基础文件...");
         *  //     WWWLoader.LoadFromStreaming("scripts.pack", UnpackScripts, UnpackScriptsError);
         *  // }
         *  // else
         *  // {
         *  //     StartGameLogic();
         *  // }
         * }
         */
    }
Ejemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        l = new LuaSvr();
        l.init(null, () =>
        {
            l.start("valuetype");
        });

        using (LuaState newState = new LuaState())
        {
            LuaTable table = new LuaTable(newState);

            Vector2 v2  = new Vector2(1, 2);
            Vector3 v3  = new Vector3(1, 2, 3);
            Vector4 v4  = new Vector4(1, 2, 3, 4);
            Color   col = new Color(.1f, .2f, .3f);
            Foo     foo = new Foo();

            table["v2"]  = v2;
            table["v3"]  = v3;
            table["v4"]  = v4;
            table["col"] = col;
            table["foo"] = foo;

            Assert.IsTrue((Vector2)table["v2"] == v2);
            Assert.IsTrue((Vector3)table["v3"] == v3);
            Assert.IsTrue((Vector4)table["v4"] == v4);
            Assert.IsTrue((Color)table["col"] == col);
            Assert.IsTrue(table["foo"] == foo);
        }
    }
Ejemplo n.º 9
0
 void complete()
 {
     LuaSvr.mainState.loaderDelegate += LuaLoder;
     lua_Svr.start("Lua_BagEvent");
     LuaSvr.mainState.getFunction("getroot").call(this.gameObject);
     LuaSvr.mainState.getFunction("EventMain").call();
 }
Ejemplo n.º 10
0
 void complete()
 {
     LuaSvr.mainState.loaderDelegate += LuaLoder;
     lua_Svr.start("UseClass");
     LuaSvr.mainState.getFunction("GetRoot").call(this.gameObject);
     LuaSvr.mainState.getFunction("ClassMain").call();
 }
Ejemplo n.º 11
0
        public void StartLuaSvr(Action <bool> onComplete)
        {
            string    initModulePath  = GetModulePath(m_luaInitModuleName);
            TextAsset initModuleAsset = null;

            initModuleAsset = ResourceManager.Instance.LoadAsset <TextAsset>(initModulePath);

            if (initModuleAsset == null)
            {
                Debug.LogError("StartLuaSvr fail load initModuleAsset fail");
                onComplete(false);
            }

            // 构造lua state 环境
            m_luaSvr = new LuaSvr();

            // 设置lua模块加载器
            LuaSvr.mainState.loaderDelegate = LuaLoader;

            // 初始化lua环境
            m_luaSvr.init(null, () =>
            {
                // 加载初始化模块
                if (!string.IsNullOrEmpty(m_luaInitModuleName))
                {
                    m_luaSvr.start(m_luaInitModuleName);
                }
            });
            onComplete(true);
        }
Ejemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () => {
         l.start("delegate");
     });
 }
Ejemplo n.º 13
0
 void Start()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         self = (LuaTable)svr.start("skynet/main");
     }, LuaSvrFlag.LSF_EXTLIB);
 }
Ejemplo n.º 14
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("LuaTest");
     });
 }
Ejemplo n.º 15
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("varobj");
     });
 }
Ejemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () =>
     {
         self = (LuaTable)luaSvr.start("startGame");
     });
 }
Ejemplo n.º 17
0
 void Awake()
 {
     _instance     = this;
     svr           = new LuaSvr();
     self          = (LuaTable)svr.start("LuaFiles/LuaCallCsAPI");
     self["event"] = DataEventSource.Instance;
     self["name"]  = "API";
 }
Ejemplo n.º 18
0
 // Use this for initialization
 void Start()
 {
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("valuetype");
     });
 }
Ejemplo n.º 19
0
    /// <summary>
    /// 从resouce目录加载Lua脚本,并初始化
    /// </summary>
    /// <param name="_rsPath">Resouce下的目录</param>
    /// <param name="_forceReading">是否强制读取</param>
    public SLua.LuaTable RsLoad(string _rsPath)
    {
        Log("加载:" + _rsPath);

        if (mluasvr.inited == false)
        {
            Log("还未初始化,等待初始化后加载:" + _rsPath);
            waitLoadLua = _rsPath;
            return(null);
        }

        if (luaDict.ContainsKey(_rsPath))
        {
            return(luaDict[_rsPath]);
        }

        //设置执行脚本
        //LuaState ls_state = new LuaState();

        //设置脚本启动代理
        LuaState.loaderDelegate = ((string fn) =>
        {
            //获取Lua文件执行目录
            string file_path = Directory.GetCurrentDirectory() + "/Assets/Resources/" + fn;

            file_path = file_path.Replace('/', '\\');
            file_path = file_path.Replace('.', '\\');


            Log("准备加载脚本:" + file_path);

            var file = File.ReadAllBytes(file_path + ".lua");

            if (file == null)
            {
                LogError("加载Lua脚本失败,不存在的Lua脚本");
            }
            else
            {
                Log("加载脚本成功.文件大小:" + file.Length);
            }

            return(file);
        });

        //通过刚才设置的代理方法加载,就会从Res目录下读取带.lua的文件了
        var self = (LuaTable)mluasvr.start(_rsPath);

        if (self != null)
        {
            luaDict.Add(_rsPath, self);
            return(self);
        }

        LogError("脚本初始化错误,脚本:" + _rsPath);

        return(null);
    }
Ejemplo n.º 20
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("custom");
     });
 }
Ejemplo n.º 21
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("MyPackage.Lua");
     });
 }
Ejemplo n.º 22
0
    private void Awake()
    {
        LuaSvr svr = new LuaSvr();

        svr.init(null, () =>
        {
            svr.start("06_RequireImport/06_RequireImport");
        });
    }
Ejemplo n.º 23
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("UseCSharpClass.Lua");
     });
 }
 // Use this for initialization
 void Start()
 {
     luaSvr = new LuaSvr();
     luaSvr.init(null, () =>
     {
         self = (LuaTable)luaSvr.start("main");
         //selfUpdate = (LuaFunction)self["update"];
     });
 }
Ejemplo n.º 25
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("BindCSharp");
     });
 }
Ejemplo n.º 26
0
 void Start()
 {
     luaSvr = new LuaSvr();
     LuaSvr.mainState.loaderDelegate += LuaLoader;
     luaSvr.init(null, () =>
     {
         luaSvr.start("CreatePrefab.Lua");
     });
 }
Ejemplo n.º 27
0
 void Start()
 {
     c = this;
     l = new LuaSvr();
     l.init(null, () =>
     {
         l.start("custom");
     });
 }
Ejemplo n.º 28
0
    void OnComplete()
    {
        l.start("main");

        SceneManager.sceneLoaded += OnSceneLoaded;
        SceneManager.LoadScene("Example");
       

    }
Ejemplo n.º 29
0
 void Start()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         self   = (LuaTable)svr.start("circle/circle");
         update = (LuaFunction)self["update"];
     });
 }
Ejemplo n.º 30
0
    /// <summary>
    /// Inits the S lua.
    /// </summary>
    /// <returns><c>true</c>, if S lua was inited, <c>false</c> otherwise.</returns>
    /// <param name="progress">Progress.</param>
    public static bool              InitSLua(System.Action <int> progress)
    {
        XBytecodeFilePicker.InitPicker();

        luaServer = new LuaSvr();

        platformPath = GetPlatformBytecodeFloder();
        if (!string.IsNullOrEmpty(platformPath))
        {
            LuaSvr.mainState.loaderDelegate = LoadScript;
        }

        Debug.LogFormat("BytecodeFloder : {0}", platformPath);

        luaServer.init(progress, () => {
                        #if !RELEASE
            LuaSvr.mainState["_DEBUG"] = true;
                        #endif

                        #if UNITY_EDITOR
            LuaSvr.mainState["_EDITOR"] = true;
                        #endif

                        #if UNITY_ANDROID
            LuaSvr.mainState["_ANDROID"] = true;
                        #endif

                        #if UNITY_IPHONE
            luaServer.luaState["_IPHONE"] = true;
                        #endif

                        #if _LANGUAGE_CN
            LuaSvr.mainState["_LANGUAGE_CN"] = true;
                        #endif

                        #if _LANGUAGE_EN
            LuaSvr.mainState["_LANGUAGE_EN"] = true;
                        #endif

                        #if _LOCAL_SERVER
            LuaSvr.mainState["_LOCAL_SERVER"] = true;
                        #endif

            var success = luaServer.start("main");
            if (success == null || (bool)success != true)
            {
                Debug.LogError("Lua main intialize failed.");
            }
        }, LuaSvrFlag.LSF_BASIC | LuaSvrFlag.LSF_EXTLIB
                        #if !RELEASE && LUA_DEBUG
                       | LuaSvrFlag.LSF_DEBUG
                        #endif
                       );

        return(true);
    }
Ejemplo n.º 31
0
 void Start()
 {
     svr = new LuaSvr();
     svr.init(null, () =>
     {
         self   = (LuaTable)svr.start("circle/circles");
         update = (LuaFunction)self["update"];
         ud     = update.cast <UpdateDelegate>();
     });
 }