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 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 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 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 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 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); } } } } } }
// ---------------------------------------------------------------------------------------------------- // ----- 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; } } }
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 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); } } }
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; } } } }
// 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(); } } }
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(); }