/// <summary> /// 重置 /// </summary> public void Reset() { IsFinish = false; InLoading = false; m_loader = null; }
// Reset #endregion #region OnEnter public override void OnEnter() { // build LoadingQ // Number of objects in the scene to parse int NumObjectsToParse = 0; // loop through each object in the list int j = SceneObjects.Length; for (int i = 0; i < j; i++) { // skip if null if (SceneObjects[i] == null) { continue; } // create the loader info LoaderInfo LoaderSceneObj = new LoaderInfo { LoaderGO = SceneObjects[i].Value }; NumObjectsToParse++; // add children, if checked if ((ParseChildrens[i] != null) && (ParseChildrens[i].Value)) { // get child count int ChildCount = LoaderSceneObj.LoaderGO.transform.childCount; // loop through and add the children for (int iChild = 0; iChild < ChildCount; iChild++) { LoaderSceneObj.ChildQ.Enqueue(LoaderSceneObj.LoaderGO.transform.GetChild(iChild).gameObject); NumObjectsToParse++; } } // add to the queue LoadingQ.Enqueue(LoaderSceneObj); } // unbox the progressbar SldProgressbar = NguiProgressbar.Value.GetComponent <UISlider>(); // unbox the label if (NguiProgressbarLabel != null) { LblProgressText = NguiProgressbarLabel.Value.GetComponent <UILabel>(); } // unbox the loader camera CameraLoader = Fsm.GetOwnerDefaultTarget(SceneLoaderCamera).GetComponent <Camera>(); // set the steps for the progressbar update ProgressStepValue = (float)NumObjectsToParse / 10000; // set progressbar values SetProgressbarValue(0); }
/// <summary> /// 加载下一个 /// </summary> private void LoadNext() { if (m_loader != null) { m_task.PushLoader(m_loader.Loader); m_loader = null; } if (m_loaders.Count == 0) { IsFinish = true; return; } m_loader = m_loaders[0]; m_loaders.RemoveAt(0); switch (m_loader.Loader.State) { case Loader.LoaderState.None: PushCallback(); m_loader.Loader.Load(); break; case Loader.LoaderState.Loading: PushCallback(); break; case Loader.LoaderState.Finished: LoadCompleted(m_loader, m_loader.Loader.Data); LoadNext(); break; } }
/// <summary> /// 下载完一个文件 /// </summary> /// <param name="info"></param> private void OnLoadComplete(LoaderInfo info) { File.WriteAllBytes(info.fileFullName, info.request.downloadHandler.data); if (singleLoadedCallback != null) { singleLoadedCallback(Path.GetFileNameWithoutExtension(currLoaderInfo.fileFullName) + " is loaded", currLoaderInfo.request.downloadHandler.data); } this.m_loadedCount++; if (this.m_loadedCount == this.m_totalCount) { currLoaderInfo = null; if (allLoadedCallback != null) { allLoadedCallback(); } } else { StartLoad(); } }
/// <summary> /// Načíta schému databázy pre spojenie <paramref name="connection"/>. Schéma je načítaná priamo z databázy aj v prípade, /// že už je uložená v keši. /// </summary> /// <param name="connection">Spojenie na databázu.</param> /// <returns>Schéma danej databázy.</returns> /// <exception cref="InvalidOperationException">Keš neobsahuje loader pre spojenie na databázu /// <paramref name="connection"/>.</exception> public DatabaseSchema RefreshSchema(object connection) { LoaderInfo linfo = GetLoaderInfo(connection); DatabaseSchema schema = linfo.Loader.LoadSchema(connection); _cache.AddOrUpdate(linfo.KeyGenerator.GenerateKey(connection), schema, (k, v) => schema); return(schema); }
/// <summary> /// 加载完成 /// </summary> /// <param name="info">加载器信息</param> /// <param name="data">加载结果</param> private void LoadCompleted(LoaderInfo info, object data) { if (info == null || info.Callback == null) { return; } info.Callback(this, data); }
/// <summary> /// 添加加载任务 /// </summary> /// <param name="url"></param> /// <param name="fileFullName"></param> public void Add(string url, string fileFullName) { LoaderInfo info = new LoaderInfo() { url = url, fileFullName = fileFullName }; loaderRequests.Enqueue(info); m_totalCount = loaderRequests.Count; m_loadedCount = 0; }
/// <summary> /// Update方式加载队列资源 /// 需要Add好所有LoaderInfo后才可以开始加载,有任意一个错误,会中断所有加载 /// 加载完的资源不缓存 /// </summary> public void StartLoad() { if (m_totalCount == 0) { return; } currLoaderInfo = loaderRequests.Dequeue(); currLoaderInfo.request = KTDownloadHelper.DownloadFileRequest(currLoaderInfo.url, currLoaderInfo.fileFullName); currLoaderInfo.opt = currLoaderInfo.request.SendWebRequest(); }
private LoaderInfo GetLoaderInfo(object connection) { LoaderInfo linfo = _loaders.FirstOrDefault((tmpLoader) => tmpLoader.Loader.SupportsConnectionType(connection)); if (linfo == null) { throw new InvalidOperationException( string.Format(Resources.DatabaseSchemaCache_UnsupportedDatabaseType, connection.GetType().FullName)); } return(linfo); }
public void DefaultScenarioSameThreadTest() { SimulationServer.Start("AntMeTest", SimulationServer.DEFAULTPORT); byte[] file = File.ReadAllBytes(@".\AntMe.Levelpack.dll"); LoaderInfo loader = AntMe.Runtime.ExtensionLoader.SecureAnalyseExtension(file, true, true); loader.Levels[0].Type.AssemblyFile = file; loader.Players[0].Type.AssemblyFile = file; int lastRound = -1; // Client 1 ISimulationClient client1 = SimulationClient.CreateNamedPipe("AntMeTest"); client1.OnLevelChanged += (c, l) => { if (l != null) { Task t = new Task(() => { c.UploadPlayer(loader.Players[0].Type); c.SetPlayerState(0, PlayerColor.Green, 0, true); }); t.Start(); } }; client1.Open("Client 1"); // Client 2 ISimulationClient client2 = SimulationClient.CreateNamedPipe("AntMeTest"); client2.OnPlayerChanged += (c, s) => { var slot = c.Slots[s]; if (slot.ReadyState && slot.PlayerInfo) { Task t = new Task(() => { c.StartSimulation(); }); t.Start(); } }; client2.OnSimulationState += (c, s) => { lastRound = s.Round; }; client2.Open("Client 2"); client2.AquireMaster(); client2.UploadLevel(loader.Levels[0].Type); Thread.Sleep(10000); Assert.IsTrue(lastRound > 0); SimulationServer.Stop(); }
/// 与 LoadScene联用 记录预加载对象 bool PreLoadScene(ResLoader loader) { LoaderInfo loaderInfo = assetBundleLoaderMap[loader.abName]; //远程资源信息 string remoteKey = loaderInfo.key; //远程资源key值 string abName = loader.abName; if (IsLoaded(abName, loaderInfo.key) || preLoaderMap.ContainsKey(abName)) { return(false); } preLoaderMap.Add(abName, loader); return(true); }
public void Stop() { if (currLoaderInfo != null) { currLoaderInfo.request.Abort(); currLoaderInfo.Dispose(); currLoaderInfo = null; } foreach (var info in loaderRequests) { info.Dispose(); } loaderRequests.Clear(); }
private void MainForm_Load(object sender, EventArgs e) { // Try to use TLS 1.2 try { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; } catch { } if (!Debugger.IsAttached) { Environment.CurrentDirectory = Application.StartupPath; } SetDoubleBuffered(modListView, true); loaderini = File.Exists(loaderinipath) ? IniSerializer.Deserialize <LoaderInfo>(loaderinipath) : new LoaderInfo(); try { if (File.Exists(codelstpath)) { mainCodes = CodeList.Load(codelstpath); } else if (File.Exists(codexmlpath)) { mainCodes = CodeList.Load(codexmlpath); } else { mainCodes = new CodeList(); } } catch (Exception ex) { MessageBox.Show(this, $"Error loading code list: {ex.Message}", "Sonic CD Steam Mod Manager", MessageBoxButtons.OK, MessageBoxIcon.Warning); mainCodes = new CodeList(); } LoadModList(); checkUpdateStartup.Checked = loaderini.UpdateCheck; checkUpdateModsStartup.Checked = loaderini.ModUpdateCheck; comboUpdateFrequency.SelectedIndex = (int)loaderini.UpdateUnit; numericUpdateFrequency.Value = loaderini.UpdateFrequency; }
/// <summary>处理队列加载资源</summary> private void LoadRes(ResLoader resLoader, Action <string> quequeHandler) { if (assetBundleLoaderMap.ContainsKey(resLoader.abName)) { resLoader.quequeHandler = quequeHandler; //记录加载完成时的队列回调 LoaderInfo loaderInfo = assetBundleLoaderMap[resLoader.abName]; if (IsLoaded(resLoader.abName, loaderInfo.key)) //已经加载 { resLoader.quequeHandler(resLoader.resId); return; } loaderQueue.Add(resLoader); if (loadingMap.ContainsKey(resLoader.abName))//已经加载中 { return; } loadingMap.Add(resLoader.abName, true); StartCoroutine(_LoadRes()); } else { quequeHandler(resLoader.resId); } }
/// <summary> /// 添加任务 /// </summary> /// <param name="type">类型</param> /// <param name="path">路径</param> /// <param name="param">附加参数</param> /// <param name="onLoaded">回调</param> /// <param name="async">异步</param> /// <param name="insert">插队</param> public void Add(Loader.LoaderType type, string path, object param, LoadMgr.GroupLoadedCallback onLoaded, bool async, bool insert) { LoaderInfo loader = new LoaderInfo { Loader = m_task.PopLoader(type, path, param, async), Callback = onLoaded }; if (insert) { m_loaders.Insert(0, loader); } else { m_loaders.Add(loader); } if (InLoading && IsFinish) { IsFinish = false; LoadNext(); } }
/// <summary> /// Zruší z keše schému databázy načítanú pre spojenie <paramref name="connection"/>. /// </summary> /// <param name="connection">Spojenie na databázu.</param> /// <exception cref="InvalidOperationException">Keš neobsahuje loader pre spojenie na databázu /// <paramref name="connection"/>.</exception> public void ClearSchema(object connection) { LoaderInfo linfo = GetLoaderInfo(connection); _cache.TryRemove(linfo.KeyGenerator.GenerateKey(connection), out DatabaseSchema schema); }
IEnumerator _LoadResManifest(ResLoader item) { string f = item.abName + ".manifest"; fileUrl = webUrl + f + "?v=" + random; //接取服务器资源 localfile = (dataPath + f).Trim(); string path; string localKey; LoaderInfo loaderInfo = assetBundleLoaderMap[f]; string remoteKey = loaderInfo.key; if (!assetBundleLoaderMap.ContainsKey(f)) { Debug.LogError("不存在资源:" + f); item.quequeHandler(""); yield break; } bool canUpdate = !File.Exists(localfile);// 是否需要更新 path = Path.GetDirectoryName(localfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!canUpdate) //检查是否更新 { localKey = PlayerPrefs.GetString(f); canUpdate = !remoteKey.Equals(localKey); if (canUpdate) { File.Delete(localfile); } } if (canUpdate) { //更新或新增文件 WWW www = new WWW(fileUrl); while (!www.isDone) { item.CallProgress(www.progress * 0.1f + 0.70f); yield return(1); } if (www.error != null) { item.quequeHandler(""); www.Dispose(); www = null; yield break; } if (www.isDone) { yield return(1); File.WriteAllBytes(localfile, www.bytes); PlayerPrefs.SetString(f, remoteKey); www.Dispose(); www = null; yield break; } } yield return(0); }
public static void remove_httpStatus(LoaderInfo that, Action <HTTPStatusEvent> value) { CommonExtensions.RemoveDelegate(that, value, HTTPStatusEvent.HTTP_STATUS); }
/// <summary> /// Vráti schému databázy pre spojenie <paramref name="connection"/>. /// </summary> /// <param name="connection">Spojenie na databázu.</param> /// <returns>Schéma danej databázy.</returns> /// <exception cref="InvalidOperationException">Keš neobsahuje loader pre spojenie na databázu /// <paramref name="connection"/>.</exception> public DatabaseSchema GetSchema(object connection) { LoaderInfo linfo = GetLoaderInfo(connection); return(_cache.GetOrAdd(linfo.KeyGenerator.GenerateKey(connection), (k) => linfo.Loader.LoadSchema(connection))); }
public static void remove_init(LoaderInfo that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.INIT); }
public static void add_init(LoaderInfo that, Action <Event> value) { CommonExtensions.CombineDelegate(that, value, Event.INIT); }
public static void add_open(LoaderInfo that, Action <Event> value) { CommonExtensions.CombineDelegate(that, value, Event.OPEN); }
public static void remove_ioError(LoaderInfo that, Action <IOErrorEvent> value) { CommonExtensions.RemoveDelegate(that, value, IOErrorEvent.IO_ERROR); }
public static void remove_open(LoaderInfo that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.OPEN); }
public static void remove_progress(LoaderInfo that, Action <ProgressEvent> value) { CommonExtensions.RemoveDelegate(that, value, ProgressEvent.PROGRESS); }
public static void add_unload(LoaderInfo that, Action <Event> value) { CommonExtensions.CombineDelegate(that, value, Event.UNLOAD); }
IEnumerator _LoadRes() { if (loaderQueue.Count == 0) { yield break; } ResLoader item = loaderQueue[0]; loaderQueue.RemoveAt(0); string f = item.abName; //assetbundle资源名 string path; //本地资源位置 string localKey; //当前本地资源key值 LoaderInfo loaderInfo = assetBundleLoaderMap[f]; //远程资源信息 string remoteKey = loaderInfo.key; //远程资源key值 #region 再检查是否已经加载 if (IsLoaded(f, loaderInfo.key)) { item.quequeHandler(item.resId); loadingMap.Remove(f); item.quequeHandler(item.resId); yield return(StartCoroutine(_LoadRes())); yield break; } #endregion if (!assetBundleLoaderMap.ContainsKey(f)) { Debug.LogError("不存在资源:" + f); loadingMap.Remove(f); item.quequeHandler(""); yield return(StartCoroutine(_LoadRes())); yield break; } fileUrl = webUrl + f + "?v=" + random; //接取服务器资源 localfile = (dataPath + f).Trim(); bool canUpdate = !File.Exists(localfile);// 是否需要更新 path = Path.GetDirectoryName(localfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!canUpdate) //检查是否更新 { localKey = PlayerPrefs.GetString(f); canUpdate = !remoteKey.Equals(localKey); if (canUpdate) { File.Delete(localfile); } } if (canUpdate) { //更新或新增文件 WWW www = new WWW(fileUrl); while (!www.isDone) { item.CallProgress(www.progress * 0.70f); yield return(1); } if (www.error != null) { loadingMap.Remove(f); item.quequeHandler(""); yield return(StartCoroutine(_LoadRes())); www.Dispose(); www = null; yield break; } if (www.isDone) { yield return(1); File.WriteAllBytes(localfile, www.bytes); yield return(StartCoroutine(_LoadResManifest(item))); loadingMap.Remove(item.abName); PlayerPrefs.SetString(item.abName, remoteKey);//记录是否下载了最新key item.quequeHandler(item.resId); www.Dispose(); www = null; } } yield return(StartCoroutine(_LoadRes())); }
public static void remove_complete(LoaderInfo that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.COMPLETE); }
// OnEnter #endregion #region OnUpdate public override void OnUpdate() { // for safety, exit if finished if (IsFinishedLoading) { return; } // exit if we are still waiting for the next object time if (TimeToLoadNextObject > Time.time) { return; } // if we have an existing object we're tracking, we can clear it now if (CurrentGO != null) { // check if we need to set this to inactive if (SetToInactive) { CurrentGO.SetActiveRecursively(false); } // reset flag SetToInactive = false; } // process if we have an existing item from the Q if (CurrentLoaderGO != null) { // check if we have a parent, and have finished all it's children if (CurrentLoaderGO.ChildQ.Count == 0) { // move the camera to the parent, if it is NOT the current go if (!CurrentLoaderGO.LoaderGO.Equals(CurrentGO)) { // move the camera MoveCameraToGO(CurrentLoaderGO.LoaderGO); // exit update, so the the camera will render the object return; } // parent has already been moved, time to clean up if (SetParentInactive) { CurrentLoaderGO.LoaderGO.SetActiveRecursively(false); } // clear the flag SetParentInactive = false; // clear parent CurrentLoaderGO = null; } // we have children which need to be processed else { // get the next child CurrentGO = CurrentLoaderGO.ChildQ.Dequeue(); // set inactive flag SetToInactive = !CurrentGO.active; // move the camera to this object MoveCameraToGO(CurrentGO); // exit update, so the the camera will render the object return; } } // when here, we are finished dealing with previous object and need to get the next object if (LoadingQ.Count > 0) { // get the next object from the Q CurrentLoaderGO = LoadingQ.Dequeue(); // check if we have children if (CurrentLoaderGO.ChildQ.Count > 0) { // assign a child CurrentGO = CurrentLoaderGO.ChildQ.Dequeue(); // set active flags SetParentInactive = !CurrentLoaderGO.LoaderGO.active; SetToInactive = !CurrentGO.active; // move the camera MoveCameraToGO(CurrentGO); // exit update, so the the camera will render the object return; } // no children, use the loader GO CurrentGO = CurrentLoaderGO.LoaderGO; // set active flag SetToInactive = !CurrentGO.active; // move the camera MoveCameraToGO(CurrentGO); // exit update, so the the camera will render the object return; } // nothing left to process! IsFinishedLoading = true; // don't call finish until we finish loading everything if (IsFinishedLoading) { Finish(); } }
public static void remove_unload(LoaderInfo that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.UNLOAD); }