Пример #1
0
    public static void updateBrushTile(Vector3 tileScale)
    {
        if (MAP_Editor.findTileMapParent() && MAP_Editor.toolEnabled)
        {
            destoryBrushTile();
            MAP_Editor.brushTile = Instantiate(MAP_Editor.currentTile, Vector3.one, Quaternion.identity) as GameObject;
            MAP_Editor.brushTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0);
            MAP_Editor.brushTile.transform.parent      = MAP_Editor.tileMapParent.transform;
            MAP_Editor.brushTile.transform.localScale  = tileScale;
            MAP_Editor.brushTile.name      = Define.MAP_BRUSH_TILE;
            MAP_Editor.brushTile.hideFlags = HideFlags.HideAndDontSave;
            MAP_Editor.brushTile.isStatic  = false;

            foreach (Transform child in MAP_Editor.brushTile.transform)
            {
                child.gameObject.isStatic = false;
            }
            MAP_Editor.tileChildObjects.Clear();
            foreach (Transform child in MAP_Editor.brushTile.transform)
            {
                MAP_Editor.tileChildObjects.Add(child.gameObject);
            }
            MAP_Editor.showWireBrush = false;
        }
    }
Пример #2
0
 public static void displayGizmoGrid()
 {
     if (MAP_Editor.findEditorGameObject())
     {
         MAP_Editor.editorGameobject.GetComponent<MAP_GizmoGrid>().gridOffset = MAP_Editor.editorPreferences.gridOffset;
         MAP_Editor.editorGameobject.GetComponent<MAP_GizmoGrid>().toolEnable = MAP_Editor.toolEnabled;
     }
 }
