void OnSceneGUI()
    {
        LSubTerrTempTrees tar = (LSubTerrTempTrees)target;

        foreach (KeyValuePair <GameObject, GlobalTreeInfo> kvp in tar.m_TempMap)
        {
            if (kvp.Key != null)
            {
                string content = "";
                content += "World Pos: " + kvp.Key.transform.position.ToString() + "\r\n";
                content += "Terrain Pos: (" + kvp.Value._treeInfo.m_pos.x.ToString("0.0000") + ", "
                           + kvp.Value._treeInfo.m_pos.y.ToString("0.0000") + ", "
                           + kvp.Value._treeInfo.m_pos.z.ToString("0.0000") + ")\r\n";
                content += "Terrain Key: " + kvp.Value._terrainIndex.ToString() + " ("
                           + LSubTerrUtils.IndexToPos(kvp.Value._terrainIndex).x.ToString() + ","
                           + LSubTerrUtils.IndexToPos(kvp.Value._terrainIndex).z.ToString() + ")\r\n";
                IntVector3 cell = new IntVector3(Mathf.FloorToInt(kvp.Key.transform.position.x) % LSubTerrConstant.Size,
                                                 Mathf.FloorToInt(kvp.Key.transform.position.y),
                                                 Mathf.FloorToInt(kvp.Key.transform.position.z) % LSubTerrConstant.Size);
                int key = LSubTerrUtils.TreePosToKey(cell);
                content += "Tree Cell: " + cell.ToString() + "\r\n";
                content += "Cell Key: " + key.ToString() + "\r\n";
                content += "Tree Proto: " + kvp.Value._treeInfo.m_protoTypeIdx.ToString() + "\r\n";
                content += "Tree Scale: (" + kvp.Value._treeInfo.m_widthScale.ToString("0.00") + ", "
                           + kvp.Value._treeInfo.m_heightScale.ToString("0.00") + ")\r\n";

                Handles.Label(kvp.Key.transform.position, content);
            }
        }
    }
Example #2
0
    public TreeInfo GetTreeInfoListAtPos(IntVector3 pos)
    {
        int      treeidx = LSubTerrUtils.TreePosToKey(pos);
        TreeInfo ti      = null;

        if (m_mapTrees.TryGetValue(treeidx, out ti))
        {
            return(ti);
        }
        return(null);
    }
Example #3
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);
    }
Example #4
0
    public void ApplyData(byte[] data, int len)
    {
        //_dataLen = len;
        if (len <= 0)
        {
            m_FinishedProcess = true;
            return;
        }

        TreeInfo tmpTi;

        #region READING_DATA
        //Profiler.BeginSample("AddTreeInfo");
        using (MemoryStream ms = new MemoryStream(data))
        {
            //IntVector3 tmpTreePos = IntVector3.Zero;
            BinaryReader br      = new BinaryReader(ms);
            int          mapSize = br.ReadInt32();
            for (int i = 0; i != mapSize; ++i)
            {
                br.ReadInt32();
                br.ReadInt32();
                br.ReadInt32();
                int _listSize = br.ReadInt32();
                for (int j = 0; j != _listSize; ++j)
                {
                    tmpTi                 = TreeInfo.GetTI();
                    tmpTi.m_clr.r         = br.ReadSingle();
                    tmpTi.m_clr.g         = br.ReadSingle();
                    tmpTi.m_clr.b         = br.ReadSingle();
                    tmpTi.m_clr.a         = br.ReadSingle();
                    tmpTi.m_heightScale   = br.ReadSingle();
                    tmpTi.m_lightMapClr.r = br.ReadSingle();
                    tmpTi.m_lightMapClr.g = br.ReadSingle();
                    tmpTi.m_lightMapClr.b = br.ReadSingle();
                    tmpTi.m_lightMapClr.a = br.ReadSingle();
                    tmpTi.m_pos.x         = br.ReadSingle();
                    tmpTi.m_pos.y         = br.ReadSingle();
                    tmpTi.m_pos.z         = br.ReadSingle();
                    tmpTi.m_protoTypeIdx  = br.ReadInt32();
                    tmpTi.m_widthScale    = br.ReadSingle();

                    AddTreeInfo(tmpTi);
                }
            }
            br.Close();
            ms.Close();
        }
        //Profiler.EndSample();

        // cutting deleted tree recorded in saved data
        //Profiler.BeginSample("CutRecordedTree");
        List <Vector3> lstDelPos;
        if (LSubTerrSL.m_mapDelPos.TryGetValue(Index, out lstDelPos))
        {
            int nDelPos = lstDelPos.Count;
            for (int i = 0; i < nDelPos; i++)
            {
                Vector3 delpos = lstDelPos [i];
                _tmpVec3.x = Mathf.FloorToInt(delpos.x);
                _tmpVec3.y = Mathf.FloorToInt(delpos.y);
                _tmpVec3.z = Mathf.FloorToInt(delpos.z);
                int tmpKey = LSubTerrUtils.TreePosToKey(_tmpVec3);
                if (m_mapTrees.TryGetValue(tmpKey, out tmpTi))
                {
                    tmpTi = tmpTi.FindTi(delpos);
                    if (tmpTi != null)
                    {
                        TreeInfo secondFoot = DeleteTreeInfo(tmpTi);
                        if (secondFoot != null)
                        {
                            DeleteTreeInfo(secondFoot);
                        }
                    }
                }
            }
        }
        //Profiler.EndSample();
        #endregion

        #region ASSIGN_LAYERS
        //Profiler.BeginSample("AssignLayer");
        List <LSubTerrLayerOption> layers       = LSubTerrainMgr.Instance.Layers;
        List <TreeInfo> []         layers_trees = new List <TreeInfo> [layers.Count];
        for (int l = layers.Count - 1; l >= 0; --l)
        {
            layers_trees[l] = new List <TreeInfo> ();
        }
        foreach (TreeInfo ti in m_listTrees)
        {
            float height = LSubTerrainMgr.Instance.GlobalPrototypeBounds[ti.m_protoTypeIdx].extents.y * 2F;
            for (int l = layers.Count - 1; l >= 0; --l)
            {
                // Trees in this layer
                if (layers[l].MinTreeHeight <= height && height < layers[l].MaxTreeHeight)
                {
                    layers_trees[l].Add(ti);
                    break;
                }
            }
        }
        for (int l = layers.Count - 1; l >= 0; --l)
        {
            LSubTerrainMgr.Instance.LayerCreators[l].AddTreeBatch(Index, layers_trees[l]);
        }
        //Profiler.EndSample();
        #endregion

        m_FinishedProcess = true;
    }
Example #5
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);
    }