public void SetActive(TileIndex rTileIndex, bool bActive) { SceneTileWrapper rSceneTileWrapper = this.Get(rTileIndex); if (rSceneTileWrapper != null) { rSceneTileWrapper.SetActive(bActive); } }
public void Release(TileIndex rTileIndex) { if (mBlockBuffers == null) { return; } SceneTileWrapper rSceneTileWrapper = mBlockBuffers.Find((rItem) => { return(rItem.curIndex.Equals(rTileIndex)); }); if (rSceneTileWrapper != null) { rSceneTileWrapper.Release(); Debug.Log("删除块: " + rTileIndex.ToString()); mBlockBuffers.Remove(rSceneTileWrapper); } }
/// <summary> /// 创建一个SceneTileWrapper /// </summary> public SceneTileWrapper Alloc(TileIndex rTileIndex, SceneTile rSceneTile, TerrainData rTerrainData) { Debug.Log("加载块: " + rTileIndex.ToString()); var rSceneTileWrapper = new SceneTileWrapper(); rSceneTileWrapper.curIndex = new TileIndex(rTileIndex); if (rSceneTile != null && rTerrainData != null) { rSceneTileWrapper.tileGo = Terrain.CreateTerrainGameObject(rTerrainData); rSceneTileWrapper.tileGo.name = string.Format("tile_{0}_{1}", rTileIndex.Row, rTileIndex.Col); rSceneTileWrapper.tileGo.transform.parent = mMultiSceneRootGo.transform; rSceneTileWrapper.tileGo.transform.position = new Vector3(rSceneTile.Offset.x, 0, rSceneTile.Offset.y); rSceneTileWrapper.sceneTile = rSceneTile; } mBlockBuffers.Add(rSceneTileWrapper); return(rSceneTileWrapper); }
/// <summary> /// 加载单个场景块 /// </summary> public IEnumerator HandleRequest(SceneTileRequest rSceneTileRequest) { TileIndex rTileIndex = rSceneTileRequest.CurIndex; SceneTileWrapper rSceneTileWrapper = mSceneBlockBuffer.Get(rTileIndex); if (rSceneTileWrapper != null) { rSceneTileRequest.SceneTileWrapper = rSceneTileWrapper; rSceneTileWrapper.SetActive(true); rSceneTileRequest.IsRunning = false; rSceneTileRequest.IsCompleted = true; mSceneBlockBuffer.SetActive(rTileIndex, true); yield break; } string rSceneTileConfigPath = string.Format("{0}/tile_{1}_{2}_config", MultiSceneManager.CurrentTestSceneName, rTileIndex.Row, rTileIndex.Col); string rSceneTilePath = string.Format("{0}/tile_{1}_{2}", MultiSceneManager.CurrentTestSceneName, rTileIndex.Row, rTileIndex.Col); ResourceRequest rRequest = Resources.LoadAsync <SceneTile>(rSceneTileConfigPath); yield return(rRequest); SceneTile rSceneTile = rRequest.asset as SceneTile; ResourceRequest rDataRequest = Resources.LoadAsync <TerrainData>(rSceneTilePath); yield return(rDataRequest); TerrainData rTerrainData = rDataRequest.asset as TerrainData; rSceneTileWrapper = mSceneBlockBuffer.Alloc(rTileIndex, rSceneTile, rTerrainData); rSceneTileRequest.SceneTileWrapper = rSceneTileWrapper; rSceneTileRequest.IsRunning = false; rSceneTileRequest.IsCompleted = true; }