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);
            }
        }
    }
    public static void AddTree(Vector3 wpos, int prototype, float width_scale = 1, float height_scale = 1)
    {
        if (s_Instance == null)
        {
            return;
        }

        int        terIdx  = LSubTerrUtils.WorldPosToIndex(wpos);
        IntVector3 terrpos = LSubTerrUtils.IndexToPos(terIdx);
        IntVector3 campos  = _iCurCamPos;

        if (Mathf.Abs(terrpos.x - campos.x) > 1)
        {
            return;
        }
        if (Mathf.Abs(terrpos.z - campos.z) > 1)
        {
            return;
        }

        if (s_Instance.m_Nodes.ContainsKey(terIdx))
        {
            LSubTerrain TargetNode = Node(terIdx);
            if (TargetNode == null)
            {
                return;
            }

            // Read TreeInfo
            TreeInfo ti = TargetNode.AddTreeInfo(wpos, prototype, width_scale, height_scale);
            if (ti != null)
            {
                float height = s_Instance.GlobalPrototypeBounds[ti.m_protoTypeIdx].extents.y * 2F;
                for (int l = s_Instance.Layers.Count - 1; l >= 0; --l)
                {
                    // Trees in this layer
                    if (s_Instance.Layers[l].MinTreeHeight <= height && height < s_Instance.Layers[l].MaxTreeHeight)
                    {
                        s_Instance.LayerCreators[l].m_allTreesInLayer[terIdx].Add(ti);
                        break;
                    }
                }
            }
        }
    }
Beispiel #3
0
    private IEnumerator RefreshBillboards()
    {
        // Check if the highest layer
        if (LSubTerrainMgr.Instance.Layers[LayerIndex].MaxTreeHeight < 50)
        {
            bBillboardProcessing = false;
            yield break;
        }

        bBillboardProcessing = true;

        // Delete Far BTerrains
        List <int> del_list = new List <int> ();
        long       tempIndexX, tempIndexZ;

        foreach (KeyValuePair <int, BillboardTerrain> kvp in m_BillboardTerrains)
        {
            IntVector3 pos = LSubTerrUtils.IndexToPos(kvp.Key);
            tempIndexX = pos.x - xIndex;
            tempIndexZ = pos.z - zIndex;
            //lz-2017.07.27 差值如果是Int.MinValue用Mathf.Abs会报错: OverflowException: Value is too small
            if (System.Math.Abs(tempIndexX) > 3 || System.Math.Abs(tempIndexZ) > 3 ||
                System.Math.Abs(tempIndexX) <= 1 && System.Math.Abs(tempIndexZ) <= 1)
            {
                kvp.Value.Reset();
                GameObject.Destroy(kvp.Value.gameObject);
                del_list.Add(kvp.Key);
            }
        }
        foreach (int del in del_list)
        {
            m_BillboardTerrains.Remove(del);
        }

        // Add new BTerrains
        for (int x = Last_x - 1; x <= Last_x + 1; ++x)
        {
            for (int z = Last_z - 1; z <= Last_z + 1; ++z)
            {
                if (x >= xIndex - 1 && x <= xIndex + 1 &&
                    z >= zIndex - 1 && z <= zIndex + 1)
                {
                    continue;
                }
                if (x > xIndex + 3 || x < xIndex - 3 ||
                    z > zIndex + 3 || z < zIndex - 3)
                {
                    continue;
                }
                int idx = LSubTerrUtils.PosToIndex(x, z);
                while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData)
                {
                    yield return(0);
                }
                if (m_allTreesInLayer.ContainsKey(idx))
                {
                    CreateOneBTerrain(x, z);
                }
            }
        }
        yield return(0);

        // Add new BTerrains
        for (int x = xIndex - 3; x <= xIndex + 3; ++x)
        {
            for (int z = zIndex - 3; z <= zIndex + 3; ++z)
            {
                if (x >= xIndex - 1 && x <= xIndex + 1 &&
                    z >= zIndex - 1 && z <= zIndex + 1)
                {
                    continue;
                }
                if (x >= Last_x - 1 && x <= Last_x + 1 &&
                    z >= Last_z - 1 && z <= Last_z + 1)
                {
                    continue;
                }
                int idx = LSubTerrUtils.PosToIndex(x, z);
                while (!m_allTreesInLayer.ContainsKey(idx) && LSubTerrainMgr.Node(idx) != null && LSubTerrainMgr.Node(idx).HasData)
                {
                    yield return(0);
                }
                if (m_allTreesInLayer.ContainsKey(idx))
                {
                    CreateOneBTerrain(x, z);
                }
            }
            yield return(0);
        }
        Last_x = xIndex;
        Last_z = zIndex;
        bBillboardProcessing = false;
    }