public static void setActiveMap() { for (int i = 0; i < MAP_Editor.ref_MapManager.mapList.Count; i++) { if (MAP_Editor.ref_MapManager.mapList[i] != null) { MAP_Editor.ref_MapManager.mapList[i].SetActive(true); } } MAP_Editor.ref_MapManager.mapList[MAP_Editor.currentMapIndex].SetActive(true); MAP_brushFunctions.updateBrushTile(); }
public static void pickTile(Vector3 position) { if (MAP_Editor.findTileMapParent()) { GameObject currentLayer = MAP_Editor.mapLayers[MAP_Editor.currentLayer - 1]; Vector3 tempVec3; for (int i = 0; i < currentLayer.transform.childCount; ++i) { tempVec3 = currentLayer.transform.GetChild(i).transform.position; if (position.x == tempVec3.x && position.z == tempVec3.z && tempVec3.y >= position.y && tempVec3.y < position.y + 1) { MAP_Editor.currentTile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(currentLayer.transform.GetChild(i).transform.gameObject)), typeof(GameObject)) as GameObject; float pickRotation = 0; float pickRotationX = 0; Transform pickTileTransform = currentLayer.transform.GetChild(i).transform; if (pickTileTransform.eulerAngles.y > 0) { pickRotation = pickTileTransform.eulerAngles.y; } if (pickTileTransform.eulerAngles.x > 0) { pickRotationX = pickTileTransform.eulerAngles.x; } MAP_Editor.currentBrushIndex = Array.IndexOf(MAP_Editor.currentTileSetObjects, MAP_Editor.currentTile); MAP_Editor.tileRotation = pickRotation; MAP_Editor.tileRotationX = pickRotationX; tempVec3 = pickTileTransform.localScale; tempVec3.x /= MAP_Editor.globalScale; tempVec3.y /= MAP_Editor.globalScale; tempVec3.z /= MAP_Editor.globalScale; MAP_Editor.tileScale = tempVec3; MAP_brushFunctions.updateBrushTile(pickTileTransform.localScale); MAP_Editor.currentBrushType = eBrushTypes.standardBrush; MAP_Editor.selectTool = eToolIcons.brushTool; return; } } } }
public static void combineTiles() { if (MAP_Editor.tileMapParent) { frozenMap = new GameObject(); frozenMap.transform.SetParent(MAP_Editor.tileMapParent.transform); frozenMap.name = Define.FROZEN_MAP; 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 (MAP_Editor.editorPreferences.layerFreeze[i]) { MAP_Editor.mapLayers[i].GetComponentsInChildren <Transform>(false, _freezeTiles); freezeTiles.AddRange(_freezeTiles); } else { GameObject layerCopy = Instantiate(MAP_Editor.mapLayers[i], MAP_Editor.mapLayers[i].transform.position, Quaternion.identity) as GameObject; layerCopy.transform.SetParent(frozenMap.transform); if (!MAP_Editor.editorPreferences.layerStatic[i]) { Transform[] tempTiles = layerCopy.GetComponentsInChildren <Transform>(); foreach (Transform item in tempTiles) { item.gameObject.isStatic = false; } } } } foreach (Transform tile in freezeTiles) { if (tile.GetComponent <MeshRenderer>()) { if (MAP_Editor.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.localScale = frozenMap.transform.localScale; } 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>().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 MAP_Editor.tileMapParent.transform) { if (layer.name.Contains(Define.LAYER)) { layer.gameObject.SetActive(false); } } MAP_brushFunctions.cleanSceneOfBrushObjects(); EditorUtility.ClearProgressBar(); MAP_brushFunctions.destoryBrushTile(); MAP_brushFunctions.cleanSceneOfBrushObjects(); MAP_Editor.selectTool = eToolIcons.defaultTools; } }
public static void checkMouseShortcuts(Event mouseEvent) { if (mouseEvent.type == EventType.ScrollWheel && mouseEvent.shift && !mouseEvent.control && !mouseEvent.alt) { mouseEvent.Use(); if (!MAP_Editor.editorPreferences.invertMouseWheel) { if (!MAP_Editor.editorPreferences.twoPointFiveDMode) { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight += MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } else { MAP_Editor.gridHeight -= MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } } else { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight -= MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } else { MAP_Editor.gridHeight += MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } } } else { if (!MAP_Editor.editorPreferences.twoPointFiveDMode) { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight -= MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } else { MAP_Editor.gridHeight += MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } } else { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight += MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } else { MAP_Editor.gridHeight -= MAP_Editor.globalScale * MAP_Editor.editorPreferences.gridLayerHeightScaler; } } } } if (mouseEvent.type == EventType.ScrollWheel && mouseEvent.shift && mouseEvent.alt && !mouseEvent.control) { mouseEvent.Use(); if (!MAP_Editor.editorPreferences.invertMouseWheel) { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight += (MAP_Editor.globalScale * 0.25f); } else { MAP_Editor.gridHeight -= (MAP_Editor.globalScale * 0.25f); } } else { if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.gridHeight -= (MAP_Editor.globalScale * 0.25f); } else { MAP_Editor.gridHeight += (MAP_Editor.globalScale * 0.25f); } } } else if (mouseEvent.type == EventType.ScrollWheel && mouseEvent.control && mouseEvent.alt && MAP_Editor.selectTool == eToolIcons.brushTool) { mouseEvent.Use(); if (Event.current.delta.y - Event.current.delta.x >= 0f) { MAP_Editor.tileRotation += 90f; } else { MAP_Editor.tileRotation -= 90f; } } else if (mouseEvent.type == EventType.ScrollWheel && mouseEvent.control && mouseEvent.shift == true && MAP_Editor.selectTool == eToolIcons.brushTool) { mouseEvent.Use(); MAP_Editor.currentBrushType = eBrushTypes.standardBrush; if (!MAP_Editor.editorPreferences.invertMouseWheel) { if (Event.current.delta.y - Event.current.delta.x > 0f) { MAP_Editor.currentBrushIndex++; if (MAP_Editor.currentBrushIndex >= MAP_Editor.currentTileSetObjects.Length) { MAP_Editor.currentBrushIndex = MAP_Editor.currentTileSetObjects.Length - 1; } MAP_Editor.currentTile = MAP_Editor.currentTileSetObjects[MAP_Editor.currentBrushIndex]; MAP_Editor.currentTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0f); MAP_brushFunctions.updateBrushTile(); } else { MAP_Editor.currentBrushIndex--; if (MAP_Editor.currentBrushIndex < 0) { MAP_Editor.currentBrushIndex = 0; } MAP_Editor.currentTile = MAP_Editor.currentTileSetObjects[MAP_Editor.currentBrushIndex]; MAP_Editor.currentTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0f); MAP_brushFunctions.updateBrushTile(); } } else { if (Event.current.delta.y - Event.current.delta.x < 0f) { MAP_Editor.currentBrushIndex++; if (MAP_Editor.currentBrushIndex >= MAP_Editor.currentTileSetObjects.Length) { MAP_Editor.currentBrushIndex = MAP_Editor.currentTileSetObjects.Length - 1; } MAP_Editor.currentTile = MAP_Editor.currentTileSetObjects[MAP_Editor.currentBrushIndex]; MAP_Editor.currentTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0f); MAP_brushFunctions.updateBrushTile(); } else { MAP_Editor.currentBrushIndex--; if (MAP_Editor.currentBrushIndex < 0) { MAP_Editor.currentBrushIndex = 0; } MAP_Editor.currentTile = MAP_Editor.currentTileSetObjects[MAP_Editor.currentBrushIndex]; MAP_Editor.currentTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0f); MAP_brushFunctions.updateBrushTile(); } } } }