private void LoadCell(string newcell, Action <string> callback, LoadPriority lp) { string lumdaName = newcell; if (!mAllLoadObjs.Keys.Contains(lumdaName)) { // @xl lumdaName,也就是lod地块prefab的名字是这个格式"场景名_Chunk_数字_LOD_数字" //Debug.LogError("really load ::" + newcell); string pName = lumdaName + ".prefab"; string bundleName = GOERoot.ResMgr.GetBundleName(pName); if (string.IsNullOrEmpty(bundleName)) { return; } GOERoot.ResMgr.GetAsset(pName, (string prefabName, UnityEngine.Object obj) => { callback(lumdaName); string[] arr = lumdaName.Split('_'); if (arr.Length != 5) { Debug.Log("包名不符合规则 " + lumdaName); return; } //string chunkname = arr[2] + " " + arr[3]; string chunkname = arr[1] + " " + arr[2]; // @xl 查找Chunk 3的节点 GameObject chunkObj = FindGameObjectInChild(mTerrainBeh.gameObject, chunkname); GameObject go = obj as GameObject; if (go != null) { // @xl 查找LOD_3 // //GameObject lodObj = FindGameObjectInChild(chunkObj, arr[4] + "_" + arr[5]); GameObject lodObj = FindGameObjectInChild(chunkObj, arr[3] + "_" + arr[4]); go.transform.parent = lodObj.transform; go.transform.localEulerAngles = Vector3.zero; go.transform.localPosition = Vector3.zero; MeshRenderer[] mrs = go.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in mrs) { MeshLightmapSetting mls = mr.gameObject.GetComponent <MeshLightmapSetting>(); if (mls != null) { mls.LoadSettings(); } } BigTerrainXSetting sett = go.GetComponent <BigTerrainXSetting>(); if (sett != null) { sett.load = true; } mAllLoadObjs.Add(lumdaName, go); mTerrainBeh.ChunkVisableUpdate(true); } }, lp); } }
internal override void OnEnter() { base.OnEnter(); //Debug.Log("@临时稳删 scene random tile enter at frame = " + GOERoot.FrameNum); if (tileDatas.Count <= 0) { return; } GOEScene scene = this.Owner as GOEScene; if (tileDatas.Count > 0) { List <AStarTile> astarData = new List <AStarTile>(); for (int i = 0; i < tileDatas.Count; ++i) { TileData td = tileDatas[i]; GOERoot.ResMgrImp.GetAsset(td.aStarDataName, (string tempName, UnityEngine.Object tempObj) => { TextAsset tempGO = tempObj as TextAsset; astarData.Add(new AStarTile(td.row, td.col, tempGO.text)); if (astarData.Count == tileDatas.Count) { scene.GetComponent <DetourMgr>().LoadAStar(astarData); } }); } List <string> lightMaps = new List <string>(); for (int i = 0; i < tileDatas.Count; ++i) { TileData td = tileDatas[i]; if (!lightMaps.Contains(td.litMapName)) { lightMaps.Add(td.litMapName); } } //Debug.Log("@xulin enter random tile at frame = " + GOERoot.FrameNum); LightmapData[] lmds = new LightmapData[lightMaps.Count]; int lightMapCount = lightMaps.Count; for (int i = 0; i < lightMaps.Count; ++i) { string litmapName = lightMaps[i]; //Debug.Log("@临时稳删 get one litmap at frame = " + GOERoot.FrameNum); GOERoot.ResMgrImp.GetAsset(litmapName, (string tempName, UnityEngine.Object tempObj) => { --lightMapCount; Texture2D litMapTex = tempObj as Texture2D; LightmapData lmd = new LightmapData(); lmd.lightmapFar = litMapTex; int litIndex = lightMaps.IndexOf(tempName); lmds[litIndex] = lmd; //Debug.Log("@xulin loaded one litmap at frame = " + GOERoot.FrameNum); if (lightMapCount == 0) { //Debug.Log("@xulin loaded all litmaps at frame = " + GOERoot.FrameNum); LightmapSettings.lightmaps = lmds; int tileCount = tileDatas.Count; //Debug.Log("count " + tileCount); for (int j = 0; j < tileDatas.Count; ++j) { TileData td = tileDatas[j]; //Debug.Log("xulin --- get asset " + td.assetName); GOERoot.ResMgrImp.GetAsset(td.assetName, (string tempTileName, UnityEngine.Object tempTileObj) => { //Debug.Log("@xulin loaded one prefab at frame = " + GOERoot.FrameNum); //Debug.Log("xulin --- get asset loaded " + td.assetName); --tileCount; if (tileCount <= 0) { //Debug.Log("@xulin loaded all prefabs at frame = " + GOERoot.FrameNum); if (scene != null && scene.OnDynamicLoadedOk != null) { scene.OnDynamicLoadedOk(); //Debug.Log("OnDynamicLoadedOk "); } } GameObject tempTileGO = tempTileObj as GameObject; if (tempTileGO == null) { //Debug.Log("tempTileGO == null" + tempTileName); } Transform go = null; for (int xx = 0; xx < tempTileGO.transform.childCount; ++xx) { go = tempTileGO.transform.GetChild(xx); if (go != null && go.name.Contains("AStars")) { go.gameObject.SetActive(false); } } tempTileGO.transform.parent = scene.Terrain.transform; tempTileGO.transform.localPosition = (AStartDetour.ROL_COUNT - td.row) * AStartDetour.TILE_SIZE * Vector3.forward + td.col * AStartDetour.TILE_SIZE * Vector3.right; tempTileGO.transform.localEulerAngles = Vector3.zero; litIndex = lightMaps.IndexOf(td.litMapName); //Debug.Log(td.litMapName + " " + litIndex); MeshRenderer[] mrs = tempTileGO.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in mrs) { mr.lightmapIndex = litIndex; MeshLightmapSetting mls = mr.gameObject.GetComponent <MeshLightmapSetting>(); if (mls != null) { mls.lightmapIndex = litIndex; mls.LoadSettings(); } } }, LoadPriority.MostPrior); } } }, LoadPriority.MostPrior); } } }