GetMainState() public static method

public static GetMainState ( ) : LuaState
return LuaState
Exemplo n.º 1
0
        void Update()
        {
            //cmd.Update();

            for (int i = 0; i < _orderedUpdateableList.Count; ++i)
            {
                _orderedUpdateableList[i].Update();
            }

            Messenger.Update();             // msg process
            GlobalTimer.Instance.Update();  // timer process
            UpdateEvent();

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (hasLoadLua)
                {
                    LuaFunction func = LuaClient.GetMainState().GetFunction("exit_ui.Show");
                    func.BeginPCall();
                    func.PCall();
                    func.EndPCall();
                    func = null;
                }
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// 发送消息到lua函数(string类型不适用)
    public void dispatchCmd(string cmdID, System.Object para1 = null, System.Object para2 = null, System.Object para3 = null, System.Object para4 = null)
    {
#if UNITY_PROFILER
        Profiler.BeginSample("LuaNotifier.dispatchCmd()");
#endif
        if (m_dispatchCmd == null && LuaClient.Instance != null && LuaClient.GetMainState() != null)
        {
            m_dispatchCmd = LuaClient.GetMainState().GetFunction("Notifier.dispatchCmdForCSharp");
        }

        if (m_dispatchCmd != null)
        {
            m_dispatchCmd.BeginPCall();
            m_dispatchCmd.Push(cmdID);
            m_dispatchCmd.Push(para1);
            m_dispatchCmd.Push(para2);
            m_dispatchCmd.Push(para3);
            m_dispatchCmd.Push(para4);
            m_dispatchCmd.PCall();
            m_dispatchCmd.EndPCall();
        }
#if UNITY_PROFILER
        Profiler.EndSample();
#endif
    }
 private static void __initialize_once()
 {
     if (__bind_script_func == null)
     {
         if (LuaClient.Instance == null)
         {
             var lua_state_go = new GameObject("__G__LuaState__");
             DontDestroyOnLoad(lua_state_go);
             lua_state_go.AddComponent <LuaClient>();
         }
         L = LuaClient.GetMainState();
         L.LuaDoString(__bind_script_function_def);                 // binder
         __bind_script_func          = L.GetFunction(L.ToLuaRef()); //
         __lua_behaviour_bind_fields = new List <FieldInfo>();
         var all_fields = typeof(LuaBehaviour).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
         foreach (var field in all_fields)
         {
             if (!field.Name.StartsWith("__lb_"))
             {
                 continue;
             }
             __lua_behaviour_bind_fields.Add(field);
         }
         __g_update_beat       = L.GetTable("UpdateBeat");
         __g_fixed_update_beat = L.GetTable("FixedUpdateBeat");
     }
 }
Exemplo n.º 4
0
 public void Initialize()
 {
     if (LuaClient.GetMainState() != null)
     {
         m_dispatchCmd = LuaClient.GetMainState().GetFunction("Notifier.dispatchCmdForCSharp");
     }
 }
Exemplo n.º 5
0
        public void SetLuaTable(LuaTable tb)
        {
            mLuaState = LuaClient.GetMainState();
            if (mLuaState == null)
            {
                return;
            }

            if (tb == null)
            {
                mLuaTable = mLuaState.GetTable("NetworkManager");
            }
            else
            {
                mLuaTable = tb;
            }

            if (mLuaTable != null)
            {
                mLuaOnSocketDataFunc = mLuaTable.GetLuaFunction("on_socket_data") as LuaFunction;
            }
            else
            {
                Debug.LogWarning("NetworkManager is null:");
            }
        }
Exemplo n.º 6
0
 private void InitEditorActor()
 {
     _setActor = LuaClient.GetMainState().GetFunction("SetActor");
     ResetActorGo();
     for (int i = 0; i < _actorTypes.Count; i++)
     {
         SetActor(_actorTypes[i], _actorNames[i], _actorGos[i]);
     }
 }
Exemplo n.º 7
0
 private void Load()
 {
     LoadClassNames();
     luaState_ = LuaClient.GetMainState();
     if (luaState_ == null)
     {
         throw new InvalidProgramException("not found MainState");
     }
 }
Exemplo n.º 8
0
 protected void Awake()
 {
     luaState = LuaClient.GetMainState();
     InitLuaSetting();
     if (isFinishLuaInit)
     {
         uiList.AddLast(this);
     }
 }
Exemplo n.º 9
0
 public static void LogoutByLua(string funcName)
 {
     if (mSdkImpl != null)
     {
         mSdkImpl.logoutCallback      = null;
         mSdkImpl.logoutCallbackByLua = LuaClient.GetMainState().GetFunction(funcName);
         mSdkImpl.Logout();
     }
 }
Exemplo n.º 10
0
 public static void PayByLua(string funcName)
 {
     if (mSdkImpl != null)
     {
         mSdkImpl.payCallback      = null;
         mSdkImpl.payCallbackByLua = LuaClient.GetMainState().GetFunction(funcName);
         mSdkImpl.Pay();
     }
 }
Exemplo n.º 11
0
        void Awake()
        {
            if (LuaClient.Instance == null)
            {
                gameObject.AddComponent <LuaClient> ();
            }
            _luaState = LuaClient.GetMainState();
            GameObject.DontDestroyOnLoad(gameObject);

            _luaState.Call("RunGame", false);
        }
Exemplo n.º 12
0
        protected void Awake()
        {
            LuaTable table = LuaClient.GetMainState().GetTable(name);

            if (table == null)
            {
                throw new LuaException(string.Format("Lua table {0} not exists", name));
            }

            Util.CallMethod(name, "Awake", gameObject, this);
        }
Exemplo n.º 13
0
    public static void SwitchAccountByLua(string funcName)
    {
        //处理我们自己的切换帐号操作
        LuaFunction lf = LuaClient.GetMainState().GetFunction(funcName);

        if (lf != null)
        {
            LoginRetInfo retInfo = new LoginRetInfo();
            Utility_LuaHelper.CallParaLuaFunc(lf, retInfo.Uid, retInfo.Token, retInfo.PlatType, retInfo.Passwd, true);
        }
    }
Exemplo n.º 14
0
    void InitLuaEnv()
    {
        LuaClient lc = gameObject.GetComponent <LuaClient>();

        if (lc == null)
        {
            lc = gameObject.AddComponent <LuaClient>();
        }

        LuaClient.GetMainState()["__UNITY_EDITOR__"] = true;
        LuaClient.GetMainState().DoFile("editor/EditorAdapter.lua");
    }
Exemplo n.º 15
0
        /// <summary>
        /// 清理内存
        /// </summary>
        public static void ClearMemory()
        {
            GC.Collect(); Resources.UnloadUnusedAssets();

            if (LuaClient.Instance == null)
            {
                return;
            }
            LuaState lua = LuaClient.GetMainState();

            lua.LuaGC(LuaGCOptions.LUA_GCCOLLECT);
        }
Exemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad(this.gameObject);
     _luaState   = LuaClient.GetMainState();
     _luaRoleMgr = _luaState.GetTable("RoleMgr");
     _luaState.translator.LogGC = true;
     if (_luaRoleMgr == null)
     {
         Debugger.LogError("找不到RoleMgr");
         return;
     }
     CreateGameObject();
 }
