Пример #1
0
    public void DelTree(TreeInfo ti)
    {
        int tmpKey = RSubTerrUtils.TreeWorldPosToChunkIndex(ti.m_pos, m_Index);

        if (!TreeInfo.RemoveTiFromDict(m_mapTrees, tmpKey, ti))
        {
            Debug.LogError("The tree to del dosen't exist");
            return;
        }
        if (!m_listTrees.Remove(ti))
        {
            Debug.LogError("The tree to del dosen't exist");
        }
    }
Пример #2
0
    public void AddTree(TreeInfo ti)
    {
        m_listTrees.Add(ti);
        int      tmpKey = RSubTerrUtils.TreeWorldPosToChunkIndex(ti.m_pos, m_Index);
        TreeInfo tmpTi;

        if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
        {
            tmpTi.AttachTi(ti);
        }
        else
        {
            m_mapTrees.Add(tmpKey, ti);
        }
    }
Пример #3
0
    public List <TreeInfo> TreesAtPos(IntVector3 pos)
    {
        treelist.Clear();
        int      X = Mathf.FloorToInt(pos.x / RSubTerrConstant.ChunkSizeF);
        int      Z = Mathf.FloorToInt(pos.z / RSubTerrConstant.ChunkSizeF);
        TreeInfo tmpTi;

        for (int x = X - 1; x <= X + 1; ++x)
        {
            for (int z = Z - 1; z <= Z + 1; ++z)
            {
                int idx     = RSubTerrUtils.ChunkPosToIndex(x, z);
                int treeidx = RSubTerrUtils.TreeWorldPosToChunkIndex(pos.ToVector3(), idx);
                if (m_Chunks.ContainsKey(idx) && m_Chunks[idx].m_mapTrees.TryGetValue(treeidx, out tmpTi))
                {
                    TreeInfo.AddTiToList(treelist, tmpTi);
                }
            }
        }
        return(treelist);
    }
Пример #4
0
    public static void DeleteTree(TreeInfo treeinfo)
    {
        if (s_Instance == null)
        {
            return;
        }
        if (treeinfo == null)
        {
            return;
        }

        // For two feet trees
        TreeInfo SecondFoot = null;

        // Delete it in Mgr's m_map32Trees
        int idx32 = RSubTerrUtils.Tree32PosTo32Index(Mathf.FloorToInt(treeinfo.m_pos.x / 32), Mathf.FloorToInt(treeinfo.m_pos.z / 32));

        if (s_Instance.m_map32Trees.ContainsKey(idx32))
        {
            s_Instance.m_map32Trees[idx32].Remove(treeinfo);
            if (s_Instance.m_map32Trees[idx32].Count == 0)
            {
                s_Instance.m_map32Trees.Remove(idx32);
            }
        }

        // Delete it in Mgr's m_mapExistTempTrees and m_mapTempTreeInfos
        if (s_Instance.m_mapExistTempTrees.ContainsKey(idx32))
        {
            GameObject gameobject_to_delete = null;
            foreach (GameObject go in s_Instance.m_mapExistTempTrees[idx32])
            {
                if (s_Instance.m_mapTempTreeInfos.ContainsKey(go))
                {
                    if (s_Instance.m_mapTempTreeInfos[go] == treeinfo)
                    {
                        // Found it!
                        gameobject_to_delete = go;
                        GameObject.Destroy(go);
                        s_Instance.m_mapTempTreeInfos.Remove(go);
                    }
                }
                else
                {
                    Debug.LogError("Can not find the GameObject key in m_mapTempTreeInfos when delete tree");
                }
            }
            if (gameobject_to_delete != null)
            {
                s_Instance.m_mapExistTempTrees[idx32].Remove(gameobject_to_delete);
            }
        }

        // Delete it in Node's m_mapTrees and m_listTrees
        int X         = Mathf.FloorToInt(treeinfo.m_pos.x / RSubTerrConstant.ChunkSizeF);
        int Z         = Mathf.FloorToInt(treeinfo.m_pos.z / RSubTerrConstant.ChunkSizeF);
        int del_count = 0;

        for (int x = X - 1; x <= X + 1; ++x)
        {
            for (int z = Z - 1; z <= Z + 1; ++z)
            {
                int idx     = RSubTerrUtils.ChunkPosToIndex(x, z);
                int treeidx = RSubTerrUtils.TreeWorldPosToChunkIndex(treeinfo.m_pos, idx);
                if (s_Instance.m_Chunks.ContainsKey(idx))
                {
                    RSubTerrainChunk chunk = s_Instance.m_Chunks[idx];
                    if (chunk.TreeList.Remove(treeinfo))
                    {
                        del_count++;
                    }
                    if (TreeInfo.RemoveTiFromDict(chunk.m_mapTrees, treeidx, treeinfo))
                    {
                        del_count++;
                    }
                }
            }
        }
        if (del_count != 2)
        {
            Debug.LogError("RSubTerrain Remove: count doesn't match");
        }

        // Delete it in layers
        foreach (RSubTerrCreator creator in s_Instance.LayerCreators)
        {
            creator.m_allTreesInLayer.Remove(treeinfo);
        }

        RSubTerrSL.AddDeletedTree(treeinfo);

        // Delete 2nd foot
        if (SecondFoot != null)
        {
            DeleteTree(SecondFoot);
        }
    }