/// 缓存分块 private void CacheInstGo(ref SceneConfig.CPositionSetting currentPos) { if (!_LoadedPoints.Contains(currentPos._BlockName)) { return; } GameObject _cacheGo; if (_ObjectCacheDic.TryGetValue(currentPos._BlockName, out _cacheGo)) { if (null != _cacheGo && _cacheGo.activeSelf) { //_cacheGo.SetActive(false); _cacheGo.transform.transform.localPosition = FAR_POS; } } else if (_ObjectCacheDic.Count < MAX_CACHE_OBJ_COUNT) { _cacheGo = FindRegObj(currentPos._BlockName); if (null != _cacheGo) { //_cacheGo.SetActive(false); _cacheGo.transform.transform.localPosition = FAR_POS; _ObjectCacheDic.Add(currentPos._BlockName, _cacheGo); } } }
/// 销毁分块 private void DestroyInstGo(ref SceneConfig.CPositionSetting currentPos) { if (!_LoadedPoints.Contains(currentPos._BlockName)) { return; } var _cacheGo = FindRegObj(currentPos._BlockName); if (null == _cacheGo) { return; } _LoadedObjectDic.Remove(currentPos._BlockName); RemoveFromSpecialObjectList(_cacheGo); ScenesAnimationManager.Instance.RemoveAnimationObj(currentPos._BlockName); _ObjectCacheDic.Remove(currentPos._BlockName); GameObject.Destroy(_cacheGo); _LoadedPoints.Remove(currentPos._BlockName); for (int i = 0; i < currentPos._LightIndexArray.Length; i++) { int v; if (_LightmapIdx2RefCountDic.TryGetValue(currentPos._LightIndexArray[i], out v)) { if (v > 0) { _LightmapIdx2RefCountDic[currentPos._LightIndexArray[i]] = v - 1; _IsLightmapsUpdated = true; } else { HobaDebuger.LogFormat("尝试销毁一张不存在的贴图,分块名称为 {0}", currentPos._BlockName); } } else { HobaDebuger.LogFormat("索引不正确,名称为 {0}", currentPos._BlockName); continue; } } }
/// 加载分块 private void LoadInstGo(ref SceneConfig.CPositionSetting currentPos, Vector3 position) { int filterRegionIndex = ScenesRegionManager.Instance.CurBlockReigionID; var isContains = IsContainsKey(currentPos._RegionArray, filterRegionIndex); if (!isContains) { return; } /// 同名文件不重复加载 if (_LoadedPoints.Contains(currentPos._BlockName)) { GameObject cacheGo; if (_ObjectCacheDic.TryGetValue(currentPos._BlockName, out cacheGo)) { cacheGo.transform.transform.localPosition = currentPos._BlockPosition; AddToSpecialObjectList(cacheGo); } } else { for (int i = 0; i < currentPos._LightIndexArray.Length; i++) { int val = 0; if (_LightmapIdx2RefCountDic.TryGetValue(currentPos._LightIndexArray[i], out val)) { _LightmapIdx2RefCountDic[currentPos._LightIndexArray[i]] = val + 1; _IsLightmapsUpdated = true; } else { HobaDebuger.LogFormat("光照贴图索引不正确,最大索引{0},当前索引为{1},资源{2}", _LightmapIdx2RefCountDic.Count - 1, currentPos._LightIndexArray[i], currentPos._BlockName); continue; } } _LoadedPoints.Add(currentPos._BlockName); LoadBlockFromBundle(currentPos._BlockName, currentPos._EffectiveType); } }