Пример #1
0
    void OnClickSavePrefab()
    {
        customBrushName = customBrushName.Trim();

        if (string.IsNullOrEmpty(customBrushName))
        {
            EditorUtility.DisplayDialog("Unable to save custom Brush", "Please specify a valid custom brush name.", "Close");
            return;
        }

        YuME_customBrushFunctions.createCustomBrush(customBrushName);

        Close();
    }
Пример #2
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;
        }
    }