public static void updateBrushTile(Vector3 tileScale) { if (YuME_mapEditor.findTileMapParent() && YuME_mapEditor.toolEnabled) { destroyBrushTile(); YuME_mapEditor.brushTile = Instantiate(YuME_mapEditor.currentTile, Vector3.zero, Quaternion.identity) as GameObject; YuME_mapEditor.brushTile.transform.eulerAngles = new Vector3(YuME_mapEditor.tileRotationX, YuME_mapEditor.tileRotation, 0f); YuME_mapEditor.brushTile.transform.parent = YuME_mapEditor.tileMapParent.transform; YuME_mapEditor.brushTile.transform.localScale = tileScale; YuME_mapEditor.brushTile.name = "YuME_brushTile"; YuME_mapEditor.brushTile.hideFlags = HideFlags.HideAndDontSave; YuME_mapEditor.brushTile.isStatic = false; foreach (Transform child in YuME_mapEditor.brushTile.transform) { child.gameObject.isStatic = false; } YuME_mapEditor.tileChildObjects.Clear(); foreach (Transform child in YuME_mapEditor.brushTile.transform) { YuME_mapEditor.tileChildObjects.Add(child.gameObject); } YuME_mapEditor.showWireBrush = false; } }
public static void pasteCustomBrush(Vector3 position) { if (YuME_mapEditor.brushTile != null) { if (YuME_mapEditor.findTileMapParent()) { Undo.RegisterFullObjectHierarchyUndo(YuME_mapEditor.tileMapParent, "Paint Custom Brush"); foreach (Transform child in YuME_mapEditor.brushTile.transform) { GameObject pasteTile = PrefabUtility.InstantiatePrefab(getPrefabFromCurrentTiles(child.gameObject) as GameObject) as GameObject; if (pasteTile != null) { child.position = normalizePosition(child.position); YuME_tileFunctions.eraseTile(child.position); pasteTile.transform.eulerAngles = child.eulerAngles; pasteTile.transform.position = child.position; pasteTile.transform.localScale = child.transform.lossyScale; pasteTile.transform.parent = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1].transform; } } EditorSceneManager.MarkAllScenesDirty(); } } }
public static void updateBrushTile() { if (YuME_mapEditor.brushTile != null) { DestroyImmediate(YuME_mapEditor.brushTile); } if (YuME_mapEditor.findTileMapParent()) { YuME_mapEditor.brushTile = Instantiate(YuME_mapEditor.currentTile, Vector3.zero, Quaternion.identity) as GameObject;; YuME_mapEditor.brushTile.transform.eulerAngles = new Vector3(0f, YuME_mapEditor.tileRotation, 0f); YuME_mapEditor.brushTile.transform.localScale = YuME_mapEditor.currentTile.transform.localScale; YuME_mapEditor.brushTile.transform.parent = YuME_mapEditor.tileMapParent.transform; YuME_mapEditor.brushTile.name = "YuME_brushTile"; YuME_mapEditor.brushTile.hideFlags = HideFlags.HideAndDontSave; YuME_mapEditor.tileChildObjects.Clear(); foreach (Transform child in YuME_mapEditor.brushTile.transform) { YuME_mapEditor.tileChildObjects.Add(child.gameObject); } YuME_mapEditor.showWireBrush = false; } }
public static void pickTile(Vector3 position) { if (YuME_mapEditor.findTileMapParent()) { GameObject currentLayer = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1]; Vector3 tempVec3; for (int i = 0; i < currentLayer.transform.childCount; ++i) { tempVec3 = currentLayer.transform.GetChild(i).transform.position; if (tempVec3.x == position.x && tempVec3.z == position.z && tempVec3.y >= position.y && tempVec3.y < position.y + 1f) { YuME_mapEditor.currentTile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(currentLayer.transform.GetChild(i).gameObject)), typeof(GameObject)) as GameObject; float pickRotation = 0; if (currentLayer.transform.GetChild(i).transform.eulerAngles.y > 0) { pickRotation = currentLayer.transform.GetChild(i).eulerAngles.y; } YuME_mapEditor.currentBrushIndex = Array.IndexOf(YuME_mapEditor.currentTileSetObjects, YuME_mapEditor.currentTile); YuME_mapEditor.currentTile.transform.localScale = currentLayer.transform.GetChild(i).gameObject.transform.localScale; YuME_mapEditor.tileRotation = pickRotation; YuME_brushFunctions.updateBrushTile(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; return; } } } }
public static void isolateGridTiles() { restoreIsolatedGridTiles(); if (YuME_mapEditor.findTileMapParent()) { foreach (Transform layer in YuME_mapEditor.tileMapParent.transform) { foreach (Transform tile in layer) { if (!YuME_mapEditor.editorPreferences.twoPointFiveDMode) { if (tile.gameObject.transform.position.y != YuME_mapEditor.gridHeight) { tile.gameObject.SetActive(false); YuME_mapEditor.isolatedGridObjects.Add(tile.gameObject); } } else { if (tile.gameObject.transform.position.z != YuME_mapEditor.gridHeight) { tile.gameObject.SetActive(false); YuME_mapEditor.isolatedGridObjects.Add(tile.gameObject); } } } } } }
public static void selectTile(Vector3 position) { if (YuME_mapEditor.findTileMapParent()) { GameObject currentLayer = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1]; for (int i = 0; i < currentLayer.transform.childCount; ++i) { float distanceToTile = Vector3.Distance(currentLayer.transform.GetChild(i).transform.position, position); if (distanceToTile < 0.1f && currentLayer.transform.GetChild(i).name != "YuME_brushTile") { for (int t = 0; t < YuME_mapEditor.selectedTiles.Count; t++) { if (currentLayer.transform.GetChild(i).gameObject.transform.position == YuME_mapEditor.selectedTiles[t].transform.position) { return; } } YuME_mapEditor.selectedTiles.Add(currentLayer.transform.GetChild(i).gameObject); return; } } } }
public static void pasteCopyBrush(Vector3 position) { if (YuME_mapEditor.brushTile != null) { if (YuME_mapEditor.findTileMapParent()) { Undo.RegisterFullObjectHierarchyUndo(YuME_mapEditor.tileMapParent, "Paint Brush"); foreach (Transform child in YuME_mapEditor.brushTile.transform) { #if UNITY_2018_3_OR_NEWER GameObject pasteTile = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject) as GameObject); #else GameObject pasteTile = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetPrefabParent(child.gameObject) as GameObject); #endif YuME_tileFunctions.eraseTile(child.position); pasteTile.transform.eulerAngles = child.eulerAngles; pasteTile.transform.position = normalizePosition(child.position); pasteTile.transform.localScale = child.transform.lossyScale; pasteTile.transform.parent = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1].transform; } EditorSceneManager.MarkAllScenesDirty(); } } }
public static void displayGizmoGrid() { if (YuME_mapEditor.findEditorGameObject()) { YuME_mapEditor.editorGameObject.GetComponent <YuME_GizmoGrid>().toolEnabled = YuME_mapEditor.toolEnabled; } }
void OnGUI() { EditorGUILayout.Space(); _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("New Map Name", EditorStyles.boldLabel); newMapName = EditorGUILayout.TextField(newMapName); if (GUILayout.Button("Add New Map", GUILayout.Height(20))) { YuME_mapManagerFunctions.buildNewMap(newMapName); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); for (int i = 0; i < YuME_mapEditor.ref_MapManager.mapList.Count; i++) { if (YuME_mapEditor.ref_MapManager.mapList[i] != null) { EditorGUILayout.BeginHorizontal(); YuME_mapEditor.ref_MapManager.mapList[i].name = EditorGUILayout.TextField(YuME_mapEditor.ref_MapManager.mapList[i].name, GUILayout.Width(200)); if (i != 0) { if (GUILayout.Button("Clone Map", GUILayout.Height(20), GUILayout.Width(75))) { YuME_mapEditor.cloneMap(YuME_mapEditor.ref_MapManager.mapList[i]); EditorSceneManager.MarkAllScenesDirty(); } if (GUILayout.Button("Delete Map", GUILayout.Height(20), GUILayout.Width(75))) { DestroyImmediate(YuME_mapEditor.ref_MapManager.mapList[i]); YuME_mapEditor.ref_MapManager.mapList.RemoveAt(i); YuME_mapEditor.currentMapIndex = 0; EditorSceneManager.MarkAllScenesDirty(); } } else { if (GUILayout.Button("Clone Map", GUILayout.Height(20), GUILayout.Width(154))) { YuME_mapEditor.cloneMap(YuME_mapEditor.ref_MapManager.mapList[i]); EditorSceneManager.MarkAllScenesDirty(); } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }
// ---------------------------------------------------------------------------------------------------- // ----- Scene Editor Tools // ---------------------------------------------------------------------------------------------------- public static void addTile(Vector3 position) { GameObject placedTile; if (YuME_mapEditor.findTileMapParent()) { if (YuME_mapEditor.useAltTiles == true) { YuME_mapEditor.s_AltTiles checkAltTiles = new YuME_mapEditor.s_AltTiles(); try { checkAltTiles = YuME_mapEditor.altTiles.Single(s => s.masterTile == YuME_mapEditor.currentTile.name); } catch { } if (checkAltTiles.masterTile != null) { int randomTile = UnityEngine.Random.Range(0, checkAltTiles.altTileObjects.Length + 1); if (randomTile < checkAltTiles.altTileObjects.Length) { placedTile = PrefabUtility.InstantiatePrefab(checkAltTiles.altTileObjects[randomTile] as GameObject) as GameObject; } else { placedTile = PrefabUtility.InstantiatePrefab(YuME_mapEditor.currentTile as GameObject) as GameObject; } } else { placedTile = PrefabUtility.InstantiatePrefab(YuME_mapEditor.currentTile as GameObject) as GameObject; } } else { placedTile = PrefabUtility.InstantiatePrefab(YuME_mapEditor.currentTile as GameObject) as GameObject; } Undo.RegisterCreatedObjectUndo(placedTile, "Placed Tile"); if (YuME_mapEditor.randomRotationMode) { placedTile.transform.eulerAngles = new Vector3(UnityEngine.Random.Range(0, 4) * 90f, UnityEngine.Random.Range(0, 4) * 90f, UnityEngine.Random.Range(0, 4) * 90f); } else { placedTile.transform.eulerAngles = new Vector3(YuME_mapEditor.tileRotationX, YuME_mapEditor.tileRotation, 0f); } placedTile.transform.position = position; placedTile.transform.localScale = YuME_mapEditor.brushTile.transform.localScale; placedTile.transform.parent = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1].transform; } EditorSceneManager.MarkAllScenesDirty(); }
public static void saveFrozenMesh(string path) { path = YuTools_Utils.shortenAssetPath(path); int counter = 1; if (YuME_mapEditor.findTileMapParent()) { foreach (Transform child in YuME_mapEditor.tileMapParent.transform) { if (child.gameObject.name == "frozenMap") { GameObject saveMap = Instantiate(child.gameObject); saveMap.name = YuME_mapEditor.tileMapParent.name; if (!AssetDatabase.IsValidFolder(path + "/" + saveMap.name + "Meshes")) { AssetDatabase.CreateFolder(path, saveMap.name + "Meshes"); } EditorUtility.ClearProgressBar(); foreach (Transform frozenMesh in saveMap.transform) { EditorUtility.DisplayProgressBar("Saving Meshes", "Saving Mesh " + (counter) + ". This might take some time", 1); Mesh saveMesh = Object.Instantiate(frozenMesh.GetComponent <MeshFilter>().sharedMesh) as Mesh; //Unwrapping.GenerateSecondaryUVSet(saveMesh); AssetDatabase.CreateAsset(saveMesh, path + "/" + saveMap.name + "Meshes/" + frozenMesh.name + counter + ".asset"); frozenMesh.GetComponent <MeshFilter>().mesh = saveMesh; counter++; } EditorUtility.ClearProgressBar(); Object prefabAlreadyCreated = AssetDatabase.LoadAssetAtPath(path + "/" + saveMap.name + ".prefab", typeof(GameObject)); if (prefabAlreadyCreated != null) { PrefabUtility.ReplacePrefab(saveMap, prefabAlreadyCreated, ReplacePrefabOptions.ReplaceNameBased); } else { PrefabUtility.CreatePrefab(path + "/" + saveMap.name + ".prefab", saveMap); } AssetDatabase.SaveAssets(); if (saveMap != null) { DestroyImmediate(saveMap); } } } AssetDatabase.Refresh(); } }
static void revertScenePrefabs() { if (YuME_mapEditor.findTileMapParent()) { foreach (Transform child in YuME_mapEditor.tileMapParent.transform) { PrefabUtility.RevertPrefabInstance(child.gameObject); } } }
public static void refreshMap() { Vector3 tempVec3; if (YuME_mapEditor.findTileMapParent()) { foreach (Transform layer in YuME_mapEditor.tileMapParent.transform) { foreach (Transform tile in layer) { tempVec3 = tile.localScale; if (tempVec3.x != YuME_mapEditor.editorPreferences.gridScaleFactor) { if (tempVec3.x < 0) { tempVec3.x = YuME_mapEditor.editorPreferences.gridScaleFactor * -1; } else { tempVec3.x = YuME_mapEditor.editorPreferences.gridScaleFactor; } } if (tempVec3.y != YuME_mapEditor.editorPreferences.gridScaleFactor) { if (tempVec3.y < 0) { tempVec3.y = YuME_mapEditor.editorPreferences.gridScaleFactor * -1; } else { tempVec3.y = YuME_mapEditor.editorPreferences.gridScaleFactor; } } if (tempVec3.z != YuME_mapEditor.editorPreferences.gridScaleFactor) { if (tempVec3.z < 0) { tempVec3.z = YuME_mapEditor.editorPreferences.gridScaleFactor * -1; } else { tempVec3.z = YuME_mapEditor.editorPreferences.gridScaleFactor; } } tile.localScale = tempVec3; } } } }
public static void pickTile(Vector3 position) { if (YuME_mapEditor.findTileMapParent()) { GameObject currentLayer = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1]; Vector3 tempVec3; for (int i = 0; i < currentLayer.transform.childCount; ++i) { tempVec3 = currentLayer.transform.GetChild(i).transform.position; if (tempVec3.x == position.x && tempVec3.z == position.z && tempVec3.y >= position.y && tempVec3.y < position.y + 1f) { #if UNITY_2018_3_OR_NEWER YuME_mapEditor.currentTile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(PrefabUtility.GetCorrespondingObjectFromSource(currentLayer.transform.GetChild(i).gameObject)), typeof(GameObject)) as GameObject; #else YuME_mapEditor.currentTile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(currentLayer.transform.GetChild(i).gameObject)), typeof(GameObject)) as GameObject; #endif 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; } YuME_mapEditor.currentBrushIndex = Array.IndexOf(YuME_mapEditor.currentTileSetObjects, YuME_mapEditor.currentTile); YuME_mapEditor.tileRotation = pickRotation; YuME_mapEditor.tileRotationX = pickRotationX; tempVec3 = pickTileTransform.localScale; tempVec3.x /= YuME_mapEditor.globalScale; tempVec3.y /= YuME_mapEditor.globalScale; tempVec3.z /= YuME_mapEditor.globalScale; YuME_mapEditor.tileScale = tempVec3; YuME_brushFunctions.updateBrushTile(pickTileTransform.localScale); YuME_mapEditor.currentBrushType = YuME_mapEditor.brushTypes.standardBrush; YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; return; } } } }
public static void createCopyBrush(bool destroySourceTiles) { YuME_tileFunctions.checkTileSelectionStatus(); if (YuME_mapEditor.currentBrushType != YuME_mapEditor.brushTypes.copyBrush && YuME_mapEditor.selectedTiles.Count > 0) { YuME_mapEditor.currentBrushType = YuME_mapEditor.brushTypes.copyBrush; if (YuME_mapEditor.brushTile != null) { DestroyImmediate(YuME_mapEditor.brushTile); } if (YuME_mapEditor.findTileMapParent()) { Undo.RegisterFullObjectHierarchyUndo(YuME_mapEditor.tileMapParent, "Create Brush"); YuME_mapEditor.brushTile = new GameObject(); YuME_mapEditor.brushTile.transform.eulerAngles = new Vector3(YuME_mapEditor.tileRotationX, YuME_mapEditor.tileRotation, 0f); YuME_mapEditor.brushTile.transform.parent = YuME_mapEditor.tileMapParent.transform; YuME_mapEditor.brushTile.name = "YuME_brushTile"; YuME_mapEditor.brushTile.transform.position = YuME_mapEditor.selectedTiles[0].transform.position; YuME_mapEditor.tileChildObjects.Clear(); foreach (GameObject tile in YuME_mapEditor.selectedTiles) { #if UNITY_2018_3_OR_NEWER GameObject tempTile = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetCorrespondingObjectFromSource(tile) as GameObject); #else GameObject tempTile = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetPrefabParent(tile) as GameObject); #endif tempTile.transform.parent = YuME_mapEditor.brushTile.transform; tempTile.transform.position = tile.transform.position; tempTile.transform.eulerAngles = tile.transform.eulerAngles; tempTile.transform.localScale = tile.transform.localScale; YuME_mapEditor.tileChildObjects.Add(tempTile); if (destroySourceTiles) { DestroyImmediate(tile); } } YuME_mapEditor.selectedTiles.Clear(); YuME_mapEditor.showWireBrush = false; } } }
public static void createCustomBrush() { GameObject tileParentObject = new GameObject(); if (YuME_mapEditor.selectedTiles.Count > 0) { // When creating a custom brush we need to find the lowest Z transform in the selection to become the pivot transform GameObject bottomLevelOfSelection = YuME_mapEditor.selectedTiles[0]; foreach (GameObject checkObjects in YuME_mapEditor.selectedTiles) { if (checkObjects.transform.position.z < bottomLevelOfSelection.transform.position.z) { bottomLevelOfSelection = checkObjects; } } // center the parent object around the lowest block to make sure all the selected brushes are centered around the parent tileParentObject.transform.position = bottomLevelOfSelection.transform.position; // Build the brush by finding the parent prefab, creating an instance and then setting it to the transform of the original scene prefab foreach (GameObject tile in YuME_mapEditor.selectedTiles) { GameObject newBrushObject = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetPrefabParent(tile) as GameObject); newBrushObject.transform.position = tile.transform.position; newBrushObject.transform.eulerAngles = tile.transform.eulerAngles; newBrushObject.transform.localScale = tile.transform.localScale; newBrushObject.transform.parent = tileParentObject.transform; } // reset the parents position so it is zero when dropped in the scene tileParentObject.transform.position = Vector3.zero; // Add the prefab to the project tileParentObject.name = "CustomBrush" + YuTools_Utils.numberOfFilesInFolder(YuME_mapEditor.availableTileSets[YuME_mapEditor.currentTileSetIndex].customBrushDestinationFolder, "*_YuME.prefab") + "_YuME.prefab"; string destinationPath = YuTools_Utils.getAssetPath(YuME_mapEditor.availableTileSets[YuME_mapEditor.currentTileSetIndex]) + "CustomBrushes/"; PrefabUtility.CreatePrefab(destinationPath + tileParentObject.name, tileParentObject); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); // refesh the asset database to tell unity changes have been made // remove our temporary builder object DestroyImmediate(tileParentObject); YuME_mapEditor.selectedTiles.Clear(); // reload the custom brushes YuME_mapEditor.loadCustomBrushes(); } }
static void revertScenePrefabs() { if (YuME_mapEditor.findTileMapParent()) { foreach (Transform child in YuME_mapEditor.tileMapParent.transform) { #if UNITY_2018_3_OR_NEWER PrefabUtility.RevertPrefabInstance(child.gameObject, InteractionMode.AutomatedAction); #else PrefabUtility.RevertPrefabInstance(child.gameObject); #endif } } }
static void swapTileSet() { string path = YuTools_Utils.getAssetPath(YuME_mapEditor.availableTileSets[swapTileSetIndex]); swapTileSetObjects = YuTools_Utils.loadDirectoryContents(path, "*.prefab"); List <GameObject> layerTiles = new List <GameObject>(); if (swapTileSetObjects != null) { GameObject swapTile; if (YuME_mapEditor.findTileMapParent()) { Undo.RegisterFullObjectHierarchyUndo(YuME_mapEditor.tileMapParent, "Swap Tiles"); foreach (Transform layer in YuME_mapEditor.tileMapParent.transform) { if (layer.gameObject.name.Contains("layer")) { layerTiles.Clear(); foreach (Transform tile in layer) { layerTiles.Add(tile.gameObject); } for (int i = 0; i < layerTiles.Count; i++) { for (int swap = 0; swap < swapTileSetObjects.Length; swap++) { if (layerTiles[i].name == swapTileSetObjects[swap].name) { EditorUtility.DisplayProgressBar("Swapping Tileset", layerTiles[i].name, (float)i / (float)layerTiles.Count); swapTile = PrefabUtility.InstantiatePrefab(swapTileSetObjects[swap] as GameObject) as GameObject; swapTile.transform.parent = layer; swapTile.transform.position = layerTiles[i].transform.position; swapTile.transform.eulerAngles = layerTiles[i].transform.eulerAngles; swapTile.transform.GetChild(0).transform.position = layerTiles[i].transform.GetChild(0).transform.position; DestroyImmediate(layerTiles[i]); break; } } } } } } } }
public static void isolateLayerTiles() { restoreIsolatedLayerTiles(); if (YuME_mapEditor.findTileMapParent()) { foreach (Transform tile in YuME_mapEditor.tileMapParent.transform) { if (tile.name != "layer" + YuME_mapEditor.currentLayer) { tile.gameObject.SetActive(false); YuME_mapEditor.isolatedLayerObjects.Add(tile.gameObject); } } } }
// ---------------------------------------------------------------------------------------------------- // ----- Scene Editor Tools // ---------------------------------------------------------------------------------------------------- public static void addTile(Vector3 position) { GameObject placedTile; if (YuME_mapEditor.findTileMapParent()) { placedTile = PrefabUtility.InstantiatePrefab(YuME_mapEditor.currentTile as GameObject) as GameObject; Undo.RegisterCreatedObjectUndo(placedTile, "Placed Tile"); placedTile.transform.eulerAngles = new Vector3(0f, YuME_mapEditor.tileRotation, 0f); placedTile.transform.position = position; placedTile.transform.localScale = YuME_mapEditor.brushTile.transform.localScale; placedTile.transform.parent = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1].transform; } EditorSceneManager.MarkAllScenesDirty(); }
public static void selectAllTiles() { if (YuME_mapEditor.findTileMapParent()) { GameObject currentLayer = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1]; if (YuME_mapEditor.selectedTiles.Count > 0) { YuME_mapEditor.selectedTiles.Clear(); } else { for (int i = 0; i < currentLayer.transform.childCount; ++i) { YuME_mapEditor.selectedTiles.Add(currentLayer.transform.GetChild(i).gameObject); } } } }
public static void eraseTile(Vector3 position) { if (YuME_mapEditor.findTileMapParent()) { GameObject currentLayer = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1]; Vector3 tempVec3; for (int i = 0; i < currentLayer.transform.childCount; ++i) { tempVec3 = currentLayer.transform.GetChild(i).transform.position; if (tempVec3.x == position.x && tempVec3.z == position.z && tempVec3.y >= position.y && tempVec3.y < position.y + 1f) { Undo.DestroyObjectImmediate(currentLayer.transform.GetChild(i).gameObject); EditorSceneManager.MarkAllScenesDirty(); return; } } } }
public static void cleanSceneOfBrushObjects() { if (YuME_mapEditor.findTileMapParent()) { List <GameObject> destroyList = new List <GameObject>(); foreach (Transform child in YuME_mapEditor.tileMapParent.transform) { if (child.gameObject.name == "YuME_brushTile") { destroyList.Add(child.gameObject); } } foreach (GameObject tileToDestory in destroyList) { DestroyImmediate(tileToDestory); } } }
// Need to keep this for legacy custom brushes // NOTE: I have removed the UNDO. This is for stability issues. public static void pasteCustomBrush(Vector3 position) { if (YuME_mapEditor.brushTile != null) { if (YuME_mapEditor.findTileMapParent()) { int badTileCount = 0; foreach (Transform child in YuME_mapEditor.brushTile.transform) { GameObject pasteTile = PrefabUtility.InstantiatePrefab(getPrefabFromCurrentTiles(child.gameObject) as GameObject) as GameObject; if (pasteTile != null) { child.position = normalizePosition(child.position); YuME_tileFunctions.eraseTile(child.position); pasteTile.transform.eulerAngles = child.eulerAngles; pasteTile.transform.position = child.position; pasteTile.transform.localScale = child.transform.lossyScale; pasteTile.transform.parent = YuME_mapEditor.mapLayers[YuME_mapEditor.currentLayer - 1].transform; } else { badTileCount++; } } if (badTileCount > 0) { Debug.Log("Custom Brush includes tiles from a different tile set. These tiles will not appear in the scene due to the lack of nested prefabs in Unity."); } EditorSceneManager.MarkAllScenesDirty(); } } }
static void Initialize() { YuME_mapEditor tileMapEditorWindow = EditorWindow.GetWindow <YuME_mapEditor>(false, "Map Editor"); tileMapEditorWindow.titleContent.text = "Map Editor"; }
public static void saveFrozenMesh(string path) { path = YuTools_Utils.shortenAssetPath(path); int counter = 1; if (YuME_mapEditor.findTileMapParent()) { foreach (Transform child in YuME_mapEditor.tileMapParent.transform) { if (child.gameObject.name == "frozenMap") { GameObject saveMap = Instantiate(child.gameObject); saveMap.name = YuME_mapEditor.tileMapParent.name; if (!AssetDatabase.IsValidFolder(path + "/" + saveMap.name + "Meshes")) { AssetDatabase.CreateFolder(path, saveMap.name + "Meshes"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } EditorUtility.ClearProgressBar(); foreach (Transform frozenMesh in saveMap.transform) { EditorUtility.DisplayProgressBar("Saving Meshes", "Saving Mesh " + (counter) + ". This might take some time", 1); Mesh saveMesh = Object.Instantiate(frozenMesh.GetComponent <MeshFilter>().sharedMesh) as Mesh; //Unwrapping.GenerateSecondaryUVSet(saveMesh); try { AssetDatabase.CreateAsset(saveMesh, path + "/" + saveMap.name + "Meshes/" + frozenMesh.name + counter + ".asset"); } catch { Debug.LogWarning("Failed to create saved map. This is likely due to a new folder being created and Unity not refreshing the asset database. Please retry saving the map."); EditorUtility.ClearProgressBar(); return; } frozenMesh.GetComponent <MeshFilter>().mesh = saveMesh; counter++; } EditorUtility.ClearProgressBar(); Object prefabAlreadyCreated = AssetDatabase.LoadAssetAtPath(path + "/" + saveMap.name + ".prefab", typeof(GameObject)); if (prefabAlreadyCreated != null) #if UNITY_2018_3_OR_NEWER { PrefabUtility.SaveAsPrefabAssetAndConnect(saveMap, path + "/" + saveMap.name + ".prefab", InteractionMode.AutomatedAction); } #else { PrefabUtility.ReplacePrefab(saveMap, prefabAlreadyCreated, ReplacePrefabOptions.ReplaceNameBased); } #endif else #if UNITY_2018_3_OR_NEWER { PrefabUtility.SaveAsPrefabAsset(saveMap, path + "/" + saveMap.name + ".prefab"); } #else { PrefabUtility.CreatePrefab(path + "/" + saveMap.name + ".prefab", saveMap); } #endif AssetDatabase.SaveAssets(); if (saveMap != null) { DestroyImmediate(saveMap); } } } AssetDatabase.Refresh(); }
void OnEnable() { YuME_mapEditor.importTileSets(false); }
public static void createCustomBrush(string customBrushName) { subMeshCount = 0; YuME_tileFunctions.checkTileSelectionStatus(); GameObject tileParentObject = new GameObject(); tileParentObject.AddComponent <YuME_tileGizmo>(); tileParentObject.GetComponent <YuME_tileGizmo>().customBrushMeshName = new List <string>(); string customBrushGUID = Guid.NewGuid().ToString("N"); tileParentObject.name = customBrushName + "_YuME.prefab"; string destinationPath = YuTools_Utils.getAssetPath(YuME_mapEditor.availableTileSets[YuME_mapEditor.currentTileSetIndex]) + "CustomBrushes/"; if (YuME_mapEditor.selectedTiles.Count > 0) { // When creating a custom brush we need to find the lowest Z transform in the selection to become the pivot transform GameObject bottomLevelOfSelection = YuME_mapEditor.selectedTiles[0]; foreach (GameObject checkObjects in YuME_mapEditor.selectedTiles) { if (checkObjects.transform.position.z < bottomLevelOfSelection.transform.position.z) { bottomLevelOfSelection = checkObjects; } } // center the parent object around the lowest block to make sure all the selected brushes are centered around the parent tileParentObject.transform.position = bottomLevelOfSelection.transform.position; // New Custom Brush implementation. Uses a technique similar to the freeze map, except for selected tils List <GameObject> tilesToCombine = new List <GameObject>(); List <Transform> _freezeTiles = new List <Transform>(); List <Transform> freezeTiles = new List <Transform>(); foreach (GameObject tile in YuME_mapEditor.selectedTiles) { tile.GetComponentsInChildren <Transform>(false, _freezeTiles); freezeTiles.AddRange(_freezeTiles); } foreach (Transform tile in freezeTiles) { if (tile.GetComponent <MeshRenderer>()) { tilesToCombine.Add(tile.gameObject); } } 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, tileParentObject, destinationPath, customBrushGUID); combine = new List <CombineInstance>(); } if (mesh.GetComponent <MeshRenderer>().sharedMaterial.name != previousMaterial.name) { newSubMesh(combine, previousMaterial, tileParentObject, destinationPath, customBrushGUID); 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, tileParentObject, destinationPath, customBrushGUID); tileParentObject.transform.position = Vector3.zero; // Add the prefab to the project #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(tileParentObject, destinationPath + tileParentObject.name); #else PrefabUtility.CreatePrefab(destinationPath + tileParentObject.name, tileParentObject); #endif AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); // refesh the asset database to tell unity changes have been made // remove our temporary builder object Debug.Log("Custom Brush " + tileParentObject.name + " created."); DestroyImmediate(tileParentObject); YuME_mapEditor.selectedTiles.Clear(); // reload the custom brushes YuME_mapEditor.loadCustomBrushes(); } }
public static void checkKeyboardShortcuts(Event keyEvent) { YuME_mapEditor.eraseToolOverride = false; YuME_mapEditor.pickToolOverride = false; if (keyEvent.shift && !keyEvent.control && !keyEvent.alt) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.eraseToolOverride = true; } } else if (keyEvent.control && !keyEvent.alt && !keyEvent.shift) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.pickToolOverride = true; } } if (keyEvent.type == EventType.keyDown) { switch (keyEvent.keyCode) { case KeyCode.Escape: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.defaultTools; break; case KeyCode.A: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.S: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.D: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; case KeyCode.Equals: Event.current.Use(); YuME_mapEditor.gridHeight++; break; case KeyCode.Minus: Event.current.Use(); YuME_mapEditor.gridHeight--; break; case KeyCode.LeftBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.LeftArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.DownArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y -= 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.UpArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y += 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.Return: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); YuME_mapEditor.setTileBrush(0); YuME_mapEditor.brushSize = Vector3.one; SceneView.RepaintAll(); } break; case KeyCode.Z: Event.current.Use(); YuME_mapEditor.tileRotation -= 90f; break; case KeyCode.X: Event.current.Use(); YuME_mapEditor.tileRotation += 90f; break; case KeyCode.I: Event.current.Use(); YuME_tileFunctions.isolateTilesToggle(); break; case KeyCode.C: Event.current.Use(); YuME_tileFunctions.flipVertical(); break; case KeyCode.V: Event.current.Use(); YuME_tileFunctions.flipHorizontal(); break; case KeyCode.Space: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.selectTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.defaultTools) { Event.current.Use(); YuME_tileFunctions.selectAllTiles(); } break; } } }
public static void checkKeyboardShortcuts(Event keyEvent) { YuME_mapEditor.eraseToolOverride = false; YuME_mapEditor.pickToolOverride = false; if (keyEvent.shift && !keyEvent.control && !keyEvent.alt) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.eraseToolOverride = true; } } else if (keyEvent.control && !keyEvent.alt && !keyEvent.shift) { if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { YuME_mapEditor.pickToolOverride = true; } } if (keyEvent.type == EventType.KeyDown) { switch (keyEvent.keyCode) { case KeyCode.Escape: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.defaultTools; YuME_mapEditor.currentBrushType = YuME_mapEditor.brushTypes.standardBrush; break; case KeyCode.Equals: Event.current.Use(); YuME_mapEditor.gridHeight += YuME_mapEditor.globalScale; break; case KeyCode.Minus: Event.current.Use(); YuME_mapEditor.gridHeight -= YuME_mapEditor.globalScale; break; case KeyCode.LeftBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightBracket: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.LeftArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.RightArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.x += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } break; case KeyCode.DownArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y -= 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z -= 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.UpArrow: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { if (Event.current.shift) { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.y += 1; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } else { Event.current.Use(); Vector3 newBrushSize = YuME_mapEditor.brushSize; newBrushSize.z += 2; YuME_mapEditor.brushSize = newBrushSize; SceneView.RepaintAll(); } } break; case KeyCode.Return: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.eraseTool) { Event.current.Use(); YuME_mapEditor.setTileBrush(0); YuME_mapEditor.brushSize = Vector3.one; YuME_mapEditor.selectedTiles.Clear(); SceneView.RepaintAll(); } else { Event.current.Use(); YuME_mapEditor.selectedTiles.Clear(); SceneView.RepaintAll(); } break; case KeyCode.Z: Event.current.Use(); YuME_mapEditor.tileRotation -= 90f; break; case KeyCode.X: Event.current.Use(); YuME_mapEditor.tileRotation += 90f; break; case KeyCode.E: if (keyEvent.shift) { YuME_mapEditor.gridHeight -= YuME_mapEditor.globalScale * YuME_mapEditor.editorPreferences.gridLayerHeightScaler; } else { YuME_mapEditor.gridHeight += YuME_mapEditor.globalScale * YuME_mapEditor.editorPreferences.gridLayerHeightScaler; } break; case KeyCode.I: Event.current.Use(); YuME_tileFunctions.isolateTilesToggle(); break; case KeyCode.C: Event.current.Use(); YuME_tileFunctions.flipVertical(); break; case KeyCode.V: Event.current.Use(); YuME_tileFunctions.flipHorizontal(); break; case KeyCode.B: Event.current.Use(); YuME_mapEditor.tileRotationX -= 90f; break; case KeyCode.N: Event.current.Use(); YuME_mapEditor.tileRotationX += 90f; break; case KeyCode.Space: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.selectTool || YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.defaultTools) { Event.current.Use(); YuME_tileFunctions.selectAllTiles(); } break; case KeyCode.R: if (YuME_mapEditor.selectedTool == YuME_mapEditor.toolIcons.brushTool) { Event.current.Use(); YuME_mapEditor.randomRotationMode = !YuME_mapEditor.randomRotationMode; } break; } if (!YuME_mapEditor.editorPreferences.useAlternativeKeyShortcuts) { switch (keyEvent.keyCode) { case KeyCode.A: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.S: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.D: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; } } else { switch (keyEvent.keyCode) { case KeyCode.G: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.brushTool; break; case KeyCode.H: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.pickTool; break; case KeyCode.J: Event.current.Use(); YuME_mapEditor.selectedTool = YuME_mapEditor.toolIcons.eraseTool; break; } } } }