コード例 #1
0
        public async Task <bool> Start()
        {
            if (mInited)
            {
                return(true);
            }
            mConfig = XConfig.GetConfig <LuaConfig>(LuaConst.ConfigPath_Resources);
            if (mConfig == null)
            {
                mStartException = new XException("[TinaX.ILRuntime] Connot found config file.");;
                return(false);
            }
            if (!mConfig.EnableLua)
            {
                return(true);
            }

            mInternal_Lua_Folder_Load_Path = mConfig.FrameworkInternalLuaFolderLoadPath;
            if (!mInternal_Lua_Folder_Load_Path.IsNullOrEmpty())
            {
                if (mInternal_Lua_Folder_Load_Path.EndsWith("/"))
                {
                    mInternal_Lua_Folder_Load_Path = mInternal_Lua_Folder_Load_Path.Substring(0, mInternal_Lua_Folder_Load_Path.Length - 1);
                }
                mInternal_Lua_Folder_Load_Path_withSlash = mInternal_Lua_Folder_Load_Path + "/";
            }
            mLuaExtension = mConfig.LuaFileExtensionName;
            if (!mLuaExtension.StartsWith("."))
            {
                mLuaExtension = "." + mLuaExtension;
            }

            if (!XCore.MainInstance.TryGetBuiltinService(out Assets))
            {
                mStartException = new XException("[TinaX.ILRuntime]" + (IsChinese? "没有任何服务实现了Framework中的内置的资产加载接口": "No service implements the built-in asset loading interface in Framework"));
                return(false);
            }

            mLoader = LoadLuaFiles;
            mLuaVM.AddLoader(mLoader);

            try
            {
                await InitInternalEntry();
            }
            catch (XException e)
            {
                mStartException = e;
                return(false);
            }

            //准备好入口文件
            if (!mConfig.EntryLuaFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await Assets.LoadAsync <TextAsset>(mConfig.EntryLuaFileLoadPath);

                    mEntryFunc = mLuaVM.LoadString <LuaFunction>(entry_ta.bytes, mConfig.EntryLuaFileLoadPath);
                    Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    mStartException = e;
                    return(false);
                }
            }

            if (mUpdateTicket != null)
            {
                mUpdateTicket.Unregister();
            }
            mUpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            await Task.Yield();

            mInited = true;
            return(true);
        }
コード例 #2
0
        public async Task <XException> Start()
        {
            if (m_Inited)
            {
                return(null);
            }
            m_Config = XConfig.GetConfig <TSConfig>(TSConst.ConfigPath_Resources);
            if (m_Config == null)
            {
                return(new XException($"[{TSConst.ServiceName}] Connot found config file."));
            }

            if (!m_Config.Enable)
            {
                return(null);
            }

            //框架内部Js文件加载路径
            m_Internal_Js_Folder_Load_Path = m_Config.FrameworkInternalJsFolderLoadPath;
            if (!m_Internal_Js_Folder_Load_Path.IsNullOrEmpty())
            {
                if (m_Internal_Js_Folder_Load_Path.EndsWith("/"))
                {
                    m_Internal_Js_Folder_Load_Path = m_Internal_Js_Folder_Load_Path.Substring(0, m_Internal_Js_Folder_Load_Path.Length - 1);
                }
                m_Internal_Js_Folder_Load_Path_withSlash = m_Internal_Js_Folder_Load_Path + "/";
            }
            //Js文件加载名称
            m_JsExtension = m_Config.JsFileExtensionName;
            if (!m_JsExtension.StartsWith("."))
            {
                m_JsExtension = "." + m_JsExtension;
            }

            if (m_Assets == null)
            {
                return(new XException($"[{TSConst.ServiceName}]" + (m_Core.IsCmnHans() ? "没有任何服务实现了Framework中的内置的资产加载接口" : "No service implements the built-in asset loading interface in Framework")));
            }

            //初始化Js的运行环境
            m_JsEnv = new JsEnv(new XTSLoader(m_Assets, c_InternalJsSign, c_Internal_Js_Extension, m_Internal_Js_Folder_Load_Path, m_JsExtension));

            //try
            //{
            //    await InitInternalEntry();
            //}
            //catch(XException e)
            //{
            //    return e;
            //}

            //准备好入口文件
            if (!m_Config.EntryJsFileLoadPath.IsNullOrEmpty())
            {
                try
                {
                    TextAsset entry_ta = await m_Assets.LoadAsync <TextAsset>(m_Config.EntryJsFileLoadPath);

                    m_EntryCodeContent = entry_ta.text;
                    //m_EntryFunc = m_JsEnv.LoadString<LuaFunction>(entry_ta.bytes, m_Config.EntryLuaFileLoadPath);
                    m_Assets.Release(entry_ta);
                }
                catch (XException e)
                {
                    return(e);
                }
            }

            if (m_UpdateTicket != null)
            {
                m_UpdateTicket.Unregister();
            }
            m_UpdateTicket = TimeMachine.RegisterUpdate(OnUpdate);

            m_Inited = true;
            return(null);
        }