/// <summary> /// Prepares the scenes array from collection /// </summary> void PrepareScenesArray() { scenesArray = new Dictionary <int[], SceneSplit> (new IntArrayComparer()); foreach (var sceneName in sceneCollection.names) { int posX = 0; int posY = 0; int posZ = 0; SceneNameToPos(sceneCollection, sceneName, out posX, out posY, out posZ); SceneSplit sceneSplit = new SceneSplit(); sceneSplit.posX = posX; sceneSplit.posY = posY; sceneSplit.posZ = posZ; sceneSplit.sceneName = sceneName.Replace(".unity", ""); scenesArray.Add(new int[] { posX, posY, posZ }, sceneSplit); } }
/// <summary> /// Manages async scene loading /// </summary> void LoadLevelAsyncManage() { if (scenesToLoad.Count > 0 && currentlySceneLoading <= 0) { if (LoadingProgress < 1 || sceneLoadFramesNextWaited && sceneLoadFrameNext <= 0) { sceneLoadFramesNextWaited = false; sceneLoadFrameNext = sceneLoadWaitFrames; while (currentlySceneLoading < maxParalleSceneLoading && scenesToLoad.Count > 0) { SceneSplit split = scenesToLoad [0]; /// if (!Application.isWebPlayer || Application.isWebPlayer && Application.CanStreamedLevelBeLoaded (split.sceneName)) { /// scenesToLoad.Remove (split); /// currentlySceneLoading++; /// Application.LoadLevelAdditiveAsync (split.sceneName); /// } } } else { sceneLoadFramesNextWaited = true; sceneLoadFrameNext--; } } }
private void LoadLevelAsyncManage() { if (!this.CanLoad()) { return; } if (this.scenesToLoad.Count > 0 && this.currentlySceneLoading <= 0) { if (this.LoadingProgress < 1f || (this.sceneLoadFramesNextWaited && this.sceneLoadFrameNext <= 0)) { this.sceneLoadFramesNextWaited = false; this.sceneLoadFrameNext = this.sceneLoadWaitFrames; while (this.currentlySceneLoading < this.maxParallelSceneLoading && this.scenesToLoad.Count > 0) { SceneSplit sceneSplit = this.scenesToLoad[0]; this.scenesToLoad.Remove(sceneSplit); this.currentlySceneLoading++; MainLevel.Instance.m_SceneAsyncOperation.Add(SceneManager.LoadSceneAsync(sceneSplit.sceneName, LoadSceneMode.Additive)); } } else { this.sceneLoadFramesNextWaited = true; this.sceneLoadFrameNext--; } } }
/// <summary>扩展连接关闭</summary> private void SessionClosedExtend() { Variable.RemoveLine(Player.User.id); report_day.OnOffLine(); RemoveCCI(); CloseTask(); GameUpdate(); GetScene(); SceneSplit.RemoveScene(Player.User.id); RemoveUser(); ClearMemory(); #if DEBUG XTrace.WriteLine("{0}", "连接关闭"); #endif }
/// <summary>正常下线</summary> private void NormalOut(view_scene_user userscene) { var otherplays = Scene.GetOtherPlayers(userscene.user_id, userscene.scene_id, (int)ModuleNumber.SCENE); if (!otherplays.Any()) { return; } #region 场景拆分 2015-03-19 var _plays = SceneSplit.GetSceneSplitPlayers(userscene.user_id, otherplays); #endregion foreach (var item in _plays) { var obj = new OnlineObject { OffLine = userscene.user_id, OtherPlayer = item.user_id }; var tokenTest = new CancellationTokenSource(); Task.Factory.StartNew(m => { var temp = m as OnlineObject; if (temp == null) { return; } if (!Variable.OnlinePlayer.ContainsKey(temp.OtherPlayer)) { return; } var otherplayerssession = Variable.OnlinePlayer[temp.OtherPlayer] as TGGSession; if (otherplayerssession == null) { return; } var aso = BuildData(temp.OffLine); SendPushCommand(otherplayerssession, aso, (int)SceneCommand.PLAYER_EXIT_SCENET, (int)ModuleNumber.SCENE); tokenTest.Cancel(); }, obj, tokenTest.Token); } }
private void PrepareScenesArray() { this.scenesArray = new Dictionary <int[], SceneSplit>(new IntArrayComparer()); foreach (string text in this.sceneCollection.names) { int num = 0; int num2 = 0; int num3 = 0; Streamer.SceneNameToPos(this.sceneCollection, text, out num, out num2, out num3); SceneSplit sceneSplit = new SceneSplit(); sceneSplit.posX = num; sceneSplit.posY = num2; sceneSplit.posZ = num3; sceneSplit.sceneName = text.Replace(".unity", string.Empty); this.scenesArray.Add(new int[] { num, num2, num3 }, sceneSplit); } }
/// <summary> /// Loads tiles in range /// </summary> void SceneLoading() { //Debug.Log (showLoadingScreen); if (showLoadingScreen && loadingStreamer != null) { showLoadingScreen = false; if (tilesLoaded >= tilesToLoad) { tilesToLoad = int.MaxValue; tilesLoaded = 0; } } int tilesToLoadNew = 0; int[] sceneIDPlayer = new int[] { xPos, yPos, zPos }; if (scenesArray.ContainsKey(sceneIDPlayer)) { SceneSplit split = scenesArray [sceneIDPlayer]; if (!split.loaded) { split.loaded = true; scenesToLoad.Add(split); loadedScenes.Add(split); tilesToLoadNew++; } } for (int x = -(int)loadingRange.x + xPos; x <= (int)loadingRange.x + xPos; x++) { for (int y = -(int)loadingRange.y + yPos; y <= (int)loadingRange.y + yPos; y++) { for (int z = -(int)loadingRange.z + zPos; z <= (int)loadingRange.z + zPos; z++) { int[] sceneID = new int[] { x, y, z }; float xMoveLimit = 0; int xDeloadLimit = 0; float yMoveLimit = 0; int yDeloadLimit = 0; float zMoveLimit = 0; int zDeloadLimit = 0; if (looping) { if (sceneCollection.xSplitIs) { if (x > sceneCollection.xLimitsy) { int xLimit = (int)sceneCollection.xLimitsy + 1; xMoveLimit = ((int)(x / xLimit)) * xLimit * sceneCollection.xSize; xDeloadLimit = ((int)(x / xLimit)) * xLimit; sceneID [0] = x % xLimit; } if (x < sceneCollection.xLimitsx) { int xLimit = (int)sceneCollection.xLimitsy + 1; xMoveLimit = ((int)((x + 1) / xLimit) - 1) * xLimit * sceneCollection.xSize; xDeloadLimit = ((int)((x + 1) / xLimit) - 1) * xLimit; sceneID [0] = (xLimit + (x % xLimit)) % xLimit; } } if (sceneCollection.ySplitIs) { if (y > sceneCollection.yLimitsy) { int yLimit = (int)sceneCollection.yLimitsy + 1; yMoveLimit = ((int)(y / yLimit)) * yLimit * sceneCollection.ySize; yDeloadLimit = ((int)(y / yLimit)) * yLimit; sceneID [1] = y % yLimit; } if (y < sceneCollection.yLimitsx) { int yLimit = (int)sceneCollection.yLimitsy + 1; yMoveLimit = ((int)((y + 1) / yLimit) - 1) * yLimit * sceneCollection.ySize; yDeloadLimit = ((int)((y + 1) / yLimit) - 1) * yLimit; sceneID [1] = (yLimit + (y % yLimit)) % yLimit; } } if (sceneCollection.zSplitIs) { if (z > sceneCollection.zLimitsy) { int zLimit = (int)sceneCollection.zLimitsy + 1; zMoveLimit = ((int)(z / zLimit)) * zLimit * sceneCollection.zSize; zDeloadLimit = ((int)(z / zLimit)) * zLimit; sceneID [2] = z % zLimit; } if (z < sceneCollection.zLimitsx) { int zLimit = (int)sceneCollection.zLimitsy + 1; zMoveLimit = ((int)((z + 1) / zLimit) - 1) * zLimit * sceneCollection.zSize; zDeloadLimit = ((int)((z + 1) / zLimit) - 1) * zLimit; sceneID [2] = (zLimit + (z % zLimit)) % zLimit; } } } if (scenesArray.ContainsKey(sceneID)) { SceneSplit split = scenesArray [sceneID]; if (!split.loaded) { split.loaded = true; split.posXLimitMove = xMoveLimit; split.xDeloadLimit = xDeloadLimit; split.posYLimitMove = yMoveLimit; split.yDeloadLimit = yDeloadLimit; split.posZLimitMove = zMoveLimit; split.zDeloadLimit = zDeloadLimit; scenesToLoad.Add(split); loadedScenes.Add(split); tilesToLoadNew++; } } } } } tilesToLoad = tilesToLoadNew; }
private void SceneLoading() { if (this.showLoadingScreen && this.loadingStreamer != null) { this.showLoadingScreen = false; if (this.tilesLoaded >= this.tilesToLoad) { this.tilesToLoad = int.MaxValue; this.tilesLoaded = 0; } } int num = 0; if (!this.useLoadingRangeMin) { int num2 = this.xPos; int num3 = this.yPos; int num4 = this.zPos; int[] array = new int[] { num2, num3, num4 }; float posXLimitMove = 0f; int num5 = 0; float posYLimitMove = 0f; int num6 = 0; float posZLimitMove = 0f; int num7 = 0; if (this.looping) { if (this.sceneCollection.xSplitIs) { int num8 = this.mod(num2 + Mathf.Abs(this.xLimitx), this.xRange) + this.xLimitx; num5 = (int)Math.Ceiling((double)((float)(num2 - this.xLimity) / (float)this.xRange)) * this.xRange; posXLimitMove = (float)(num5 * this.sceneCollection.xSize); array[0] = num8; } if (this.sceneCollection.ySplitIs) { int num9 = this.mod(num3 + Mathf.Abs(this.yLimitx), this.yRange) + this.yLimitx; num6 = (int)Math.Ceiling((double)((float)(num3 - this.yLimity) / (float)this.yRange)) * this.yRange; posYLimitMove = (float)(num6 * this.sceneCollection.ySize); array[1] = num9; } if (this.sceneCollection.zSplitIs) { int num10 = this.mod(num4 + Mathf.Abs(this.zLimitx), this.zRange) + this.zLimitx; num7 = (int)Math.Ceiling((double)((float)(num4 - this.zLimity) / (float)this.zRange)) * this.zRange; posZLimitMove = (float)(num7 * this.sceneCollection.zSize); array[2] = num10; } } if (this.scenesArray.ContainsKey(array)) { SceneSplit sceneSplit = this.scenesArray[array]; if (!sceneSplit.loaded) { sceneSplit.loaded = true; sceneSplit.posXLimitMove = posXLimitMove; sceneSplit.xDeloadLimit = num5; sceneSplit.posYLimitMove = posYLimitMove; sceneSplit.yDeloadLimit = num6; sceneSplit.posZLimitMove = posZLimitMove; sceneSplit.zDeloadLimit = num7; this.scenesToLoad.Add(sceneSplit); this.loadedScenes.Add(sceneSplit); num++; } } } for (int i = -(int)this.loadingRange.x + this.xPos; i <= (int)this.loadingRange.x + this.xPos; i++) { for (int j = -(int)this.loadingRange.y + this.yPos; j <= (int)this.loadingRange.y + this.yPos; j++) { for (int k = -(int)this.loadingRange.z + this.zPos; k <= (int)this.loadingRange.z + this.zPos; k++) { if (!this.useLoadingRangeMin || (float)(i - this.xPos) < -this.loadingRangeMin.x || (float)(i - this.xPos) > this.loadingRangeMin.x || (float)(j - this.yPos) < -this.loadingRangeMin.y || (float)(j - this.yPos) > this.loadingRangeMin.y || (float)(k - this.zPos) < -this.loadingRangeMin.z || (float)(k - this.zPos) > this.loadingRangeMin.z) { int[] array2 = new int[] { i, j, k }; float posXLimitMove2 = 0f; int num11 = 0; float posYLimitMove2 = 0f; int num12 = 0; float posZLimitMove2 = 0f; int num13 = 0; if (this.looping) { if (this.sceneCollection.xSplitIs) { int num14 = this.mod(i + Mathf.Abs(this.xLimitx), this.xRange) + this.xLimitx; num11 = (int)Math.Ceiling((double)((float)(i - this.xLimity) / (float)this.xRange)) * this.xRange; posXLimitMove2 = (float)(num11 * this.sceneCollection.xSize); array2[0] = num14; } if (this.sceneCollection.ySplitIs) { int num15 = this.mod(j + Mathf.Abs(this.yLimitx), this.yRange) + this.yLimitx; num12 = (int)Math.Ceiling((double)((float)(j - this.yLimity) / (float)this.yRange)) * this.yRange; posYLimitMove2 = (float)(num12 * this.sceneCollection.ySize); array2[1] = num15; } if (this.sceneCollection.zSplitIs) { int num16 = this.mod(k + Mathf.Abs(this.zLimitx), this.zRange) + this.zLimitx; num13 = (int)Math.Ceiling((double)((float)(k - this.zLimity) / (float)this.zRange)) * this.zRange; posZLimitMove2 = (float)(num13 * this.sceneCollection.zSize); array2[2] = num16; } } if (this.scenesArray.ContainsKey(array2)) { SceneSplit sceneSplit2 = this.scenesArray[array2]; if (!sceneSplit2.loaded) { sceneSplit2.loaded = true; sceneSplit2.posXLimitMove = posXLimitMove2; sceneSplit2.xDeloadLimit = num11; sceneSplit2.posYLimitMove = posYLimitMove2; sceneSplit2.yDeloadLimit = num12; sceneSplit2.posZLimitMove = posZLimitMove2; sceneSplit2.zDeloadLimit = num13; this.scenesToLoad.Add(sceneSplit2); this.loadedScenes.Add(sceneSplit2); num++; } } } } } } this.tilesToLoad = num; this.initialized = true; }