public void Batch(bool AddMeshColliders, bool RemoveLeftOvers) { GameObject mapTilesStatic = (GameObject)GameObject.Find("uteMAP_ALLTILES/uteMAP_STATIC"); uteCombineChildren combiner = (uteCombineChildren)mapTilesStatic.GetComponent <uteCombineChildren>(); if (!combiner) { combiner = (uteCombineChildren)mapTilesStatic.AddComponent <uteCombineChildren>(); } combiner.Batch(AddMeshColliders, RemoveLeftOvers); }
public List <GameObject> GetBatchedObjects() { uteCombineChildren combiner = GameObject.Find("uteMAP_ALLTILES/uteMAP_STATIC").GetComponent <uteCombineChildren>(); if (combiner) { return(combiner.GetBatchedObjects()); } Debug.Log("[RuntimeCombiner] No Batch information was found."); return(null); }
public void UnBatch() { GameObject mapTilesStatic = (GameObject)GameObject.Find("uteMAP_ALLTILES/uteMAP_STATIC"); uteCombineChildren combiner = (uteCombineChildren)mapTilesStatic.GetComponent <uteCombineChildren>(); if (combiner) { combiner.UnBatch(); } else { Debug.Log("[RuntimeCombiner] No Batch information was found."); } }
private IEnumerator _LoadMapAsync(int frameSkip) { #if UNITY_EDITOR Debug.Log("Loading Map... (This message appears only in the Editor)"); #endif GameObject MAP = new GameObject(mapName); GameObject MAP_S = new GameObject("STATIC"); GameObject MAP_D = new GameObject("DYNAMIC"); MAP_S.transform.parent = MAP.transform; MAP_D.transform.parent = MAP.transform; string[] myMapInfoAll = myLatestMap.Split("$"[0]); for (int i = 0; i < myMapInfoAll.Length - 1; i++) { string[] myMapParts = myMapInfoAll[i].Split(":"[0]); int objID = System.Convert.ToInt32(myMapParts[0]); GameObject obj = (GameObject)refTiles[objID]; float pX = System.Convert.ToSingle(myMapParts[1]); float pY = System.Convert.ToSingle(myMapParts[2]); float pZ = System.Convert.ToSingle(myMapParts[3]); int rX = System.Convert.ToInt32(myMapParts[4]); int rY = System.Convert.ToInt32(myMapParts[5]); int rZ = System.Convert.ToInt32(myMapParts[6]); string staticInfo = myMapParts[7]; bool isStatic = false; if (staticInfo.Equals("1")) { isStatic = true; } GameObject newObj = (GameObject)Instantiate(obj, new Vector3(pX, pY, pZ) + MapOffset + new Vector3(-500, 0, -500), Quaternion.identity); newObj.name = objID.ToString(); newObj.transform.localEulerAngles = new Vector3(rX, rY, rZ) + obj.transform.localEulerAngles; if (i % frameSkip == 0) { yield return(0); } if (isStatic) { newObj.isStatic = true; newObj.transform.parent = MAP_S.transform; } else { newObj.isStatic = false; newObj.transform.parent = MAP_D.transform; } } if (StaticBatching) { uteCombineChildren batching = (uteCombineChildren)MAP_S.AddComponent <uteCombineChildren>(); string optLevel = "low"; if (currentOptimizationLevelIndex == 1) { optLevel = "medium"; } else if (currentOptimizationLevelIndex == 2) { optLevel = "high"; } batching.Batch(AddMeshColliders, RemoveLeftovers, false, PrepareForLightmapping, optLevel); } MAP_S.transform.localScale = MapScale; MAP_D.transform.localScale = MapScale; isMapLoaded = true; #if UNITY_EDITOR Debug.Log("Map LOADED! (This message appears only in the Editor)"); #endif yield return(0); }
IEnumerator _LoadMapAsyncFromPoint(Vector3 point, int objectsPerFrame, int startAsyncAfterObjNr = 0) { List <Tile> allTilesForAsyncLoad = new List <Tile>(); List <Tile> allTilesForAsyncLoadNew = new List <Tile>(); GameObject MAP = new GameObject(mapName); GameObject MAP_S = new GameObject("STATIC"); GameObject MAP_D = new GameObject("DYNAMIC"); MAP_S.transform.parent = MAP.transform; MAP_D.transform.parent = MAP.transform; string[] myMapInfoAll = myLatestMap.Split("$"[0]); float distance = 10000000.0f; int nearestToPoint = 0; for (int i = 0; i < myMapInfoAll.Length - 1; i++) { string[] myMapParts = myMapInfoAll[i].Split(":"[0]); int objID = System.Convert.ToInt32(myMapParts[0]); GameObject obj = (GameObject)refTiles[objID]; float pX = System.Convert.ToSingle(myMapParts[1]); float pY = System.Convert.ToSingle(myMapParts[2]); float pZ = System.Convert.ToSingle(myMapParts[3]); int rX = System.Convert.ToInt32(myMapParts[4]); int rY = System.Convert.ToInt32(myMapParts[5]); int rZ = System.Convert.ToInt32(myMapParts[6]); string staticInfo = myMapParts[7]; Vector3 fixedPos = new Vector3(pX, pY, pZ) + new Vector3(-500, 0, -500) + MapOffset; float dist = Vector3.Distance(point, fixedPos); allTilesForAsyncLoad.Add(new Tile(fixedPos, new Vector3(rX, rY, rZ), objID, staticInfo, obj, dist)); } allTilesForAsyncLoad = allTilesForAsyncLoad.OrderBy(x => x.distanceFromPoint).ToList(); /*List<int> newIndexes = new List<int>(); * int counter = 0; * Debug.Log(nearestToPoint+"AAA"); * for(int i=0;i<newTiles.Count;i++) * { * if(allTilesForAsyncLoad.Count<i) * { * newIndexes.Add(i); * } * * int res = i-(i-(++counter)); * * if(res>=0) * { * newIndexes.Add(res); * } * } * * for(int i=0;i<newIndexes.Count;i++) * { * Debug.Log(nearestToPoint+":"+newIndexes[i]); * }*/ int n_ct = 0; for (int i = 0; i < allTilesForAsyncLoad.Count; i++) { //int idx = newIndexes[i]; // if(idx>=newTiles.Count) continue; GameObject newObj = (GameObject)Instantiate(allTilesForAsyncLoad[i].obj, allTilesForAsyncLoad[i].pos, Quaternion.identity); newObj.transform.localEulerAngles = allTilesForAsyncLoad[i].rot; // = newTiles[i].obj.transform.localEulerAngles; newObj.name = allTilesForAsyncLoad[i].id.ToString(); if (allTilesForAsyncLoad[i].isStatic) { newObj.isStatic = true; newObj.transform.parent = MAP_S.transform; } else { newObj.isStatic = false; newObj.transform.parent = MAP_D.transform; } if (i > startAsyncAfterObjNr) { if (n_ct++ > 20) // if(i%objectsPerFrame==0) { n_ct = 0; yield return(0); } } } if (StaticBatching) { uteCombineChildren batching = (uteCombineChildren)MAP_S.AddComponent <uteCombineChildren>(); string optLevel = "low"; if (currentOptimizationLevelIndex == 1) { optLevel = "medium"; } else if (currentOptimizationLevelIndex == 2) { optLevel = "high"; } batching.Batch(AddMeshColliders, RemoveLeftovers, false, PrepareForLightmapping, optLevel); } MAP_S.transform.localScale = MapScale; MAP_D.transform.localScale = MapScale; isMapLoaded = true; yield return(0); }
IEnumerator ExportToPrefab() { GameObject _MAP = (GameObject)Instantiate(MAP_STATIC, MAP_STATIC.transform.position, MAP_STATIC.transform.rotation); _MAP.name = "MAPTemp"; _MAP.transform.position = new Vector3(0.0f, 0.0f, 0.0f); if (isCombineMesh == false) { uteCombineChildren uteCC = (uteCombineChildren)_MAP.AddComponent <uteCombineChildren>(); uteCC.Batch(addMeshCollider, true, true); } yield return(0); Object tempPrefab = PrefabUtility.CreateEmptyPrefab(uteGLOBAL3dMapEditor.getMyPatternsDir() + mapName + ".prefab"); MeshFilter[] tns = (MeshFilter[])_MAP.GetComponentsInChildren <MeshFilter>(); for (int i = 0; i < tns.Length; i++) { string meshName = ((MeshFilter)tns[i]).gameObject.name; if (meshName.Equals("Combined mesh")) { Mesh mesh = new Mesh(); mesh.name = "CombinedMesh1"; mesh = ((MeshFilter)tns[i]).mesh; AssetDatabase.AddObjectToAsset(mesh, tempPrefab); } } Transform[] allObjsT = (Transform[])_MAP.GetComponentsInChildren <Transform>(); Transform nearestT = _MAP.transform; float nearestF = 10000000.0f; for (int i = 0; i < allObjsT.Length; i++) { Transform objT = (Transform)allObjsT[i]; if (!objT.gameObject.name.Equals("MAPTemp")) { if (objT.gameObject.transform.parent.gameObject.name.Equals("MAPTemp")) { float currentDistF = (float)Vector3.Distance(objT.transform.position, _MAP.transform.position); if (currentDistF < nearestF) { nearestF = currentDistF; nearestT = objT; } } } } Vector3 SavePos = nearestT.position; for (int i = 0; i < allObjsT.Length; i++) { Transform objT = (Transform)allObjsT[i]; if (!objT.gameObject.name.Equals("MAPTemp")) { if (objT.gameObject.transform.parent.gameObject.name.Equals("MAPTemp")) { objT.position -= SavePos + new Vector3(.5f, .5f, .5f); } } } PrefabUtility.ReplacePrefab(_MAP, tempPrefab, ReplacePrefabOptions.ReplaceNameBased); Destroy(_MAP); isShow = false; }