private IEnumerator RefreshRegion() { bProcessing = true; #region PREPARE_DATA yield return(0); m_mapPrototype.Clear(); m_listPrototype.Clear(); for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData) { yield return(0); } if (m_allTreesInLayer.ContainsKey(idx)) { List <TreeInfo> trees_in_zone = m_allTreesInLayer[idx]; foreach (TreeInfo ti in trees_in_zone) { // New prototype ? if (!m_mapPrototype.ContainsKey(ti.m_protoTypeIdx)) { int next_index = m_listPrototype.Count; m_mapPrototype.Add(ti.m_protoTypeIdx, next_index); m_listPrototype.Add(ti.m_protoTypeIdx); } } } } yield return(0); } TreePrototype [] FinalPrototypeArray = new TreePrototype [m_listPrototype.Count]; for (int i = 0; i < m_listPrototype.Count; ++i) { FinalPrototypeArray[i] = new TreePrototype(); FinalPrototypeArray[i].bendFactor = LSubTerrainMgr.Instance.GlobalPrototypeBendFactorList[m_listPrototype[i]]; FinalPrototypeArray[i].prefab = LSubTerrainMgr.Instance.GlobalPrototypePrefabList[m_listPrototype[i]]; } // Calc Count int tree_count = 0; for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); if (m_allTreesInLayer.ContainsKey(idx)) { tree_count += m_allTreesInLayer[idx].Count; } } } TreeInstance [] FinalTreeInstanceArray = new TreeInstance [tree_count]; int t = 0; for (int x = xIndex - 1; x <= xIndex + 1; ++x) { for (int z = zIndex - 1; z <= zIndex + 1; ++z) { int idx = LSubTerrUtils.PosToIndex(x, z); if (m_allTreesInLayer.ContainsKey(idx)) { List <TreeInfo> trees_in_zone = m_allTreesInLayer[idx]; foreach (TreeInfo ti in trees_in_zone) { if (t < FinalTreeInstanceArray.Length) { Vector3 new_pos = ti.m_pos; new_pos += new Vector3(x - xIndex + 1, 0, z - zIndex + 1); new_pos.x /= 3; new_pos.z /= 3; FinalTreeInstanceArray[t].color = ti.m_clr; FinalTreeInstanceArray[t].heightScale = ti.m_heightScale; FinalTreeInstanceArray[t].widthScale = ti.m_widthScale; FinalTreeInstanceArray[t].lightmapColor = ti.m_lightMapClr; FinalTreeInstanceArray[t].position = new_pos; if (!m_mapPrototype.ContainsKey(ti.m_protoTypeIdx)) { FinalTreeInstanceArray[t].heightScale = 0; FinalTreeInstanceArray[t].widthScale = 0; FinalTreeInstanceArray[t].position = Vector3.zero; FinalTreeInstanceArray[t].prototypeIndex = 0; continue; } FinalTreeInstanceArray[t].prototypeIndex = m_mapPrototype[ti.m_protoTypeIdx]; } t++; } } } } yield return(0); #endregion #region ASSIGN_DATA gameObject.SetActive(false); m_TerrData.treeInstances = new TreeInstance[0]; m_TerrData.treePrototypes = FinalPrototypeArray; m_TerrData.treeInstances = FinalTreeInstanceArray; if (Application.isEditor) { _TreePrototypeCount = m_TerrData.treePrototypes.Length; _TreeInstanceCount = m_TerrData.treeInstances.Length; } transform.position = LSubTerrUtils.PosToWorldPos(new IntVector3(xIndex - 1, 0, zIndex - 1)); gameObject.SetActive(true); #endregion bProcessing = false; if (OnRefreshRegion != null) { OnRefreshRegion(); } StartCoroutine("RefreshBillboards"); }