public static void AddDeletedTree(Vector3 pos) { if (m_mapDelPos == null) { Debug.LogError("LSubTerrSL haven't initialized!"); return; } int index = LSubTerrUtils.WorldPosToIndex(pos); pos.x = pos.x - Mathf.FloorToInt(pos.x / LSubTerrConstant.SizeF) * LSubTerrConstant.SizeF; pos.z = pos.z - Mathf.FloorToInt(pos.z / LSubTerrConstant.SizeF) * LSubTerrConstant.SizeF; if (m_mapDelPos.ContainsKey(index)) { if (!m_mapDelPos[index].Contains(pos)) { m_mapDelPos[index].Add(pos); } } else { List <Vector3> del_list = new List <Vector3> (); del_list.Add(pos); m_mapDelPos.Add(index, del_list); } }
public static List <GlobalTreeInfo> Picking(Vector3 position, Vector3 direction, bool includeTrees = false, float distance = 1.5f, float angle = 45f) { if (s_Instance == null) { return(picklist); } ClearTreeinfo(); distance = Mathf.Clamp(distance, 0.1f, 2f); int ix = Mathf.FloorToInt(position.x); int iy = Mathf.FloorToInt(position.y); int iz = Mathf.FloorToInt(position.z); TreeInfo tmpTi; for (int x = ix - 2; x <= ix + 2; ++x) { for (int y = iy - 2; y <= iy + 2; ++y) { for (int z = iz - 2; z <= iz + 2; ++z) { int idx = LSubTerrUtils.WorldPosToIndex(new Vector3(x + .5F, 0, z + .5F)); if (Node(idx) != null) { temp.x = x % LSubTerrConstant.Size; temp.y = y; temp.z = z % LSubTerrConstant.Size; tmpTi = Node(idx).GetTreeInfoListAtPos(temp); while (tmpTi != null) { TreeInfo ti = tmpTi; tmpTi = tmpTi.Next; if (HasCollider(ti.m_protoTypeIdx) && !includeTrees) { continue; } Vector3 treepos = LSubTerrUtils.TreeTerrainPosToWorldPos(x >> LSubTerrConstant.SizeShift, z >> LSubTerrConstant.SizeShift, ti.m_pos); Vector3 diff = treepos - position; diff.y = 0; if (diff.magnitude > distance) { continue; } direction.y = 0; if (Vector3.Angle(diff, direction) < angle) { GlobalTreeInfo gti = GetGlobalTreeInfo(); gti._terrainIndex = idx; gti._treeInfo = ti; picklist.Add(gti); } } } } } } return(picklist); }
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; } } } } }
public static List <GlobalTreeInfo> Picking(IntVector3 position, bool includeTrees) { if (s_Instance == null) { return(picklist); } ClearTreeinfo(); int x = position.x; int y = position.y; int z = position.z; int idx = LSubTerrUtils.WorldPosToIndex(new Vector3(x + .5F, 0, z + .5F)); TreeInfo tmpTi; if (Node(idx) != null) { int rx = x % LSubTerrConstant.Size; int ry = y; int rz = z % LSubTerrConstant.Size; tmpTi = Node(idx).GetTreeInfoListAtPos(new IntVector3(rx, ry, rz)); while (tmpTi != null) { TreeInfo ti = tmpTi; tmpTi = tmpTi.Next; if (HasCollider(ti.m_protoTypeIdx) && !includeTrees) { continue; } GlobalTreeInfo gti = GetGlobalTreeInfo(); gti._terrainIndex = idx; gti._treeInfo = ti; picklist.Add(gti); } } return(picklist); }