private void DrawOutline() { foreach (KeyValuePair <int, List <GameObject> > kvp in m_mapExistTempTrees) { IntVector3 pos = LSubTerrUtils.Tree32KeyTo32Pos(kvp.Key); int x = pos.x; int z = pos.z; Debug.DrawLine(new Vector3(x * 32, PlayerTransform.position.y, z * 32), new Vector3(x * 32 + 32, PlayerTransform.position.y, z * 32), Color.yellow); Debug.DrawLine(new Vector3(x * 32 + 32, PlayerTransform.position.y, z * 32), new Vector3(x * 32 + 32, PlayerTransform.position.y, z * 32 + 32), Color.yellow); Debug.DrawLine(new Vector3(x * 32 + 32, PlayerTransform.position.y, z * 32 + 32), new Vector3(x * 32, PlayerTransform.position.y, z * 32 + 32), Color.yellow); Debug.DrawLine(new Vector3(x * 32, PlayerTransform.position.y, z * 32 + 32), new Vector3(x * 32, PlayerTransform.position.y, z * 32), Color.yellow); } }
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); } }