Пример #3
0
    private void OnGUI()
    {
        EditorGUILayout.Space();
        _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
        EditorGUILayout.BeginVertical(Define.BOX);

        EditorGUILayout.LabelField("new map name", EditorStyles.boldLabel);

        newMapName = EditorGUILayout.TextField(newMapName);


        if (GUILayout.Button("add new map", GUILayout.Height(20)))
        {
            Map_mapManagerFunctions.buildNewMap(newMapName);
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(Define.BOX);

        for (int i = 0; i < MAP_Editor.ref_MapManager.mapList.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();

            MAP_Editor.ref_MapManager.mapList[i].name = EditorGUILayout.TextField(MAP_Editor.ref_MapManager.mapList[i].name, GUILayout.Width(200));
            if (i != 0)
            {
                if (GUILayout.Button("close map", GUILayout.Height(20), GUILayout.Width(75)))
                {
                    MAP_Editor.cloneMap(MAP_Editor.ref_MapManager.mapList[i]);
                    EditorSceneManager.MarkAllScenesDirty();
                }
                if (GUILayout.Button("delete map", GUILayout.Height(20), GUILayout.Width(75)))
                {
                    DestroyImmediate(MAP_Editor.ref_MapManager.mapList[i]);
                    MAP_Editor.ref_MapManager.mapList.RemoveAt(i);
                    MAP_Editor.currentMapIndex = 0;
                    EditorSceneManager.MarkAllScenesDirty();
                }
            }
            else
            {
                if (GUILayout.Button("clone map", GUILayout.Height(20), GUILayout.Width(75)))
                {
                    MAP_Editor.cloneMap(MAP_Editor.ref_MapManager.mapList[i]);
                    EditorSceneManager.MarkAllScenesDirty();
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.EndScrollView();
    }
Пример #4
0
    public static void refreshMap()
    {
        Vector3 tempVec3;

        if (MAP_Editor.findTileMapParent())
        {
            foreach (Transform layer in MAP_Editor.tileMapParent.transform)
            {
                foreach (Transform tile in layer)
                {
                    tempVec3 = tile.localScale;
                    if (tempVec3.x != MAP_Editor.editorPreferences.gridScaleFactor)
                    {
                        if (tempVec3.x < 0)
                        {
                            tempVec3.x = MAP_Editor.editorPreferences.gridScaleFactor * -1;
                        }
                        else
                        {
                            tempVec3.x = MAP_Editor.editorPreferences.gridScaleFactor;
                        }
                    }

                    if (tempVec3.y != MAP_Editor.editorPreferences.gridScaleFactor)
                    {
                        if (tempVec3.y < 0)
                        {
                            tempVec3.y = MAP_Editor.editorPreferences.gridScaleFactor * -1;
                        }
                        else
                        {
                            tempVec3.y = MAP_Editor.editorPreferences.gridScaleFactor;
                        }
                    }

                    if (tempVec3.z != MAP_Editor.editorPreferences.gridScaleFactor)
                    {
                        if (tempVec3.z < 0)
                        {
                            tempVec3.z = MAP_Editor.editorPreferences.gridScaleFactor * -1;
                        }
                        else
                        {
                            tempVec3.z = MAP_Editor.editorPreferences.gridScaleFactor;
                        }
                    }

                    tile.localScale = tempVec3;
                }
            }
        }
    }
Пример #5
0
    public static void addTile(Vector3 position)
    {
        GameObject placedTile;

        if (MAP_Editor.findTileMapParent())
        {
            if (MAP_Editor.useAltTiles == true)
            {
                s_AltTiles checkAltTiles = new s_AltTiles();
                try
                {
                    checkAltTiles = MAP_Editor.altTiles.Single(s => s.masterTile == MAP_Editor.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(MAP_Editor.currentTile as GameObject) as GameObject;
                    }
                }
                else
                {
                    placedTile = PrefabUtility.InstantiatePrefab(MAP_Editor.currentTile as GameObject) as GameObject;
                }
            }
            else
            {
                placedTile = PrefabUtility.InstantiatePrefab(MAP_Editor.currentTile as GameObject) as GameObject;
            }

            Undo.RegisterCreatedObjectUndo(placedTile, Define.MAP_PLACED_TILE);
            if (MAP_Editor.randomRotationMode)
            {
                placedTile.transform.eulerAngles = new Vector3(UnityEngine.Random.Range(0, 4) * 90, UnityEngine.Random.Range(0, 4) * 90, UnityEngine.Random.Range(0, 4) * 90);
            }
            else
            {
                placedTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0);
            }

            placedTile.transform.position   = position;
            placedTile.transform.localScale = MAP_Editor.brushTile.transform.localScale;
            placedTile.transform.parent     = MAP_Editor.mapLayers[MAP_Editor.currentLayer - 1].transform;
        }
        EditorSceneManager.MarkAllScenesDirty();
    }
Пример #6
0
    public static void createCopyBrush(bool destroySourceTiles)
    {
        MAP_tileFunctions.checkTileSelectionStatus();

        if (MAP_Editor.currentBrushType != eBrushTypes.copyBrush && MAP_Editor.selectTiles.Count > 0)
        {
            MAP_Editor.currentBrushType = eBrushTypes.copyBrush;

            if (MAP_Editor.brushTile != null)
            {
                DestroyImmediate(MAP_Editor.brushTile);
            }

            if (MAP_Editor.findTileMapParent())
            {
                Undo.RegisterFullObjectHierarchyUndo(MAP_Editor.tileMapParent, "Create Brush");

                MAP_Editor.brushTile = new GameObject();
                MAP_Editor.brushTile.transform.eulerAngles = new Vector3(MAP_Editor.tileRotationX, MAP_Editor.tileRotation, 0f);
                MAP_Editor.brushTile.transform.parent      = MAP_Editor.tileMapParent.transform;
                MAP_Editor.brushTile.name = "YuME_brushTile";

                MAP_Editor.brushTile.transform.position = MAP_Editor.selectTiles[0].transform.position;

                MAP_Editor.tileChildObjects.Clear();

                foreach (GameObject tile in MAP_Editor.selectTiles)
                {
#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      = MAP_Editor.brushTile.transform;
                    tempTile.transform.position    = tile.transform.position;
                    tempTile.transform.eulerAngles = tile.transform.eulerAngles;
                    tempTile.transform.localScale  = tile.transform.localScale;

                    MAP_Editor.tileChildObjects.Add(tempTile);

                    if (destroySourceTiles)
                    {
                        DestroyImmediate(tile);
                    }
                }

                MAP_Editor.selectTiles.Clear();

                MAP_Editor.showWireBrush = false;
            }
        }
    }
Пример #7
0
    static void swapTileSet()
    {
        string path = MAPTools_Utils.getAssetsPath(MAP_Editor.availableTileSets[swapTileSetIndex]);

        swapTileSetObjects = MAPTools_Utils.loadDirectoryContents(path, "*.prefab");

        List <GameObject> layerTiles = new List <GameObject>();

        if (swapTileSetObjects != null)
        {
            GameObject swapTile;

            if (MAP_Editor.findTileMapParent())
            {
                Undo.RegisterFullObjectHierarchyUndo(MAP_Editor.tileMapParent, "Swap Tiles");

                foreach (Transform layer in MAP_Editor.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;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Пример #8
0
 public static void isolateLayerTiles()
 {
     restoreIsolatedLayerTiles();
     if (MAP_Editor.findTileMapParent())
     {
         foreach (Transform item in MAP_Editor.tileMapParent.transform)
         {
             if (item.name != string.Format("layer{0}", MAP_Editor.currentLayer))
             {
                 item.gameObject.SetActive(false);
                 MAP_Editor.isolataLayerObjects.Add(item.gameObject);
             }
         }
     }
 }
Пример #9
0
    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;
                }
            }
        }
    }
Пример #10
0
 public static void selectAllTiles()
 {
     if (MAP_Editor.findTileMapParent())
     {
         GameObject currentLayer = MAP_Editor.mapLayers[MAP_Editor.currentLayer - 1];
         if (MAP_Editor.selectTiles.Count > 0)
         {
             MAP_Editor.selectTiles.Clear();
         }
         else
         {
             for (int i = 0; i < currentLayer.transform.childCount; i++)
             {
                 MAP_Editor.selectTiles.Add(currentLayer.transform.GetChild(i).gameObject);
             }
         }
     }
 }
Пример #11
0
 public static void cleanSceneOfBrushObjects()
 {
     if (MAP_Editor.findTileMapParent())
     {
         List <GameObject> destoryList = new List <GameObject>();
         foreach (Transform child in MAP_Editor.tileMapParent.transform)
         {
             if (child.name == Define.MAP_BRUSH_TILE)
             {
                 destoryList.Add(child.gameObject);
             }
         }
         foreach (GameObject obj in destoryList)
         {
             DestroyImmediate(obj);
         }
     }
 }
Пример #12
0
    public static void eraseTile(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 (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;
                }
            }
        }
    }
Пример #13
0
    public static void pasteCopyBrush(Vector3 position)
    {
        if (MAP_Editor.brushTile != null)
        {
            if (MAP_Editor.findTileMapParent())
            {
                Undo.RegisterFullObjectHierarchyUndo(MAP_Editor.tileMapParent, Define.PAINT_BRUSH);

                foreach (Transform child in MAP_Editor.brushTile.transform)
                {
                    GameObject pasteTile = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject) as GameObject);
                    MAP_tileFunctions.eraseTile(child.position);
                    pasteTile.transform.eulerAngles = child.eulerAngles;
                    pasteTile.transform.position    = normalizePosition(child.position);
                    pasteTile.transform.localScale  = child.transform.lossyScale;
                    pasteTile.transform.parent      = MAP_Editor.mapLayers[MAP_Editor.currentLayer - 1].transform;
                }
                EditorSceneManager.MarkAllScenesDirty();
            }
        }
    }
