private void SceneLoaded(Scene scene, LoadSceneMode modee) { if (lastScene.isLoaded && lastScene.name != null) { Logger.InfoFormat("The last scene {0} have been loaded, unload it first!", lastScene.name); SceneManager.UnloadSceneAsync(lastScene); } lastScene = scene; if (!scene.isLoaded) { throw new Exception("Scene is not loaded."); } SceneManager.SetActiveScene(scene); Logger.DebugFormat("SET ACTIVE SCENE: {0}", scene.name); foreach (var go in scene.GetRootGameObjects()) { var comp = go.GetComponentInChildren <PositionRelatedEffect>(); if (comp != null) { _effectUpdater = new PositionRelatedEffectUpdater(comp); } // 禁用相机,保证角色动画不更新 if (SharedConfig.IsServer) { foreach (var v in go.GetComponentsInChildren <Camera>()) { v.enabled = false; } } } if (AllSceneLoaded != null) { AllSceneLoaded(); } if (onSceneLoaded != null) { onSceneLoaded(0, 0, scene); } }
private void SceneLoaded(Scene scene, LoadSceneMode modee) { var match = _scenePositionRegex.Match(scene.name); if (match.Success) { int index1 = Convert.ToInt32(match.Groups[1].Value); int index2 = Convert.ToInt32(match.Groups[2].Value); _sceneLoadMap[index1, index2].State = SceneState.Loaded; _sceneLoadMap[index1, index2].Scene = scene; _sceneLoadMap[index1, index2].Active = true; foreach (var gameObject in _sceneLoadMap[index1, index2].Scene.GetRootGameObjects()) { var terrain = gameObject.GetComponent <Terrain>(); if (terrain != null) { Type t = Type.GetType("ArtPlugins.TerrainProxy, Assembly-CSharp"); if (t != null) { terrain.gameObject.AddComponent(t); Logger.Debug("ArtPlugins.TerrainProxy, Assembly-CSharp Founded"); } else { Logger.Debug("ArtPlugins.TerrainProxy, Assembly-CSharp Not Founded"); } } } if (onSceneLoaded != null) { Logger.DebugFormat("onSceneLoaded Terrain {0} {1}", index1, index2); onSceneLoaded(index1, index2, _sceneLoadMap[index1, index2].Scene); } _loadingScene--; if (SceneLoadedEvent != null) { var center = _basePosition + new Vector3(_gridSize * (index1 + 0.5f), 0, _gridSize * (index2 + 0.5f)); // 预设:场景高度在0~1000m之间 float heightScope = 1000; center.y = heightScope * 0.5f; SceneLoadedEvent(scene, center, _gridSize > heightScope ? _gridSize : heightScope); } } if (_additiveScenes != null && _additiveScenes.Contains(scene.name)) { SceneManager.SetActiveScene(scene); Logger.InfoFormat("SET ACTIVE SCENE: {0}", scene.name); foreach (var go in scene.GetRootGameObjects()) { var comp = go.GetComponentInChildren <PositionRelatedEffect>(); if (comp != null) { _effectUpdater = new PositionRelatedEffectUpdater(comp); } foreach (var v in go.GetComponentsInChildren <Camera>()) { // 禁用相机,保证角色动画不更新 if (SharedConfig.IsServer) { v.enabled = false; } else { Type t = Type.GetType("ArtPlugins.GQS_Bind_Camera, Assembly-CSharp"); if (t != null) { v.gameObject.AddComponent(t); } else { Logger.Error("ArtPlugins.GQS_Bind_Camera is null ??? !!!"); } } v.useOcclusionCulling = SharedConfig.EnableOC; } } _loadingScene--; } foreach (var gameObject in scene.GetRootGameObjects()) { var terrain = gameObject.GetComponent <Terrain>(); if (terrain != null) { terrain.treeDistance = 800; } } Logger.InfoFormat("Scene loaded: {0}, remain loading scene: {1}", scene.name, _loadingScene); if (_loadingScene == 0 && AllSceneLoaded != null) { AllSceneLoaded(); } }