Пример #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 TreeInfo DeleteTreeInfo(TreeInfo ti)         // return SecondFoot
    {
        _tmpVec3.x = Mathf.FloorToInt(ti.m_pos.x * LSubTerrConstant.SizeF);
        _tmpVec3.y = Mathf.FloorToInt(ti.m_pos.y * LSubTerrConstant.HeightF);
        _tmpVec3.z = Mathf.FloorToInt(ti.m_pos.z * LSubTerrConstant.SizeF);
        int tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3);

        TreeInfo.RemoveTiFromDict(m_mapTrees, tmpKey, ti);
        if (m_listTrees.Remove(ti))
        {
            TreeInfo.FreeTI(ti);
        }

        // Delete it in Mgr's m_map32Trees
        tmpKey = LSubTerrUtils.TreeWorldPosTo32Key(LSubTerrUtils.TreeTerrainPosToWorldPos(X, Z, ti.m_pos));
        List <TreeInfo> tmpTis;

        if (LSubTerrainMgr.Instance.m_map32Trees.TryGetValue(tmpKey, out tmpTis))
        {
            tmpTis.Remove(ti);
            if (tmpTis.Count == 0)
            {
                LSubTerrainMgr.Instance.m_map32Trees.Remove(tmpKey);
            }
        }

        // Check if it's 2 feet tree
        TreeInfo secondFoot;

        if (m_mapTwoFeetTrees.TryGetValue(ti, out secondFoot))
        {
            m_mapTwoFeetTrees.Remove(ti);
            m_mapTwoFeetTrees.Remove(secondFoot);               // remove 2nd foot to avoid from recursive
            return(secondFoot);
        }
        return(null);
    }
Пример #3
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);
        }
    }