Exemplo n.º 1
0
    public static void eraseTiles()
    {
        if (standardBrushSize)
        {
            YuME_tileFunctions.eraseTile(tilePosition);
        }
        else
        {
            Vector3 newTilePos = tilePosition;

            for (int y = 0; y < (int)brushSize.y; y++)
            {
                newTilePos.y = tilePosition.y + y;
                newTilePos.z = tilePosition.z - ((brushSize.z - 1) / 2);

                for (int z = 0; z < (int)brushSize.z; z++)
                {
                    newTilePos.x = tilePosition.x - ((brushSize.x - 1) / 2);
                    for (int x = 0; x < (int)brushSize.x; x++)
                    {
                        YuME_tileFunctions.eraseTile(newTilePos);
                        newTilePos.x++;
                    }
                    newTilePos.z++;
                }
            }
        }
    }
    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 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 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;
            }
        }
    }
    // 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();
            }
        }
    }
Exemplo n.º 6
0
    // ----------------------------------------------------------------------------------------------------
    // ----- Draw Scene Tools
    // ----------------------------------------------------------------------------------------------------

    static void OnSceneGUI(SceneView sceneView)
    {
        if (toolEnabled)
        {
            // ----------------------------------------------------------------------------------------------------
            // ----- Draw Scene Editor Tools
            // ----------------------------------------------------------------------------------------------------

            if (selectedTool > 0 && toolEnabled)
            {
                controlId = GUIUtility.GetControlID(FocusType.Passive);
                updateSceneMousePosition();
                checkTilePositionIsValid(sceneView.position);
                YuME_sceneGizmoFunctions.drawBrushGizmo();
            }

            // ----------------------------------------------------------------------------------------------------
            // ----- Draw Editor Tool Bar
            // ----------------------------------------------------------------------------------------------------

            YuME_editorSceneUI.drawToolUI(sceneView);

            // ----------------------------------------------------------------------------------------------------
            // ----- Check Keyboard and Mouse Shortcuts
            // ----------------------------------------------------------------------------------------------------

            YuME_keyboardShortcuts.checkKeyboardShortcuts(Event.current);
            YuME_mouseShorcuts.checkMouseShortcuts(Event.current);

            foreach (GameObject selected in selectedTiles)
            {
                if (selected != null)
                {
                    YuME_sceneGizmoFunctions.drawSceneGizmoCube(selected.transform.position, Vector3.one, Color.green);
                }
            }

            // ----------------------------------------------------------------------------------------------------
            // ----- Momenteray handling of the editor tool bar
            // ----------------------------------------------------------------------------------------------------

            switch (selectedTool)
            {
            case toolIcons.defaultTools:
                YuME_brushFunctions.destroyBrushTile();
                break;

            case toolIcons.brushTool:
                YuME_brushFunctions.createBrushTile();
                selectedTiles.Clear();
                break;

            case toolIcons.pickTool:
                YuME_brushFunctions.destroyBrushTile();
                selectedTiles.Clear();
                break;

            case toolIcons.eraseTool:
                YuME_brushFunctions.destroyBrushTile();
                selectedTiles.Clear();
                break;

            case toolIcons.selectTool:
                YuME_brushFunctions.destroyBrushTile();
                break;

            case toolIcons.copyTool:
                YuME_customBrushFunctions.createCopyBrush(false);
                selectedTool = toolIcons.brushTool;
                break;

            case toolIcons.moveTool:
                YuME_customBrushFunctions.createCopyBrush(true);
                selectedTool = toolIcons.brushTool;
                break;

            case toolIcons.trashTool:
                YuME_tileFunctions.trashTiles();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.customBrushTool:
                YuME_customBrushFunctions.createCustomBrush();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.showGizmos:
                showGizmos = !showGizmos;
                YuTools_Utils.disableTileGizmo(showGizmos);
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.gridUpTool:
                if (Event.current.alt)
                {
                    gridHeight += 0.25f;
                }
                else
                {
                    gridHeight++;
                }
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.gridDownTool:
                if (Event.current.alt)
                {
                    gridHeight -= 0.25f;
                }
                else
                {
                    gridHeight--;
                }
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.rotateTool:
                tileRotation += 90f;
                selectedTool  = previousSelectedTool;
                break;

            case toolIcons.flipHorizontalTool:
                YuME_tileFunctions.flipHorizontal();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.flipVerticalTool:
                YuME_tileFunctions.flipVertical();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.isolateTool:
                YuME_tileFunctions.isolateTilesToggle();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.isolateLayerTool:
                YuME_tileFunctions.isolateLayerToggle();
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.layerUp:
                currentLayer++;
                selectedTool = previousSelectedTool;
                break;

            case toolIcons.layerDown:
                currentLayer--;
                selectedTool = previousSelectedTool;
                break;
            }

            // ----------------------------------------------------------------------------------------------------
            // ----- Check Scene View Inputs for Drawing, Picking etc.
            // ----------------------------------------------------------------------------------------------------

            if (selectedTool > toolIcons.defaultTools)
            {
                if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) &&
                    Event.current.button == 0 &&
                    Event.current.alt == false &&
                    Event.current.shift == false &&
                    Event.current.control == false &&
                    allowTileRedraw)
                {
                    switch (selectedTool)
                    {
                    case toolIcons.brushTool:
                        switch (currentBrushType)
                        {
                        case brushTypes.standardBrush:
                            addTiles();
                            break;

                        case brushTypes.customBrush:
                            YuME_customBrushFunctions.pasteCustomBrush(tilePosition);
                            break;

                        case brushTypes.copyBrush:
                            YuME_customBrushFunctions.pasteCopyBrush(tilePosition);
                            break;
                        }
                        break;

                    case toolIcons.pickTool:
                        YuME_tileFunctions.pickTile(tilePosition);
                        break;

                    case toolIcons.eraseTool:
                        eraseTiles();
                        break;

                    case toolIcons.selectTool:
                        YuME_tileFunctions.selectTile(tilePosition);
                        break;
                    }

                    allowTileRedraw = false;
                }
                else if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) &&
                         Event.current.button == 0 &&
                         Event.current.alt == false &&
                         Event.current.shift == true &&
                         Event.current.control == false &&
                         allowTileRedraw)
                {
                    switch (selectedTool)
                    {
                    case toolIcons.brushTool:
                        eraseTiles();
                        break;
                    }

                    allowTileRedraw = false;
                }
                else if ((Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) &&
                         Event.current.button == 0 &&
                         Event.current.alt == false &&
                         Event.current.shift == false &&
                         Event.current.control == true &&
                         allowTileRedraw)
                {
                    switch (selectedTool)
                    {
                    case toolIcons.brushTool:
                        YuME_tileFunctions.pickTile(tilePosition);
                        break;

                    case toolIcons.selectTool:
                        YuME_tileFunctions.deSelectTile(tilePosition);
                        break;
                    }

                    allowTileRedraw = false;
                }

                HandleUtility.AddDefaultControl(controlId);
            }

            if (showGizmos)
            {
                if (selectedTiles.Count > 0)
                {
                    foreach (GameObject tile in selectedTiles)
                    {
                        YuME_sceneGizmoFunctions.handleInfo data;
                        data.tileName = tile.name;
                        data.layer    = tile.transform.parent.name;
                        data.grid     = tile.transform.position.y;
                        YuME_sceneGizmoFunctions.drawTileInfo(tile.transform.position, data);
                    }
                }
            }

            // ----------------------------------------------------------------------------------------------------
            // ----- Scene Housekeeping
            // ----------------------------------------------------------------------------------------------------

            YuME_brushFunctions.updateBrushPosition();
            repaintSceneView();
            previousSelectedTool = selectedTool;
        }
    }
