コード例 #1
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;
            }
        }
    }
コード例 #2
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();
            }
        }
    }
コード例 #3
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();
            }
        }
    }
コード例 #4
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();
        }
    }
コード例 #5
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;
                }
            }
        }
    }