Пример #14
0
 public static void delSelectTile(Vector3 position)
 {
     if (MAP_Editor.findTileMapParent())
     {
         GameObject currentLayer = MAP_Editor.mapLayers[MAP_Editor.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).transform.name != Define.MAP_BRUSH_TILE)
             {
                 for (int t = 0; t < MAP_Editor.selectTiles.Count; t++)
                 {
                     if (currentLayer.transform.GetChild(i).transform.position == MAP_Editor.selectTiles[i].transform.position)
                     {
                         MAP_Editor.selectTiles.RemoveAt(t);
                         return;
                     }
                 }
             }
         }
     }
 }
Пример #15
0
 public static void isolateGridTiles()
 {
     restoreIsolatedGridTiles();
     if (MAP_Editor.findTileMapParent())
     {
         foreach (Transform layer in MAP_Editor.tileMapParent.transform)
         {
             foreach (Transform tile in layer)
             {
                 if (!MAP_Editor.editorPreferences.twoPointFiveDMode)
                 {
                     tile.gameObject.SetActive(false);
                     MAP_Editor.isolatedGridObjects.Add(tile.gameObject);
                 }
                 else
                 {
                     tile.gameObject.SetActive(false);
                     MAP_Editor.isolatedGridObjects.Add(tile.gameObject);
                 }
             }
         }
     }
 }
