示例#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);
    }
示例#2
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);
    }