public void Release() { _dataLen = 0; if (m_mapTrees != null) { m_mapTrees.Clear(); } if (m_listTrees != null) { TreeInfo.FreeTIs(m_listTrees); m_listTrees.Clear(); } if (LSubTerrainMgr.Instance != null) { for (int i = 0; i < LSubTerrainMgr.Instance.Layers.Count; ++i) { LSubTerrainMgr.Instance.LayerCreators[i].DelTreeBatch(Index); } for (int i = X * 8; i < X * 8 + 8; i++) { for (int j = Z * 8; j < Z * 8 + 8; j++) { int tmpKey = LSubTerrUtils.Tree32PosTo32Key(i, j); LSubTerrainMgr.Instance.m_map32Trees.Remove(tmpKey); } } } }
private void RefreshTreeGos() { int x32 = Mathf.FloorToInt(PlayerTransform.position.x / 32); int z32 = Mathf.FloorToInt(PlayerTransform.position.z / 32); List <TreeInfo> tmpTis; for (int x = x32 - 2; x <= x32 + 2; ++x) { for (int z = z32 - 2; z <= z32 + 2; ++z) { int idx = LSubTerrUtils.Tree32PosTo32Key(x, z); if (!m_mapExistTempTrees.ContainsKey(idx) && m_map32Trees.TryGetValue(idx, out tmpTis)) { List <GameObject> tmptreelist = new List <GameObject> (); int nTis = tmpTis.Count; for (int i = 0; i < nTis; i++) { TreeInfo ti = tmpTis[i]; if (GlobalPrototypeColliders[ti.m_protoTypeIdx] == null) { continue; } GameObject temptree_go = GameObject.Instantiate(GlobalPrototypeColliders[ti.m_protoTypeIdx], LSubTerrUtils.TreeTerrainPosToWorldPos(x / 8, z / 8, ti.m_pos), Quaternion.identity) as GameObject; temptree_go.transform.parent = TempTreesGroup.transform; temptree_go.transform.localScale = new Vector3(ti.m_widthScale, ti.m_heightScale, ti.m_widthScale); temptree_go.name = temptree_go.transform.position.ToString() + " Type " + ti.m_protoTypeIdx; temptree_go.layer = NearTreeLayer; temptree_go.SetActive(true); if (OnTreeColliderCreated != null) { OnTreeColliderCreated(temptree_go); } tmptreelist.Add(temptree_go); m_mapTempTreeInfos.Add(temptree_go, new GlobalTreeInfo(x / 8, z / 8, ti)); } m_mapExistTempTrees.Add(idx, tmptreelist); } } } List <int> keys_to_del = new List <int> (); foreach (KeyValuePair <int, List <GameObject> > kvp in m_mapExistTempTrees) { IntVector3 pos32 = LSubTerrUtils.Tree32KeyTo32Pos(kvp.Key); if (Mathf.Abs(pos32.x - x32) > 2 || Mathf.Abs(pos32.z - z32) > 2) { keys_to_del.Add(kvp.Key); foreach (GameObject go in kvp.Value) { if (OnTreeColliderDestroy != null) { OnTreeColliderDestroy(go); } m_mapTempTreeInfos.Remove(go); GameObject.Destroy(go); } } } foreach (int k in keys_to_del) { m_mapExistTempTrees.Remove(k); } }