void InitWorldRect() { Vector2 worldCenter = BuildingGeoList.GetRerenceLeftBottomInMeters(); // worldRect center,墨卡托坐标 float tileSize = BuildingGeoList.tileSizeInMeters(); float worldRectX = worldCenter.x - tileSize * tileNum / 2; float worldRectY = worldCenter.y - tileSize * tileNum / 2; // 左上角 worldRect = new Rect(worldRectX, worldRectY, tileSize * tileNum, tileSize * tileNum); }
private void InitQuadTree() { InitWorldRect(); terrainRoot = new GameObject("terrain-root"); terrainRoot.transform.position = new Vector3(0, 0, 0); terrainRoot.transform.localScale = Vector3.one * BuildingGeoList.GetWorldScaleFactor(); qTree = new CityQuadTree(worldRect, 0, null); qTree.InitSearchTarget(new Rect(BuildingGeoList.GetRerenceRect().x, BuildingGeoList.GetRerenceRect().y, BuildingGeoList.GetRerenceRect().width + 100, BuildingGeoList.GetRerenceRect().height - 100), terrainRoot, planeMeshPrefab); }
private void CreateMesh(GameObject root, GameObject planeMeshPrefab) { Vector2 referenceO = BuildingGeoList.GetReferenceCenterInMeters(); Vector3 position = new Vector3(this.nodeCenter.x - referenceO.x, 0, this.nodeCenter.y - referenceO.y); //GameObject leafPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); GameObject leafPlane = GameObject.Instantiate(planeMeshPrefab); leafPlane.name = "depth-" + this.currentDepth; leafPlane.transform.position = position; leafPlane.transform.localScale = (new Vector3(1, 0, 1)) * this.nodeSize * 0.1f; // 墨卡托坐标. 一个plan primitive本身的unity size是10*10 leafPlane.transform.SetParent(root.transform); leafPlane.AddComponent <MeshCollider>().sharedMesh = leafPlane.GetComponent <MeshFilter>().mesh; }
public void UpdateTerrain(Rect newRect) { //Debug.Log("terrain controller: update terrain"); qTree.UpdateSearchTarget(newRect, terrainRoot, planeMeshPrefab); terrainRoot.transform.localScale = Vector3.one * BuildingGeoList.GetWorldScaleFactor(); // ? }