Пример #16
0
    // 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 (MAP_Editor.brushTile != null)
        {
            if (MAP_Editor.findTileMapParent())
            {
                int badTileCount = 0;

                foreach (Transform child in MAP_Editor.brushTile.transform)
                {
                    GameObject pasteTile = PrefabUtility.InstantiatePrefab(getPrefabFromCurrentTiles(child.gameObject) as GameObject) as GameObject;

                    if (pasteTile != null)
                    {
                        child.position = normalizePosition(child.position);
                        MAP_tileFunctions.eraseTile(child.position);
                        pasteTile.transform.eulerAngles = child.eulerAngles;
                        pasteTile.transform.position    = child.position;
                        pasteTile.transform.localScale  = child.transform.lossyScale;
                        pasteTile.transform.SetParent(MAP_Editor.mapLayers[MAP_Editor.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();
            }
        }
    }
Пример #17
0
 void OnEnable()
 {
     MAP_Editor.importTileSets(false);
 }
Пример #18
0
    public static void saveFrozenMesh(string path)
    {
        path = MAPTools_Utils.shortenAssetPath(path);
        int counter = 1;

        if (MAP_Editor.findTileMapParent())
        {
            foreach (Transform child in MAP_Editor.tileMapParent.transform)
            {
                if (child.gameObject.name == "frozenMap")
                {
                    GameObject saveMap = Instantiate(child.gameObject);
                    saveMap.name = MAP_Editor.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)
                    {
                        PrefabUtility.SaveAsPrefabAssetAndConnect(saveMap, path + "/" + saveMap.name + ".prefab", InteractionMode.AutomatedAction);
                    }
                    else
                    {
                        PrefabUtility.SaveAsPrefabAsset(saveMap, path + "/" + saveMap.name + ".prefab");
                    }
                    AssetDatabase.SaveAssets();
                    if (saveMap != null)
                    {
                        DestroyImmediate(saveMap);
                    }
                }
            }

            AssetDatabase.Refresh();
        }
    }
Пример #19
0
    public static void checkKeyboardShortcuts(Event keyEvent)
    {
        MAP_Editor.eraseToolOverride = false;
        MAP_Editor.pickToolOverride  = false;

        if (keyEvent.shift && !keyEvent.control && !keyEvent.alt)
        {
            if (MAP_Editor.selectTool == eToolIcons.brushTool)
            {
                MAP_Editor.eraseToolOverride = true;
            }
        }
        else if (keyEvent.control && !keyEvent.alt && !keyEvent.shift)
        {
            if (MAP_Editor.selectTool == eToolIcons.brushTool)
            {
                MAP_Editor.pickToolOverride = false;
            }
        }
        if (keyEvent.type == EventType.KeyDown)
        {
            switch (keyEvent.keyCode)
            {
            case KeyCode.Escape:
                Event.current.Use();
                MAP_Editor.selectTool       = eToolIcons.defaultTools;
                MAP_Editor.currentBrushType = eBrushTypes.standardBrush;
                break;

            case KeyCode.Equals:
                Event.current.Use();
                MAP_Editor.gridHeight += MAP_Editor.globalScale;
                break;

            case KeyCode.Minus:
                Event.current.Use();
                MAP_Editor.gridHeight -= MAP_Editor.globalScale;
                break;

            case KeyCode.LeftBracket:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    Event.current.Use();
                    Vector3 newBrushSize = MAP_Editor.brushSize;
                    newBrushSize.x      -= 2;
                    newBrushSize.z      -= 2;
                    MAP_Editor.brushSize = newBrushSize;
                    SceneView.RepaintAll();
                }
                break;

            case KeyCode.RightBracket:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    Event.current.Use();
                    Vector3 newBrushSize = MAP_Editor.brushSize;
                    newBrushSize.x      += 2;
                    newBrushSize.z      += 2;
                    MAP_Editor.brushSize = newBrushSize;
                    SceneView.RepaintAll();
                }
                break;

            case KeyCode.LeftArrow:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    Event.current.Use();
                    Vector3 newBrushSize = MAP_Editor.brushSize;
                    newBrushSize.x      -= 2;
                    MAP_Editor.brushSize = newBrushSize;
                    SceneView.RepaintAll();
                }
                break;

            case KeyCode.RightArrow:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    Event.current.Use();
                    Vector3 newBrushSize = MAP_Editor.brushSize;
                    newBrushSize.x      += 2;
                    MAP_Editor.brushSize = newBrushSize;
                    SceneView.RepaintAll();
                }
                break;

            case KeyCode.DownArrow:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    if (Event.current.shift)
                    {
                        Event.current.Use();
                        Vector3 newBrushSize = MAP_Editor.brushSize;
                        newBrushSize.y      -= 1;
                        MAP_Editor.brushSize = newBrushSize;
                        SceneView.RepaintAll();
                    }
                    else
                    {
                        Event.current.Use();
                        Vector3 newBrushSize = MAP_Editor.brushSize;
                        newBrushSize.z      -= 2;
                        MAP_Editor.brushSize = newBrushSize;
                        SceneView.RepaintAll();
                    }
                }
                break;

            case KeyCode.UpArrow:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    if (Event.current.shift)
                    {
                        Event.current.Use();
                        Vector3 newBrushSize = MAP_Editor.brushSize;
                        newBrushSize.y      += 1;
                        MAP_Editor.brushSize = newBrushSize;
                        SceneView.RepaintAll();
                    }
                    else
                    {
                        Event.current.Use();
                        Vector3 newBrushSize = MAP_Editor.brushSize;
                        newBrushSize.z      += 2;
                        MAP_Editor.brushSize = newBrushSize;
                        SceneView.RepaintAll();
                    }
                }
                break;

            case KeyCode.Return:
                if (MAP_Editor.selectTool == eToolIcons.brushTool || MAP_Editor.selectTool == eToolIcons.eraseTool)
                {
                    Event.current.Use();
                    MAP_Editor.setTileBrush(0);
                    MAP_Editor.brushSize = Vector3.one;
                    MAP_Editor.selectTiles.Clear();
                    SceneView.RepaintAll();
                }
                else
                {
                    Event.current.Use();
                    MAP_Editor.selectTiles.Clear();
                    SceneView.RepaintAll();
                }
                break;

            case KeyCode.Z:
                Event.current.Use();
                MAP_Editor.tileRotation -= 90f;
                break;

            case KeyCode.X:
                Event.current.Use();
                MAP_Editor.tileRotation += 90f;
                break;

            case KeyCode.I:
                Event.current.Use();
                MAP_tileFunctions.isolateTilesToggle();
                break;

            case KeyCode.C:
                Event.current.Use();
                MAP_tileFunctions.flipVertical();
                break;

            case KeyCode.V:
                Event.current.Use();
                MAP_tileFunctions.flipHorizontal();
                break;

            case KeyCode.B:
                Event.current.Use();
                MAP_Editor.tileRotationX -= 90f;
                break;

            case KeyCode.N:
                Event.current.Use();
                MAP_Editor.tileRotationX += 90f;
                break;

            case KeyCode.Space:
                if (MAP_Editor.selectTool == eToolIcons.selectTool || MAP_Editor.selectTool == eToolIcons.defaultTools)
                {
                    Event.current.Use();
                    MAP_tileFunctions.selectAllTiles();
                }
                break;

            case KeyCode.R:
                if (MAP_Editor.selectTool == eToolIcons.brushTool)
                {
                    Event.current.Use();
                    MAP_Editor.randomRotationMode = !MAP_Editor.randomRotationMode;
                }
                break;
            }


            if (!MAP_Editor.editorPreferences.useAlternativeKeyShortcuts)
            {
                switch (keyEvent.keyCode)
                {
                case KeyCode.A:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.brushTool;
                    break;

                case KeyCode.S:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.pickTool;
                    break;

                case KeyCode.D:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.eraseTool;
                    break;
                }
            }
            else
            {
                switch (keyEvent.keyCode)
                {
                case KeyCode.G:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.brushTool;
                    break;

                case KeyCode.H:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.pickTool;
                    break;

                case KeyCode.J:
                    Event.current.Use();
                    MAP_Editor.selectTool = eToolIcons.eraseTool;
                    break;
                }
            }
        }
    }
Пример #20
0
    public static void createCustomBrush(string customBrushName)
    {
        subMeshCount = 0;

        MAP_tileFunctions.checkTileSelectionStatus();

        GameObject tileParentObject = new GameObject();

        tileParentObject.AddComponent <MAP_tileGizmo>();
        tileParentObject.GetComponent <MAP_tileGizmo>().customBrushMeshName = new List <string>();

        string customBrushGUID = Guid.NewGuid().ToString("N");

        tileParentObject.name = customBrushName + Define.MAP_PREFAB;

        string destinationPath = MAPTools_Utils.getAssetsPath(MAP_Editor.availableTileSets[MAP_Editor.currentTileSetIndex]) + Define.CUSTOM_BRUSHFES + "/";

        if (MAP_Editor.selectTiles.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 = MAP_Editor.selectTiles[0];

            foreach (GameObject checkObjects in MAP_Editor.selectTiles)
            {
                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 MAP_Editor.selectTiles)
            {
                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);
            MAP_Editor.selectTiles.Clear();

            // reload the custom brushes
            MAP_Editor.loadCustomBrushes();
        }
    }