Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
    public static void DeleteTree(GlobalTreeInfo treeinfo)
    {
        if (s_Instance == null || treeinfo == null)
        {
            return;
        }

        // Delete it in Mgr's m_map32Trees
        int             tmpKey = LSubTerrUtils.TreeWorldPosTo32Key(treeinfo.WorldPos);
        List <TreeInfo> tmpTis;

        if (s_Instance.m_map32Trees.TryGetValue(tmpKey, out tmpTis))
        {
            tmpTis.Remove(treeinfo._treeInfo);
            if (tmpTis.Count == 0)
            {
                s_Instance.m_map32Trees.Remove(tmpKey);
            }
        }

        // Delete it in Mgr's m_mapExistTempTrees and m_mapTempTreeInfos
        List <GameObject> existGos;

        if (s_Instance.m_mapExistTempTrees.TryGetValue(tmpKey, out existGos))
        {
            GameObject     gameobject_to_delete = null;
            GlobalTreeInfo gti;
            foreach (GameObject go in existGos)
            {
                if (s_Instance.m_mapTempTreeInfos.TryGetValue(go, out gti))
                {
                    if (gti._treeInfo == treeinfo._treeInfo)
                    {
                        // Found it!
                        gameobject_to_delete = go;

                        if (OnTreeColliderDestroy != null)
                        {
                            OnTreeColliderDestroy(gameobject_to_delete);
                        }

                        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)
            {
                existGos.Remove(gameobject_to_delete);
            }
        }

        // Delete it in Node's m_mapTrees and m_listTrees
        TreeInfo secondFoot = null;             // For two feet trees

        if (Node(treeinfo._terrainIndex) != null)
        {
            secondFoot = Node(treeinfo._terrainIndex).DeleteTreeInfo(treeinfo._treeInfo);
        }
        else
        {
            Debug.LogError("Can not find the subterrain node when delete tree");
        }

        // Delete it in layers
        foreach (LSubTerrCreator creator in s_Instance.LayerCreators)
        {
            if (creator.m_allTreesInLayer.TryGetValue(treeinfo._terrainIndex, out tmpTis))
            {
                tmpTis.Remove(treeinfo._treeInfo);
            }
            else
            {
                Debug.LogError("Can not find the key in layer's m_allTreesInLayer when delete tree");
            }
        }

        LSubTerrSL.AddDeletedTree(treeinfo._terrainIndex, treeinfo._treeInfo);

        // Delete 2nd foot ?? Is this really necessary??
        if (secondFoot != null)
        {
            GlobalTreeInfo gti_2ndfoot = new GlobalTreeInfo(treeinfo._terrainIndex, secondFoot);
            DeleteTree(gti_2ndfoot);
        }
    }
Ejemplo n.º 3
0
    private TreeInfo AddTreeInfo(TreeInfo ti)
    {
        // Tree place holder works
        if (ti.m_protoTypeIdx == LSubTerrainMgr.TreePlaceHolderPrototypeIndex ||
            ti.m_pos.x < 0.00001 || ti.m_pos.z < 0.00001 || ti.m_pos.x > 0.99999 || ti.m_pos.z > 0.99999)               // Avoid bugs
        {
            TreeInfo.FreeTI(ti);
            return(null);
        }

        // Add to tree map
        _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 tmpTi;

        if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
        {
            tmpTi.AttachTi(ti);
        }
        else
        {
            m_mapTrees.Add(tmpKey, ti);
        }

        // Add to tree list
        m_listTrees.Add(ti);
        // Add to 32 tree map
        if (LSubTerrainMgr.HasCollider(ti.m_protoTypeIdx) || LSubTerrainMgr.HasLight(ti.m_protoTypeIdx))
        {
            tmpKey = LSubTerrUtils.TreeWorldPosTo32Key(LSubTerrUtils.TreeTerrainPosToWorldPos(X, Z, ti.m_pos));
            List <TreeInfo> tmpTis;
            if (!LSubTerrainMgr.Instance.m_map32Trees.TryGetValue(tmpKey, out tmpTis))
            {
                tmpTis = new List <TreeInfo>();
                LSubTerrainMgr.Instance.m_map32Trees.Add(tmpKey, tmpTis);
            }
            tmpTis.Add(ti);
        }

        // Tree place holder works
        LTreePlaceHolderInfo tphinfo = LSubTerrainMgr.GetTreePlaceHolderInfo(ti.m_protoTypeIdx);

        if (tphinfo != null)
        {
            TreeInfo tph = TreeInfo.GetTI();
            tph.m_clr         = Color.white;
            tph.m_heightScale = tphinfo.m_HeightScale * ti.m_heightScale;
            tph.m_lightMapClr = Color.white;
            Vector3 tphoffset = tphinfo.TerrOffset;
            tphoffset.x       *= ti.m_widthScale;
            tphoffset.y       *= ti.m_heightScale;
            tphoffset.z       *= ti.m_widthScale;
            tph.m_pos          = ti.m_pos + tphoffset;
            tph.m_protoTypeIdx = LSubTerrainMgr.TreePlaceHolderPrototypeIndex;
            tph.m_widthScale   = tphinfo.m_WidthScale * ti.m_widthScale;

            // Add to tree map
            _tmpVec3.x = Mathf.FloorToInt(tph.m_pos.x * LSubTerrConstant.SizeF);
            _tmpVec3.y = Mathf.FloorToInt(tph.m_pos.y * LSubTerrConstant.HeightF);
            _tmpVec3.z = Mathf.FloorToInt(tph.m_pos.z * LSubTerrConstant.SizeF);
            tmpKey     = LSubTerrUtils.TreePosToKey(_tmpVec3);
            if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
            {
                tmpTi.AttachTi(tph);
            }
            else
            {
                m_mapTrees.Add(tmpKey, tph);
            }

            // Add to tree list
            m_listTrees.Add(tph);
            m_mapTwoFeetTrees.Add(tph, ti);
            m_mapTwoFeetTrees.Add(ti, tph);
        }
        return(ti);
    }