public 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;
            }

            CsRpcWrap.DisposeCSLuaFunc();
            state.Dispose();
        }
    }
 protected virtual void StartMain()
 {
     luaState.DoFile("Gac/GameMgr.lua");
     GameMgr.Instance.InitLuaCallBackFunc();
     CsRpcWrap.RegisterCSLuaFunc();
     //levelLoaded = luaState.GetFunction("OnLevelWasLoaded");
     CallMain();
 }
Esempio n. 3
0
        public bool OnceDispatch(ref byte[] pData, uint uSize, uint uProcessedSize, ref uint uProcessedOnce)
        {
            int  type         = 0;
            int  msgSize      = 0;
            Type callBackType = null;

            try
            {
                if (uSize < TYPE_SIZE)
                {
                    return(false);
                }

                if (TYPE_SIZE == sizeof(byte))
                {
                    type = pData[uProcessedSize];
                }
                else
                {
                    byte[] pPos = new byte[TYPE_SIZE];
                    Array.Copy(pData, uProcessedSize, pPos, 0, TYPE_SIZE);
                    type = BitConverter.ToInt32(pPos, 0);
                }

                callBackType = HandlerRcvType[type];
                msgSize      = Marshal.SizeOf(callBackType);

                if (uSize < msgSize)
                {
                    return(false);
                }

                uProcessedOnce += TYPE_SIZE;
            }
            catch (System.Exception ex)
            {
                Debug.LogErrorFormat("OnceDispatch_Error uSize:{0},uProcessedSize:{1},uProcessedOnce:{2},type:{3},msgSize:{4},TYPE_SIZE:{5},RpcLen:{6},ex:{7}", uSize, uProcessedSize, uProcessedOnce, type, msgSize, TYPE_SIZE, HandlerRcvType.Length, ex.ToString());
            }

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            string sMark = string.Format("CallLuaCsRpc {0}", callBackType != null ? callBackType.Name : type.ToString());
            Profile.BenchmarkBegin(sMark);
#endif
            bool bOk = CsRpcWrap.Call_Bytes2Handler_To_Lua(type, ref pData, (uint)(uProcessedSize + uProcessedOnce), ref uProcessedOnce);

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            Debug.AssertFormat(bOk, "CsRpcWrap.Call_Bytes2Handler_To_Lua Error type:{0}:", type);
            Profile.BenchmarkEnd(sMark);
#endif

            return(true);
        }