Exemplo n.º 7
0
    void mainGUI()
    {
        if (Event.current != null)
        {
            // ----------------------------------------------------------------------------------------------------
            // ----- Check Keyboard and Mouse Shortcuts
            // ----------------------------------------------------------------------------------------------------

            YuME_keyboardShortcuts.checkKeyboardShortcuts(Event.current);
            YuME_mouseShorcuts.checkMouseShortcuts(Event.current);

            SceneView.RepaintAll();
        }

        EditorGUILayout.Space();

        GUILayout.Label(editorData.mapEditorHeader);

        EditorGUILayout.BeginVertical("box");

        if (GUILayout.Button("Get the full version of YuME", GUILayout.Height(30)))
        {
            Application.OpenURL("http://u3d.as/DrF");
        }

        EditorGUILayout.BeginHorizontal();

        toolEnabled = GUILayout.Toggle(toolEnabled, "Enable YuME", "Button", GUILayout.Height(30));

        if (_toolEnabled != toolEnabled)
        {
            if (!toolEnabled)
            {
                YuTools_Utils.showUnityGrid(true);
                YuME_tileFunctions.restoreIsolatedGridTiles();
                YuME_tileFunctions.restoreIsolatedLayerTiles();
            }
            else
            {
                setTileBrush(0);
                YuTools_Utils.showUnityGrid(false);
            }

            SceneView.RepaintAll();
        }

        _toolEnabled = toolEnabled;

        openConfig = GUILayout.Toggle(openConfig, editorData.configButton, "Button", GUILayout.Width(30), GUILayout.Height(30));

        if (openConfig == true)
        {
            YuME_editorConfig editorConfig = EditorWindow.GetWindow <YuME_editorConfig>(true, "Editor Config");
            editorConfig.titleContent.text = "Editor Config";
        }

        openConfig = false;

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("box");
        gridDimensions = EditorGUILayout.Vector2Field("Grid Dimensions", gridDimensions);
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("box");
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Grid Height: " + gridHeight.ToString());
        GUILayout.Label("Brush Size: (" + brushSize.x.ToString() + "," + brushSize.y.ToString() + "," + brushSize.z.ToString() + ")");
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("box");
        EditorGUILayout.LabelField("Pick The Tile Set To Use", EditorStyles.boldLabel);
        currentTileSetIndex = EditorGUILayout.Popup("Choose Tileset", currentTileSetIndex, tileSetNames);

        if (currentTileSetIndex != _currentTileSetIndex)
        {
            loadPreviewTiles();
        }

        if (GUILayout.Button("Reload Available Tilesets", GUILayout.Height(30)))
        {
            importTileSets(true);
            loadCustomBrushes();
            loadPreviewTiles(); // this is in the wrong place - it needs to be triggered when the user picks a new tileset
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical("box");

        string[] buttonLabels = new string[] { "Tileset Brushes", "Custom Brushes" };

        brushPallete = (brushOptions)GUILayout.SelectionGrid(
            (int)brushPallete,
            buttonLabels,
            2,
            EditorStyles.toolbarButton
            );

        EditorGUILayout.EndVertical();

        drawTilePreviews();

        EditorGUILayout.BeginVertical("box");

        EditorGUILayout.LabelField("Tile Previw Columns", EditorStyles.boldLabel);
        tilePreviewColumnWidth = EditorGUILayout.IntSlider(tilePreviewColumnWidth, 1, 10);

        EditorGUILayout.EndVertical();

        updateGridColors();
        YuME_sceneGizmoFunctions.displayGizmoGrid();

        _currentTileSetIndex = currentTileSetIndex;
    }
    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;
                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;
                }
            }
        }
    }
Exemplo n.º 10
0
    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;
            }
        }
    }