Exemplo n.º 17
0
    void CheckNetState(NetworkReachability netState)
    {
        //Debug.Log("NetworkReachability-------------------------------");
        LuaFunction func = LuaClient.GetMainState().GetFunction("network_mgr.NetworkReachability");

        if (func != null)
        {
            func.BeginPCall();
            func.Push((int)netState);
            func.PCall();
            func.EndPCall();
            func = null;
        }
    }
Exemplo n.º 18
0
        void BeginAction()
        {
            _isFinish = false;
            _isStart  = true;
            List <object> argValue = new List <object>();

            Debug.Assert(_autoValueInputArgNames.Count == _autoValueInputArgValues.Count);
            for (int i = 0; i < _autoValueInputArgNames.Count; i++)
            {
                string argName = _autoValueInputArgNames[i];
                Port   p       = GetInputPort(argName);
                if (p is ValueInput)
                {
                    ValueInput valueInput = (ValueInput)p;
                    if (!valueInput.isDefaultValue)
                    {
                        argValue.Add(valueInput.value);
                    }
                    else
                    {
                        argValue.Add(_autoValueInputArgValues[i]);
                    }
                }
            }

            string targets = "";

            if (!_targetValueIn.isDefaultValue)
            {
                targets = _targetValueIn.value;
            }
            else
            {
                targets = _targetsArgValues;
            }

            LuaState    state         = LuaClient.GetMainState();
            LuaFunction addActionFunc = state.GetFunction("SMAddAction");

            object[] args = argValue.ToArray();
            addActionFunc.BeginPCall();
            addActionFunc.Push(_actionKey);
            addActionFunc.Push(_luaFileName);
            addActionFunc.Push(targets);
            addActionFunc.Push(args);
            addActionFunc.PCall();
            addActionFunc.EndPCall();
            addActionFunc.Dispose();
        }
