Inheritance: MonoBehaviour
Exemplo n.º 1
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]);
     }
 }
 private void Load()
 {
     LoadClassNames();
     luaState_ = LuaClient.GetMainState();
     if (luaState_ == null)
     {
         throw new InvalidProgramException("not found MainState");
     }
 }
Exemplo n.º 3
0
 public static void PayByLua(string funcName)
 {
     if (mSdkImpl != null)
     {
         mSdkImpl.payCallback      = null;
         mSdkImpl.payCallbackByLua = LuaClient.GetMainState().GetFunction(funcName);
         mSdkImpl.Pay();
     }
 }
Exemplo n.º 4
0
    protected void Awake()
    {
        Instance = this;
        Init();

#if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded += OnSceneLoaded;
#endif
    }
Exemplo n.º 5
0
 void Start()
 {
     instance = this;
     //luastate = new LuaState();
     DontDestroyOnLoad(this.gameObject);
     //需要将LuaClient中的protected LuaState luaState = null;改为public,
     //同时可以在LuaClient中再封装一个调用Lua模块函数的方法。
     luaClient = this.gameObject.AddComponent <LuaClient>();
 }
Exemplo n.º 6
0
 public static void LogoutByLua(string funcName)
 {
     if (mSdkImpl != null)
     {
         mSdkImpl.logoutCallback      = null;
         mSdkImpl.logoutCallbackByLua = LuaClient.GetMainState().GetFunction(funcName);
         mSdkImpl.Logout();
     }
 }
Exemplo n.º 7
0
 protected void Awake()
 {
     luaState = LuaClient.GetMainState();
     InitLuaSetting();
     if (isFinishLuaInit)
     {
         uiList.AddLast(this);
     }
 }
Exemplo n.º 8
0
    protected void Awake()
    {
        Debug.Log("Init Lua Client " + name);
        Instance = this;
        Init();
#if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded += OnSceneLoaded;
#endif
    }
Exemplo n.º 9
0
    /// <summary>
    /// 执行Lua方法
    /// </summary>
    /// <returns></returns>
    public static object[] CallLuaMethod(string module, string func, params object[] args)
    {
        LuaClient luaClient = GameManager.Instance.GetLuaClient();

        if (null == luaClient)
        {
            return(null);
        }
        return(luaClient.CallFunction(module + "." + func, args));
    }
Exemplo n.º 10
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.º 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
        /// <summary>
        /// 游戏模块开始运行入口
        /// </summary>
        public void GameStart()
        {
            audioManager.Init();
            timerManager.Init();
            netMessageCenter.Init();

            //将lua初始化移动到这里,所有的必要条件都准备好以后再初始化lua虚拟机
            luaClient = gameLauncherObj.AddComponent <LuaClient>();

            init = true;
        }
Exemplo n.º 14
0
    void RemoveUpdate()
    {
        LuaClient inst = LuaClient.Instance;

        if (inst)
        {
            LuaLooper loop = inst.GetLooper();
            loop.UpdateEvent.Remove(update, self);
            loop.LateUpdateEvent.Remove(lateUpdate, self);
            loop.FixedUpdateEvent.Remove(fixedUpdate, self);
        }
    }
Exemplo n.º 15
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.º 16
0
    void InitClient()
    {
        UIAPI.Init();
        GameAPI.Init();

        Instance = this;
        Init();

                #if UNITY_5_4
        SceneManager.sceneLoaded += OnSceneLoaded;
                #endif
    }
Exemplo n.º 17
0
    void RemoveUpdateEvent()
    {
        LuaClient client = LuaClient.Instance;

        if (LuaClient.Instance)
        {
            LuaLooper loop = client.GetLooper();
            loop.UpdateEvent.Remove(update, _luaTable);
            loop.LateUpdateEvent.Remove(lateUpdate, _luaTable);
            loop.FixedUpdateEvent.Remove(fixedUpdate, _luaTable);
        }
    }
Exemplo n.º 18
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.º 19
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.º 20
0
    public override void Init()
    {
        if (luaObject == null)
        {
            luaObject = new GameObject("LuaClientObject");
            luaClient = luaObject.AddComponent <LuaClient>();
            GameObject.DontDestroyOnLoad(luaObject);
            dicObjScript = new Dictionary <GameObject, CScriptObject>();
            luaClient.Init();
        }

        instance = this;
    }
Exemplo n.º 21
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.º 22
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.º 23
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.º 24
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.º 25
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.º 26
0
    public void StartUp()
    {
        Instance = this;
        if (!Settings.kIsRunFromLua)
        {
            StartMain();
            return;
        }

        Init();

#if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded += OnSceneLoaded;
#endif
    }
Exemplo n.º 27
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.º 28
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.º 29
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.º 30
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.º 31
0
    public virtual void Destroy()
    {
        if (luaState != null)
        {
        #if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded -= OnSceneLoaded;
        #endif
            LuaState state = luaState;
            luaState = null;

            if (levelLoaded != null)
            {
                levelLoaded.Dispose();
                levelLoaded = null;
            }

            if (loop != null)
            {
                loop.Destroy();
                loop = null;
            }

            state.Dispose();
            Instance = null;
        }
    }
Exemplo n.º 32
0
    protected void Awake()
    {
        Instance = this;
        Init();

        #if UNITY_5_4_OR_NEWER
        SceneManager.sceneLoaded += OnSceneLoaded;
        #endif
    }
Exemplo n.º 33
0
    protected void Destroy()
    {
        if (luaState != null)
        {
            if (levelLoaded != null)
            {
                levelLoaded.Dispose();
                levelLoaded = null;
            }

            loop.Destroy();
            luaState.Dispose();
            loop = null;
            luaState = null;
            Instance = null;
        }
    }
Exemplo n.º 34
0
 protected void Awake()
 {
     Instance = this;
     Init();
 }