void OnEnable() { editorData = ScriptableObject.CreateInstance <YuME_editorData>(); AssetPreview.SetPreviewTextureCacheSize(1000); YuTools_Utils.disableTileGizmo(showGizmos); YuTools_Utils.addLayer("YuME_TileMap"); YuME_brushFunctions.cleanSceneOfBrushObjects(); string[] guids; // ---------------------------------------------------------------------------------------------------- // ----- Load Editor Settings // ---------------------------------------------------------------------------------------------------- guids = AssetDatabase.FindAssets("YuME_editorSetupData"); editorData = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0]), typeof(YuME_editorData)) as YuME_editorData; importTileSets(false); loadPreviewTiles(); loadCustomBrushes(); _toolEnabled = toolEnabled; gridSceneObject = GameObject.Find("YuME_MapEditorObject"); updateGridColors(); gridHeight = 0; YuME_brushFunctions.createBrushTile(); YuTools_Utils.showUnityGrid(true); SceneView.RepaintAll(); // ---------------------------------------------------------------------------------------------------- // ----- Setup Scene Delegates // ---------------------------------------------------------------------------------------------------- currentScene = EditorSceneManager.GetActiveScene().name; SceneView.onSceneGUIDelegate -= OnSceneGUI; SceneView.onSceneGUIDelegate += OnSceneGUI; EditorApplication.hierarchyWindowChanged -= OnSceneChanged; EditorApplication.hierarchyWindowChanged += OnSceneChanged; }
public static void combineTiles() { if (YuME_mapEditor.tileMapParent) { frozenMap = new GameObject(); frozenMap.transform.parent = YuME_mapEditor.tileMapParent.transform; frozenMap.name = "frozenMap"; List <GameObject> tilesToCombine = new List <GameObject>(); List <GameObject> lightsToCreate = new List <GameObject>(); List <Transform> freezeTiles = new List <Transform>(); List <Transform> _freezeTiles = new List <Transform>(); EditorUtility.DisplayProgressBar("Building Frozen Map", "Finding Tiles to Freeze", 0f); for (int i = 0; i < 8; i++) { if (YuME_mapEditor.editorPreferences.layerFreeze[i]) { YuME_mapEditor.mapLayers[i].GetComponentsInChildren <Transform>(false, _freezeTiles); freezeTiles.AddRange(_freezeTiles); } else { GameObject layerCopy = Instantiate(YuME_mapEditor.mapLayers[i], YuME_mapEditor.mapLayers[i].transform.position, Quaternion.identity) as GameObject; layerCopy.transform.parent = frozenMap.transform; if (!YuME_mapEditor.editorPreferences.layerStatic[i]) { Transform[] tempTiles = layerCopy.GetComponentsInChildren <Transform>(); foreach (Transform child in tempTiles) { child.gameObject.isStatic = false; } } } } foreach (Transform tile in freezeTiles) { if (tile.GetComponent <MeshRenderer>()) { if (YuME_mapEditor.editorPreferences.convexCollision) { MeshCollider _tempCol = tile.GetComponent <MeshCollider>(); if (_tempCol != null) { _tempCol.convex = true; } } tilesToCombine.Add(tile.gameObject); } if (tile.GetComponent <Light>()) { lightsToCreate.Add(tile.gameObject); } } foreach (GameObject light in lightsToCreate) { GameObject newLight = GameObject.Instantiate(light); newLight.isStatic = true; newLight.transform.position = light.transform.position; newLight.transform.eulerAngles = light.transform.eulerAngles; newLight.transform.parent = frozenMap.transform; } tilesToCombine = tilesToCombine.OrderBy(x => x.GetComponent <MeshRenderer>().sharedMaterial.name).ToList(); Material previousMaterial = tilesToCombine[0].GetComponent <MeshRenderer>().sharedMaterial; List <CombineInstance> combine = new List <CombineInstance>(); CombineInstance tempCombine = new CombineInstance(); int vertexCount = 0; foreach (GameObject mesh in tilesToCombine) { vertexCount += mesh.GetComponent <MeshFilter>().sharedMesh.vertexCount; if (vertexCount > 60000) { vertexCount = 0; newSubMesh(combine, mesh.GetComponent <MeshRenderer>().sharedMaterial); combine = new List <CombineInstance>(); } if (mesh.GetComponent <MeshRenderer>().sharedMaterial.name != previousMaterial.name) { newSubMesh(combine, previousMaterial); combine = new List <CombineInstance>(); } tempCombine.mesh = mesh.GetComponent <MeshFilter>().sharedMesh; tempCombine.transform = mesh.GetComponent <MeshFilter>().transform.localToWorldMatrix; combine.Add(tempCombine); previousMaterial = mesh.GetComponent <MeshRenderer>().sharedMaterial; } newSubMesh(combine, previousMaterial); foreach (Transform layer in YuME_mapEditor.tileMapParent.transform) { if (layer.name.Contains("layer")) { layer.gameObject.SetActive(false); } } YuME_brushFunctions.cleanSceneOfBrushObjects(); EditorUtility.ClearProgressBar(); YuME_brushFunctions.destroyBrushTile(); YuME_brushFunctions.cleanSceneOfBrushObjects(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.defaultTools; } }