Exemplo n.º 19
0
        /// <summary>
        /// 执行Lua方法
        /// </summary>
        public static object[] CallMethod(string module, string func, params object[] args)
        {
            if (LuaClient.Instance == null)
            {
                return(null);
            }
            LuaState    lua     = LuaClient.GetMainState();
            LuaFunction luaFunc = lua.GetFunction(module + "." + func);

            if (luaFunc != null)
            {
                return(luaFunc.LazyCall(args));
            }
            return(null);
        }
Exemplo n.º 20
0
        bool UpdateAction()
        {
            LuaState    state            = LuaClient.GetMainState();
            LuaFunction updateActionFunc = state.GetFunction("SMUpdateAction");

            updateActionFunc.BeginPCall();
            updateActionFunc.Push(_actionKey);
            updateActionFunc.Push(Time.deltaTime);
            updateActionFunc.PCall();
            bool isFinish = updateActionFunc.CheckBoolean();

            updateActionFunc.EndPCall();
            updateActionFunc.Dispose();
            return(isFinish);
        }
Exemplo n.º 21
0
        void EndAction()
        {
            Debug.Log("**** C# EndAction");
            _isFinish = true;
            _isStart  = false;
            LuaState    state         = LuaClient.GetMainState();
            LuaFunction delActionFunc = state.GetFunction("SMDelAction");

            delActionFunc.BeginPCall();
            delActionFunc.Push(_actionKey);
            delActionFunc.PCall();
            delActionFunc.EndPCall();
            delActionFunc.Dispose();
            CallFlowOutputs();
        }
Exemplo n.º 22
0
    public void CallFunc(string file, string func, MonoBehaviour obj)
    {
        luaState = LuaClient.GetMainState();
        luaState.DoFile(file);

        try
        {
            luaState.Call(func, obj);
        }
        catch (System.Exception e)
        {
            // Awake中必须这样特殊处理异常
            luaState.ThrowLuaException(e);
        }
    }
Exemplo n.º 23
0
    /// <summary>
    /// Initializes a new instance of the <see cref="UniWebViewMessage"/> struct.
    /// </summary>
    /// <param name="rawMessage">Raw message which will be parsed to a UniWebViewMessage.</param>
    public UniWebViewMessage(string rawMessage) : this()
    {
        this.rawMessage = rawMessage;
        string[] schemeSplit = rawMessage.Split(new string[] { "://" }, System.StringSplitOptions.None);
        if (schemeSplit.Length >= 2)
        {
            this.scheme = schemeSplit[0];
            string pathAndArgsString = "";
            int    index             = 1;
            while (index < schemeSplit.Length)
            {
                pathAndArgsString = string.Concat(pathAndArgsString, schemeSplit[index]);
                index++;
            }

            string[] split = pathAndArgsString.Split("?"[0]);

            this.path = split[0].TrimEnd('/');
            this.args = new Dictionary <string, string>();
            if (split.Length > 1)
            {
                foreach (string pair in split[1].Split("&"[0]))
                {
                    string[] elems = pair.Split("="[0]);
                    if (elems.Length > 1)
                    {
                        args[elems[0]] = WWW.UnEscapeURL(elems[1]);
                    }
                }
            }

            LuaInterface.LuaState luastate = LuaClient.GetMainState();
            table               = luastate.GetTable(2);
            table["scheme"]     = this.scheme;
            table["path"]       = this.path;
            table["rawMessage"] = this.rawMessage;
            foreach (KeyValuePair <string, string> kvp in args)
            {
                //Debug.Log(kvp.Key);
                //Debug.Log(kvp.Value);
                table[kvp.Key] = kvp.Value;
            }
        }
        else
        {
            Debug.LogError("Bad url scheme. Can not be parsed to UniWebViewMessage: " + rawMessage);
        }
    }
Exemplo n.º 24
0
        public AbstractParams Invoke(AbstractParams ScriptParms)
        {
#if TOLUA
            if (LuaClient.Instance == null)
            {
                LogMgr.Log("未使用lua,但是程序集中包含了带有lua目标的函数的注册");
                return(null);
            }

            TryInit(this.attribute);

            if (this.luafunc == null)
            {
                this.luafunc = LuaClient.GetMainState().GetFunction(luafilepath.Split('.')[0] + "." + this.methodname);
                if (this.luafunc == null)
                {
                    //try get function from global
                    this.luafunc = LuaClient.GetMainState().GetFunction(this.methodname);
                }
            }

            if (this.luafunc != null)
            {
                int oldTop = this.luafunc.BeginPCall();
                //retry
                if (Luatable == null)
                {
                    this.Luatable = TryGetClassLuaFunction(this.luafilepath);
                }

                if (Luatable != null)
                {
                    this.luafunc.Push(Luatable);
                }

                this._LuaScriptParmsCall(ScriptParms);
                this.luafunc.PCall();
                AbstractParams retparams = this._LuaRetCall(oldTop);

                this.luafunc.EndPCall();
                return(retparams);
            }
#else
            LogMgr.LogError("Lua Client Missing Cant Invoke Lua Function");
#endif

            return(null);
        }
