hi there
i´m loading my level at runtime. Each level is made out of single Tiles/Blocks. The maximum Mapsize is 320320 tiles, each on the same height, and each tile has 2 Polygons and the same 512512 texture + Normalmap.
I´ve 1 draw_call, no update method.
This is my maploading code:
using UnityEngine;
using System.Collections;
public class Map_Loader : MonoBehaviour {
public int scrollspeed = 10;
public int zoomspeed = 20;
public int rotatespeed = 5;
public int mapsize_x = 1;
public int mapsize_y = 1;
public Vector3 mouse3d;
public Vector2 mouse3dtile;
public GameObject TilemapHolder;
public GameObject kamera;
public GameObject kamera_view;
public Camera kamera_view_cam;
public GameObject BasicMapPrefab;
public GameObject BasicBlockForSize;
public int _____________________;
public GameObject DirtBlock;
public GameObject DirtStraight;
public GameObject DirtInnerCurver;
public GameObject DirtOuterCurver;
public GameObject DirtRoof;
public GameObject DirtGold;
public GameObject DirtDitrima;
public GameObject DirtFloor;
public int prefabInterneBlockzahl = 1;
public int ____________________;
//public BlockStats[][] tilemap;
BlockStats scriptholder;
public GameObject[,] tilemap;
Ray mousepoint;
RaycastHit hit;
Vector3 size;
int camheight = 0;
Transform childholder;
bool map_loaded = false;
// Use this for initialization
void Start () {
map_loaded = false;
MeshFilter mf = BasicBlockForSize.GetComponent(typeof(MeshFilter)) as MeshFilter;
if (mf == null){return;}
Mesh mesh = mf.sharedMesh;
if (mesh == null){return;}
size = mesh.bounds.size;
camheight = (int)(size.y*5.3);
size = new Vector3(size.x*prefabInterneBlockzahl, size.y, size.x*prefabInterneBlockzahl);
kamera.transform.position = new Vector3(((mapsize_x/2)*size.x), 0, ((mapsize_y/2)*size.x)-(10*size.x));
// Start Maploader
StartCoroutine(createMap());
}
IEnumerator createMap() {
//if(mapsize_x > 10 || mapsize_y > 10){
// Debug.LogError("Mapsize is out of Bounds. Please set a maximum size of 10*10 Prefabs.");
// Application.Quit();
//}
int maprun_x = 0;
int maprun_y = 0;
float pos_x = 0;
float pos_y = 0;
int yieldcount = 0;
tilemap = new GameObject[321,321];
for(maprun_y=0; maprun_y<mapsize_y; maprun_y++){
//Debug.Log("Y auf: " + maprun_y);
//Debug.Log("Block_ID: " + blockid);
for(maprun_x=0; maprun_x<mapsize_x; maprun_x++){
pos_x = maprun_x*size.x;
pos_y = maprun_y*size.z;
tilemap[maprun_x, maprun_y] = Instantiate(BasicMapPrefab, new Vector3(pos_x, 0, pos_y), Quaternion.identity) as GameObject;
tilemap[maprun_x, maprun_y].transform.parent = TilemapHolder.transform;
tilemap[maprun_x, maprun_y].name = "DirtBlock_Position: "+(maprun_x)+"/"+(maprun_y);
}
//wait after every row / update percentage of UI Loadbar
if(yieldcount > 10){
yield return 0;
Debug.Log("Reihe geladen: " + (maprun_y-1));
yieldcount = 0;
}
else{
yieldcount ++;
}
}
map_loaded = true;
}
}
What happens now:
if i add this script to ma Tilemap object wich is set as “TilemapHolder”. Add mapsizes and prefab, i hit play.
Now - the FPS drops from 533 to an amount between 0.5 and 1.5…
When the complete map is loaded, the FPS are at a maximum of 130FPS…
You only see 40x30 Maptiles, the rest is out of view. I´ve no light added - and it makes no difference if i remove the normalmap or not.
So… is there a good way to prevent this FPS drop during mapload - And a way to raise the FPS during runtime after the loading is finished?