public IEnumerator Initialize(string projectName, MainLoader _loader, string luaScriptBundlePath, string luaScriptsRootPath) { LuaEnv = new LuaEnv(); LuaScripts = new Dictionary <string, TextAsset>(); var operation = _loader.GetLoadBundleOperation(luaScriptBundlePath); yield return(operation); var assets = operation.GetAllAssets <TextAsset>(); foreach (var luaAssets in assets) { var firstIndex = luaAssets.Key.LastIndexOf(luaScriptsRootPath.ToLower()) + luaScriptsRootPath.Length; var luaPath = luaAssets.Key.Substring(firstIndex + 1, luaAssets.Key.Length - firstIndex - 1 - 8); Debug.AssertFormat(!LuaScripts.ContainsKey(luaPath), "lua script file name [{0}] is duplicated", luaPath); LuaScripts.Add(luaPath, luaAssets.Value); } LuaEnv.AddLoader( (ref string filepath) => { var filePath = filepath.ToLower(); Debug.AssertFormat(LuaScripts.ContainsKey(filePath), "lua script [{0}] not exist", filePath); return(LuaScripts[filePath].bytes); }); LuaFunction mainLuaFunction = LuaEnv.DoString(LuaScripts["main"].bytes)[0] as LuaFunction; mainLuaFunction.Call(projectName); }
// Cross-initialize. void Start() { // If this hasn't run yet. if (instance == null) { instance = this; // Load the main (required) scene if it is not loaded. if (!GameStateLoader.IsLoaded("main")) { GameStateLoader.LoadSceneAsync("main"); } // Else if it is loaded and it's the only scene loaded. else if (SceneManager.sceneCount == 1) { // Load the title scene. GameStateLoader.LoadSceneAsync("title"); } } else { // Destroy this game object. Destroy(gameObject); } }
public LoadLevelOperation(MainLoader loader, string assetbundlePath, string levelName, bool isAdditive) { _loader = loader; _levelName = levelName; _isAddtive = isAdditive; _assetbundlePath = assetbundlePath; IsDone = false; }
private void Awake() { _updater = gameObject.AddComponent <MainUpdater>(); _loader = gameObject.AddComponent <MainLoader>(); _luaLoader = gameObject.AddComponent <LuaLoader>(); _luaHelper = gameObject.AddComponent <LuaHelper>(); DontDestroyOnLoad(gameObject); }
void Start() { BuildMainLoadUI(); m_loader = new MainLoader(); m_loader.OnProgress = OnLoadProgress; m_loader.OnComplete = LoadEnded; new CoroutineTask(m_loader.Load()); // TaskManager execute }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); return; } _instance = this; DontDestroyOnLoad(this.gameObject); }
public static void CheckCondition(string strRes) { if (string.IsNullOrEmpty(strRes)) { Debug.LogError("error:resource is empty"); return; } MainLoader.AddDownloadDone(strRes); List <Condition> check = null; lock (RegisterCondition) { check = RegisterCondition; RegisterCondition = new List <Condition>(); } //another thread call may be invalid so must push it into loader.list to check in update if (check != null) { MainLoader.AddCheck(check); } }
void Start() { Ins = this; GameData.LoadState(); //Log.LogInfo("load start"); if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor) { strPlatform = Application.platform.ToString(); } strResource = Application.persistentDataPath + "/Resource"; strUpdatePath = Application.persistentDataPath + "/Update"; strUpdateConfig = Application.persistentDataPath + "/" + "config.xml"; //can not use Application.streamingAssetsPath in other thread so save it GameObject.DontDestroyOnLoad(this); CreateConfig(); //检查表是否需要全部资源替换. //if (CheckTableCompleted()) // TableUpdate(); Global.ShowLoadingStart(); state = LoadStep.ChcekNeedUpdate; StartCoroutine(RestoreUpdate()); }
public LoadBundleOperation(MainLoader loader, string assetbundleName) { _loader = loader; _assetbundleName = assetbundleName; #if UNITY_EDITOR if (MainLoader.IsSimulationMode) { IsDone = true; } else #endif { if (!_loader.LoadedBundles.ContainsKey(assetbundleName)) { IsDone = false; var dependencies = _loader.Manifest.GetAllDependencies(_assetbundleName); foreach (var dependency in dependencies) { LoadedBundle loadedBundle; if (_loader.LoadedBundles.TryGetValue(dependency, out loadedBundle)) { loadedBundle.ReferecedCount++; } else { _pendingDependencies.Enqueue(dependency); } } } else { IsDone = true; } } }
IEnumerator DownloadNecessaryData() { //check data is ok //if (strServerVer == null || GameData.Version().CompareTo(strServerVer) != -1) // yield break; //check last download is interrupt if (MainLoader.config != null && MainLoader.config.mlst.Count != 0) { string strTargetV = MainLoader.config.strTargetVer; //target ver == server ver restore from last state if (strTargetV == strServerVer) { foreach (var item in MainLoader.config.mlst) { if (!string.IsNullOrEmpty(item.strLoadbytes) && item.strTotalbytes == item.strLoadbytes && item.strTotalbytes != "0") { if (item.bHashChecked) { continue; } } if (!string.IsNullOrEmpty(item.strFile) && item.bForceUpdate) { UpdateClient.AddRequest(item.strFile, strUpdatePath + "/" + item.strFile, new HttpClient.cb(UpdateTableProgress), System.Convert.ToInt64(item.strLoadbytes), item); } } AllCount = HttpClient.RequestMap.Count; if (AllCount != 0) { MainLoader.ChangeStep(LoadStep.NeedUpdate); errorCount = 0; DownloadCount = 0; HttpClient.StartDownload(); } else { MainLoader.ChangeStep(LoadStep.NotNeedUpdate); } yield break; } } //download 0.0.0.0-0.0.0.1.xml string strUrl = string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strUpdateFile); string strLocalFile = strUpdatePath + "/" + strUpdateFile; using (WWW updateXml = new WWW(strUrl)) { yield return(updateXml); File.WriteAllBytes(strLocalFile, updateXml.bytes); DeCompressFile(strLocalFile, strUpdatePath + "/" + "update.xml"); XmlDocument xmlVer = new XmlDocument(); xmlVer.Load(strUpdatePath + "/" + "update.xml"); XmlElement updateFilelst = xmlVer.DocumentElement; if (updateFilelst != null) { string strFileNum = updateFilelst.GetAttribute("Filenum"); List <UpdateFile> data = new List <UpdateFile>(); foreach (XmlElement each in updateFilelst) { string strFileName = each.GetAttribute("name"); string strMD5 = each.GetAttribute("MD5"); bool bFind = false; UpdateFile res = null; foreach (var item in MainLoader.config.mlst) { if (item.strFile == strFileName) { bFind = true; break; } } if (bFind && res != null) { res.strMd5 = strMD5; res.bHashChecked = false; res.strLoadbytes = "0"; res.strTotalbytes = "0"; //下载的必要数据包括在Resources目录内的文件,以及以.zip结束的文件(表格或者数据或脚本) string[] strResourceDirectory = strFileName.Split('/'); bool bForce = false; foreach (var eachDir in strResourceDirectory) { if (eachDir == "Resources") { bForce = true; break; } } if (strFileName.EndsWith(".zip")) { bForce = true; } res.bForceUpdate = bForce; data.Add(res); } else { string[] strResourceDirectory = strFileName.Split('/'); bool bForce = false; foreach (var eachDir in strResourceDirectory) { if (eachDir == "Resources") { bForce = true; break; } } if (strFileName.EndsWith(".zip")) { bForce = true; } UpdateFile file = new UpdateFile(strFileName, strMD5, "0", "0", bForce); data.Add(file); } } MainLoader.config.mlst = data; MainLoader.config.strTargetVer = strServerVer; foreach (var item in MainLoader.config.mlst) { if (!UpdateConfig.keySearch.ContainsKey(item.strFile)) { UpdateConfig.keySearch.Add(item.strFile, item); } if (item.strLoadbytes != "0" && item.strLoadbytes == item.strTotalbytes) { continue; } if (item.bForceUpdate) { UpdateClient.AddRequest(item.strFile, strUpdatePath + "/" + item.strFile, new HttpClient.cb(UpdateTableProgress), Convert.ToInt64(item.strLoadbytes), item); } } AllCount = HttpClient.RequestMap.Count; if (AllCount != 0) { int nUnNecessCount = Convert.ToInt32(strFileNum) - AllCount; MainLoader.ChangeStep(LoadStep.NeedUpdate); errorCount = 0; DownloadCount = 0; HttpClient.StartDownload(); } else { MainLoader.ChangeStep(LoadStep.NotNeedUpdate); } } } }
IEnumerator RestoreUpdate() { if (Application.internetReachability == NetworkReachability.NotReachable) { Log.LogInfo("connect time out"); MainLoader.ChangeStep(LoadStep.NotNeedUpdate); yield break; } else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) { //3G Tip } //Restore DownLoad From Progress.xml System.Net.Sockets.Socket sClient = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.IP); System.Net.EndPoint server = new System.Net.IPEndPoint(Dns.GetHostAddresses(GameData.Domain)[0], System.Convert.ToInt32(strPort)); System.Threading.ManualResetEvent connectDone = new System.Threading.ManualResetEvent(false); try { connectDone.Reset(); sClient.BeginConnect(server, delegate(IAsyncResult ar) { try { System.Net.Sockets.Socket client = (System.Net.Sockets.Socket)ar.AsyncState; client.EndConnect(ar); } catch (System.Exception e) { Log.LogInfo(e.Message + "|" + e.StackTrace); } finally { connectDone.Set(); } } , sClient); //timeout if (!connectDone.WaitOne(2000)) { Log.LogInfo("connect time out"); MainLoader.ChangeStep(LoadStep.CannotConnect); yield break; } else { if (!sClient.Connected) { Log.LogInfo("connect disabled by server"); MainLoader.ChangeStep(LoadStep.CannotConnect); yield break; } } } catch { sClient.Close(); MainLoader.ChangeStep(LoadStep.CannotConnect); yield break; } finally { connectDone.Close(); } //Log.LogInfo("download:" + string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strVFileName)); using (WWW vFile = new WWW(string.Format(strVFile, strHost, strPort, strProjectUrl, strPlatform, strVFileName))) { //Log.LogInfo("error:" + vFile.error); yield return(vFile); if (vFile.error != null && vFile.error.Length != 0) { //Log.LogInfo("error " + vFile.error); vFile.Dispose(); //not have new version file //can continue game MainLoader.ChangeStep(LoadStep.NotNeedUpdate); yield break; } if (vFile.bytes != null && vFile.bytes.Length != 0) { File.WriteAllBytes(strUpdatePath + "/" + "v.zip", vFile.bytes); DeCompressFile(strUpdatePath + "/" + "v.zip", strUpdatePath + "/" + "v.xml"); vFile.Dispose(); } else { MainLoader.ChangeStep(LoadStep.NotNeedUpdate); yield break; } } XmlDocument xmlVer = new XmlDocument(); xmlVer.Load(strUpdatePath + "/" + "v.xml"); XmlElement ServerVer = xmlVer.DocumentElement; if (ServerVer != null) { string strServer = ServerVer.GetAttribute("ServerV"); UpdateClient = HttpManager.AllocClient(string.Format(strDirectoryBase, strHost, strPort, strProjectUrl, strPlatform, strServer, "")); //if (strServer != null && GameData.Version().CompareTo(strServer) == -1) //{ // strServerVer = strServer; // foreach (XmlElement item in ServerVer) // { // string strClientV = item.GetAttribute("ClientV"); // if (strClientV == GameData.Version()) // { // strUpdateFile = item.GetAttribute("File"); // break; // } // } // if (strUpdateFile != null && strUpdateFile.Length != 0) // StartCoroutine("DownloadNecessaryData"); //} //else //{ // Log.LogInfo("not need update"); // MainLoader.ChangeStep(LoadStep.NotNeedUpdate); //} } }
//void OnApplicationQuit() //{ //主线程阻塞到下载线程结束. //HttpManager.Quit(); //释放日志占用 //Log.Uninit(); //保存下载进度 //SaveConfig(true); //} private void Awake() { Ins = this; }
public void Initialize(MainLoader loader, MainUpdater updater) { _loader = loader; _updater = updater; }
public LoadAssetOperation(MainLoader loader, MainUpdater updater, string assetPath) { _loader = loader; _updater = updater; _assetPath = assetPath; }
public void MineMonitors(EventLog log) { var configuredClients = ConfigurationManager.AppSettings as NameValueCollection; if (configuredClients == null) { log.WriteEntry("Unable to load the configuration file.", EventLogEntryType.Warning, 13, 1); return; } if (configuredClients.Count == 0) { log.WriteEntry("No keys detected in configuration file.", EventLogEntryType.Warning, 14, 1); return; } //PgDbCollector.CleanFactDocument(); foreach (var key in configuredClients.AllKeys) { string configuredClient = configuredClients.GetValues(key).FirstOrDefault(); if ("libDir".Equals(key.ToString())) { continue; } EnterpriseSection clientConfig = (EnterpriseSection)System.Configuration.ConfigurationManager.GetSection("Empresas/" + configuredClient); if (clientConfig == null) { log.WriteEntry("Client configuration not found for Empresas/" + configuredClient + ".", EventLogEntryType.Warning, 15, 1); continue; } Empresa empresa = PgDbCollector.GetCompanyByName(clientConfig.NombreEmpresa); log.WriteEntry("Client configuration found in database: " + clientConfig.NombreEmpresa + "; " + empresa.Ruta); NpgsqlConnection conn = new NpgsqlConnection(); string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.JASPER].ConnectionString; conn = new NpgsqlConnection(connectionString); conn.Open(); if (empresa != null) { log.WriteEntry("Invoice codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosFactura + "]", EventLogEntryType.Information, 16, 1); log.WriteEntry("Payment codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosPago + "]", EventLogEntryType.Information, 17, 1); log.WriteEntry("Sale codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosVenta + "]", EventLogEntryType.Information, 17, 1); log.WriteEntry("Return codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosDevolucion + "]", EventLogEntryType.Information, 17, 1); string[] facturas = clientConfig.CodigosFactura.Split(','); string[] abonos = clientConfig.CodigosPago.Split(','); string[] venta = clientConfig.CodigosVenta.Split(','); string[] devolucion = clientConfig.CodigosDevolucion.Split(','); try { //AdminPaqImpl.DownloadMonitors(venta, devolucion, facturas, abonos, empresa, log); log.WriteEntry("Downloading from AdminPaq: " + empresa.Ruta, EventLogEntryType.Information, 8, 2); // DIM ETLs List <CatCliente> clientes = CatCliente.GetClientes(empresa.Ruta); log.WriteEntry(clientes.Count + " clientes found for " + empresa.Nombre + " in AdminPaq", EventLogEntryType.Information, 9, 2); ETLClientes.Execute(empresa.Id, empresa.Nombre, clientes, conn); List <CatSeller> sellers = CatSeller.GetSellers(empresa.Ruta); log.WriteEntry(sellers.Count + " agents found for " + empresa.Nombre + " in AdminPaq", EventLogEntryType.Information, 10, 2); ETLSellers.Execute(empresa.Id, empresa.Nombre, sellers, conn); ETLMeses.Execute(conn); // FACT Preparation FactVencido vencido = new FactVencido(); vencido.Prepare(empresa.Id, empresa.Ruta, conn); log.WriteEntry(string.Format("Prepared due documents for {0}", empresa.Nombre), EventLogEntryType.Information, 11, 2); FactPorVencer porVencer = new FactPorVencer(); porVencer.Prepare(empresa.Id, empresa.Ruta, conn); log.WriteEntry(string.Format("Prepared documents about to due for {0}", empresa.Nombre), EventLogEntryType.Information, 12, 2); FactCobranza cobranza = new FactCobranza(); cobranza.Prepare(empresa.Id, empresa.Ruta, conn); log.WriteEntry(string.Format("Prepared collection documents for {0}", empresa.Nombre), EventLogEntryType.Information, 13, 2); FactSales factSale = new FactSales(); factSale.Prepare(empresa.Id, empresa.Ruta, conn); log.WriteEntry(string.Format("Prepared sale documents for {0}", empresa.Nombre), EventLogEntryType.Information, 14, 2); // FILL FACTS DocsMiner dMiner = new DocsMiner(); dMiner.Vencidos = vencido.GruposVencimiento; dMiner.PorVencer = porVencer.GruposVencimiento; dMiner.Cobranza = cobranza.GruposCobranza; dMiner.Ventas = factSale.GruposVenta; log.WriteEntry(string.Format("Mining documents for {0} started", empresa.Nombre), EventLogEntryType.Information, 15, 2); dMiner.Execute(empresa, facturas, abonos, venta, devolucion, log); log.WriteEntry(string.Format("Mining documents for {0} completed", empresa.Nombre), EventLogEntryType.Information, 16, 2); MainLoader loader = new MainLoader(); loader.Vencidos = dMiner.Vencidos; loader.PorVencer = dMiner.PorVencer; loader.Cobranza = dMiner.Cobranza; loader.Ventas = dMiner.Ventas; log.WriteEntry(string.Format("Loading documents for {0} started", empresa.Nombre), EventLogEntryType.Information, 17, 2); loader.Load(empresa.Id, conn); log.WriteEntry(string.Format("Loading documents for {0} completed", empresa.Nombre), EventLogEntryType.Information, 18, 2); }catch (Exception ex) { log.WriteEntry("Exception while mining monitors: " + ex.Message + " || " + ex.StackTrace, EventLogEntryType.Error, 19, 2); } } conn.Close(); } }