Exemplo n.º 25
0
    LuaFunction FindLuaFunction(string funName)
    {
        LuaFunction luaFun = null;

        if (!cachedLuaFunction.ContainsKey(funName))
        {
            luaFun = LuaClient.GetMainState().GetFunction(funName);
            cachedLuaFunction[funName] = luaFun;
        }
        else
        {
            luaFun = cachedLuaFunction[funName];
        }

        return(luaFun);
    }
Exemplo n.º 26
0
        void TryInit(Script_LuaLogicAttribute att)
        {
#if TOLUA
            if (inited)
            {
                return;
            }

            if (att != null)
            {
                this.luafilepath = att.luapath;
                this.methodname  = att.methodName;
                this.Luatable    = TryGetClassLuaFunction(att.luapath);
                if (this.Luatable == null)
                {
                    object[] retObj = LuaClient.GetMainState().DoFile(att.luapath.ToLower());

                    if (retObj != null && retObj.Length > 0)
                    {
                        LuaTable table = retObj[0] as LuaTable;
                        if (table != null)
                        {
                            classFuncDictionary[att.luapath] = new WeakReference(table);
                            this.Luatable = table;
                            this.luafunc  = table[methodname] as LuaFunction;
                        }
                        else
                        {
                            LogMgr.LogErrorFormat("类型不匹配 :{0}", retObj[0]);
                        }
                    }
                    else
                    {
                        this.luafunc = LuaClient.GetMainState().GetFunction(methodname);
                    }
                }
                else
                {
                    this.luafunc = this.Luatable.GetLuaFunction(att.methodName);
                }
            }

            inited = true;
#endif
        }
Exemplo n.º 27
0
    // Start is called before the first frame update
    void Start()
    {
        gameObject.AddComponent <LuaClient>();
        luaState = LuaClient.GetMainState();

        luaState.DoFile("GameMode.lua");
        luaState.DoFile("PlayerController.lua");
        //luaState.DoFile("BlockConfig.lua");
        luaState.DoFile("BlockController.lua");
        luaState.DoFile("BlockRenderer.lua");
        luaState.DoFile("HUD.lua");

        CallFunc("GameMode.Start");
        CallFunc("PlayerController.Start");
        CallFunc("BlockController.Start");
        CallFunc("BlockRenderer.Start");
        CallFunc("HUD.Start");
    }
Exemplo n.º 28
0
    protected override bool ExeOnTarget(BaseEntity tar)
    {
        var state = LuaClient.GetMainState();

        state.DoFile(scriptFile);
        var func     = state.GetFunction(function);
        var params1  = state.GetTable(function + "_Params");
        var iterator = extraParamters.GetEnumerator();

        while (iterator.MoveNext())
        {
            params1[iterator.Current.Key] = iterator.Current.Value;
        }
        func.BeginPCall();
        func.Push(params1);
        func.PCall();
        func.EndPCall();
        return(true);
    }
    public override void Start()
    {
        LuaFunction func = LuaClient.GetMainState()
                           .GetFunction("show_chapter_info_mgr.OnLevelLoading");

        func.BeginPCall();
        func.Push(SceneMgr.Instance.SceneId);
        func.PCall();
        _duration = (float)func.CheckNumber();
        func.EndPCall();
        func.Dispose();

        if (_duration > 0)
        {
            _coroutine = GameKernel.Instance.StartCoroutine(WaitFinish());
        }
        else
        {
            Complete();
        }
    }
Exemplo n.º 30
0
 private void OnApplicationPause(bool isPause)
 {
     if (isPause)
     {
         LuaFunction func = LuaClient.GetMainState().GetFunction("network_mgr.AppPauseNotify");
         func.BeginPCall();
         func.Push(1);
         func.PCall();
         func.EndPCall();
         func = null;
     }
     else
     {
         LuaFunction func = LuaClient.GetMainState().GetFunction("network_mgr.AppPauseNotify");
         func.BeginPCall();
         func.Push(0);
         func.PCall();
         func.EndPCall();
         func = null;
     }
 }