Example #1
0
    public void DisplayTreesGUI()
    {
        terrainNoiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves,
                                                 persistance, lacunarity, offset);

        treeMap.ClearAllEditorPreviewTiles();

        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                float currentHeight = terrainNoiseMap[x, y];


                if (currentHeight > tileTypes[1].height && currentHeight <= tileTypes[2].height)
                {
                    int random = Random.Range(0, 100);
                    if (random < 2)
                    {
                        treeMap.SetEditorPreviewTile(new Vector3Int(x, y, 0), appleTree);
                    }
                }
            }
        }
    }
Example #2
0
    public void DisplayMapGUI()
    {
        tileMap.ClearAllEditorPreviewTiles();

        terrainNoiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves,
                                                 persistance, lacunarity, offset);

        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                float currentHeight = terrainNoiseMap[x, y];

                for (int i = 0; i < tileTypes.Length; i++)
                {
                    if (currentHeight <= tileTypes[i].height)
                    {
                        //tileMap.SetTile(new Vector3Int(x, y, 0), tileTypes[i].tile);
                        tileMap.SetEditorPreviewTile(new Vector3Int(x, y, 0), tileTypes[i].tile);
                        break;
                    }
                }
            }
        }
    }
Example #3
0
    void ContinueAddDoor()
    {
        _tilemapInst.ClearAllEditorPreviewTiles();
        Vector3Int pos = _Bounds.ConstrainPointToBounds(curBounds, curMousePos);

        //pos = ConstrainPointToOuterBounds(curBounds, pos);
        _tilemapInst.SetEditorPreviewTile(pos, doorTilePrefab);
    }
        //Clear the Tilemap
        public void ClearTilemap()
        {
            Tilemap tilemap = SelectTilemapInScene();

            tilemap.ClearAllTiles();
            tilemap.ClearAllEditorPreviewTiles();
            WriteTemplateSquare();
        }
Example #5
0
        public override void OnMouseLeave()
        {
            if (tilemap != null)
            {
                tilemap.ClearAllEditorPreviewTiles();
            }

            base.OnMouseLeave();
        }
Example #6
0
 public override void ClearPreview()
 {
     base.ClearPreview();
     if (lastTilemap != null)
     {
         lastTilemap.ClearAllEditorPreviewTiles();
         lastTilemap = null;
     }
 }
Example #7
0
    public void ClearAll()
    {
        tileMap.ClearAllTiles();
        treeMap.ClearAllTiles();
        waterMap.ClearAllTiles();

        tileMap.ClearAllEditorPreviewTiles();
        treeMap.ClearAllEditorPreviewTiles();
        waterMap.ClearAllEditorPreviewTiles();
    }
Example #8
0
 public virtual void ClearPreview()
 {
     if (!(this.m_LastGrid == null))
     {
         BoundsInt?lastBounds = this.m_LastBounds;
         if (lastBounds.HasValue && !(this.m_LastBrushTarget == null))
         {
             GridBrushBase.Tool?lastTool = this.m_LastTool;
             if (lastTool.HasValue)
             {
                 Tilemap component = this.m_LastBrushTarget.GetComponent <Tilemap>();
                 if (component != null)
                 {
                     GridBrushBase.Tool?lastTool2 = this.m_LastTool;
                     if (lastTool2.HasValue)
                     {
                         GridBrushBase.Tool value = lastTool2.Value;
                         if (value != GridBrushBase.Tool.FloodFill)
                         {
                             if (value != GridBrushBase.Tool.Box)
                             {
                                 if (value == GridBrushBase.Tool.Paint)
                                 {
                                     foreach (Vector3Int current in this.m_LastBounds.Value.allPositionsWithin)
                                     {
                                         GridBrushEditor.ClearTilemapPreview(component, current);
                                     }
                                 }
                             }
                             else
                             {
                                 Vector3Int position  = this.m_LastBounds.Value.position;
                                 Vector3Int a         = position + this.m_LastBounds.Value.size;
                                 BoundsInt  boundsInt = new BoundsInt(position, a - position);
                                 foreach (Vector3Int current2 in boundsInt.allPositionsWithin)
                                 {
                                     GridBrushEditor.ClearTilemapPreview(component, current2);
                                 }
                             }
                         }
                         else
                         {
                             component.ClearAllEditorPreviewTiles();
                         }
                     }
                 }
                 this.m_LastBrushTarget = null;
                 this.m_LastGrid        = null;
                 this.m_LastBounds      = null;
                 this.m_LastTool        = null;
             }
         }
     }
 }
Example #9
0
        public override void OnPaintSceneGUI(GridLayout grid, GameObject brush_target, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            StampTileBrush brush    = (StampTileBrush)target;
            Tilemap        tile_map = brush_target.GetComponent <Tilemap>();

            base.OnPaintSceneGUI(grid, brush_target, position, tool, executing);

            tile_map.ClearAllEditorPreviewTiles();

            if (tool == GridBrushBase.Tool.Paint)
            {
                brush.PaintPreview(tile_map, position.min);
            }
        }
Example #10
0
        public override void OnPaintSceneGUI(IGridLayout grid, GameObject[] layers, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            base.OnPaintSceneGUI(grid, layers, position, tool, executing);
            if (lineBrush.lineStartActive)
            {
                foreach (GameObject go in layers)
                {
                    Tilemap tilemap = go.GetComponent <Tilemap>();
                    if (tilemap != null)
                    {
                        tilemap.ClearAllEditorPreviewTiles();
                    }
                }

                // Draw preview tiles for tilemap
                Vector2Int startPos = new Vector2Int(lineBrush.lineStart.x, lineBrush.lineStart.y);
                Vector2Int endPos   = new Vector2Int(position.x, position.y);
                if (startPos == endPos)
                {
                    brush.PaintPreview(grid, layers, position);
                }
                else
                {
                    foreach (var point in LineBrush.GetPointsOnLine(startPos, endPos))
                    {
                        Vector3Int paintPos   = new Vector3Int(point.x, point.y, position.z);
                        BoundsInt  previewPos = new BoundsInt(paintPos, position.size);
                        brush.PaintPreview(grid, layers, previewPos);
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    var min = lineBrush.lineStart;
                    var max = lineBrush.lineStart + position.size;

                    // Draws a box on the picked starting position
                    GL.PushMatrix();
                    GL.MultMatrix(GUI.matrix);
                    GL.Begin(GL.LINES);
                    Handles.color = Color.blue;
                    Handles.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(max.x, min.y, min.z));
                    Handles.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z));
                    Handles.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z));
                    Handles.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, min.y, min.z));
                    GL.End();
                    GL.PopMatrix();
                }
            }
        }
Example #11
0
        /// <summary>Clears any preview drawn previously by the GridBrushEditor.</summary>
        public virtual void ClearPreview()
        {
            if (m_LastGrid == null || m_LastBounds == null || m_LastBrushTarget == null || m_LastTool == null)
            {
                return;
            }

            Tilemap map = m_LastBrushTarget.GetComponent <Tilemap>();

            if (map != null)
            {
                switch (m_LastTool)
                {
                case GridBrushBase.Tool.FloodFill:
                {
                    map.ClearAllEditorPreviewTiles();
                    break;
                }

                case GridBrushBase.Tool.Box:
                {
                    Vector3Int min    = m_LastBounds.Value.position;
                    Vector3Int max    = min + m_LastBounds.Value.size;
                    BoundsInt  bounds = new BoundsInt(min, max - min);
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearTilemapPreview(map, location);
                    }
                    break;
                }

                case GridBrushBase.Tool.Paint:
                {
                    BoundsInt bounds = m_LastBounds.Value;
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearTilemapPreview(map, location);
                    }
                    break;
                }
                }
            }

            m_LastBrushTarget = null;
            m_LastGrid        = null;
            m_LastBounds      = null;
            m_LastTool        = null;
        }
Example #12
0
    private void ClearDungeon()
    {
        groundMap.ClearAllTiles();
        groundMap.ResizeBounds();
        groundMap.RefreshAllTiles();
        groundMap.ClearAllEditorPreviewTiles();

        pitMap.ClearAllTiles();
        pitMap.ResizeBounds();
        pitMap.RefreshAllTiles();
        pitMap.ClearAllEditorPreviewTiles();

        wallMap.ClearAllTiles();
        wallMap.ResizeBounds();
        wallMap.RefreshAllTiles();
        wallMap.ClearAllEditorPreviewTiles();
    }
Example #13
0
        public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            tilemap = brushTarget.GetComponent <Tilemap>();
            if (tilemap != null)
            {
                tilemap.ClearAllEditorPreviewTiles();
            }


            if (tool == GridBrushBase.Tool.Paint)
            {
                foreach (Vector3Int q in moduloBrush.GetQuadsForTile(position))
                {
                    base.PaintPreview(gridLayout, brushTarget, q);
                }
            }
        }
        // 複数Tilemapの移動ルーチン
        void MoveAllTilemapsRoutine(BoundsInt position, bool preview, bool moveStart = false)
        {
            ExBrushTarget[] ts = FindObjectsOfType <ExBrushTarget>();
            foreach (ExBrushTarget t in ts)
            {
                if (t.TilemapTarget && t.involved)
                {
                    Tilemap tilemap = t.GetComponent <Tilemap>();
                    tilemap.ClearAllEditorPreviewTiles();

                    GridLayout gl = t.GetComponentInParent <GridLayout>();
                    if (gl != null)
                    {
                        if (moveStart)
                        {
                            // position位置のタイルをカットしてcellsDictに格納する
                            cellsDict[t] = GetCells(tilemap, position, true);
                        }
                        SetCells(tilemap, position, cellsDict[t], preview);
                    }
                }
            }
        }
        private void DuringSceneGui(SceneView sceneView)
        {
            Event evt = Event.current;

            if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited && evt.type != EventType.Repaint)
            {
                return;
            }

            Grid activeGrid = GetActiveGrid();

            if (activeGrid == null || DragAndDrop.objectReferences.Length == 0)
            {
                return;
            }

            Vector3    localMouse        = GridEditorUtility.ScreenToLocal(activeGrid.transform, evt.mousePosition);
            Vector3Int mouseGridPosition = activeGrid.LocalToCell(localMouse);

            switch (evt.type)
            {
            //TODO: Cache this
            case EventType.DragUpdated:
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                List <TileBase> tiles = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences);
                instance.m_HoverData = TileDragAndDrop.CreateHoverData(null, null, tiles);
                if (instance.m_HoverData.Count > 0)
                {
                    Event.current.Use();
                    GUI.changed = true;
                }
                break;

            case EventType.DragPerform:
                if (instance.m_HoverData.Count > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    var     tileSheet = TileDragAndDrop.ConvertToTileSheet(instance.m_HoverData);
                    Tilemap tilemap   = GetOrCreateActiveTilemap();
                    tilemap.ClearAllEditorPreviewTiles();
                    int i = 0;
                    foreach (KeyValuePair <Vector2Int, TileDragAndDropHoverData> item in instance.m_HoverData)
                    {
                        Vector3Int position = new Vector3Int(mouseGridPosition.x + item.Key.x, mouseGridPosition.y + item.Key.y, 0);
                        tilemap.SetTile(position, tileSheet[i++]);
                        tilemap.SetTransformMatrix(position, Matrix4x4.TRS(item.Value.positionOffset - tilemap.tileAnchor, Quaternion.identity, Vector3.one));
                    }
                    instance.m_HoverData = null;
                    GUI.changed          = true;
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                if (instance.m_HoverData != null)
                {
                    Tilemap map = Selection.activeGameObject.GetComponentInParent <Tilemap>();

                    if (map != null)
                    {
                        map.ClearAllEditorPreviewTiles();
                    }

                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    foreach (KeyValuePair <Vector2Int, TileDragAndDropHoverData> item in instance.m_HoverData)
                    {
                        Vector3Int gridPos = mouseGridPosition + new Vector3Int(item.Key.x, item.Key.y, 0);
                        if (item.Value.hoverObject is TileBase)
                        {
                            TileBase tile = item.Value.hoverObject as TileBase;
                            if (map != null)
                            {
                                map.SetEditorPreviewTile(gridPos, tile);
                            }
                        }
                    }
                }
                break;
            }

            if (instance.m_HoverData != null && (
                    Event.current.type == EventType.DragExited ||
                    Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape))
            {
                if (instance.m_HoverData.Count > 0)
                {
                    Tilemap map = Selection.activeGameObject.GetComponentInParent <Tilemap>();
                    if (map != null)
                    {
                        map.ClearAllEditorPreviewTiles();
                    }

                    Event.current.Use();
                }

                instance.m_HoverData = null;
            }
        }
Example #16
0
 public void ClearPreview()
 {
     tilemap.ClearAllEditorPreviewTiles();
 }
Example #17
0
        private void OnSceneGUIDelegate(SceneView sceneView)
        {
            Event current = Event.current;

            if (current.type == EventType.DragUpdated || current.type == EventType.DragPerform || current.type == EventType.DragExited || current.type == EventType.Repaint)
            {
                Grid activeGrid = TileDragAndDropManager.GetActiveGrid();
                if (!(activeGrid == null) && DragAndDrop.objectReferences.Length != 0)
                {
                    Vector3    localPosition = GridEditorUtility.ScreenToLocal(activeGrid.transform, current.mousePosition);
                    Vector3Int a             = activeGrid.LocalToCell(localPosition);
                    EventType  type          = current.type;
                    if (type != EventType.DragUpdated)
                    {
                        if (type != EventType.DragPerform)
                        {
                            if (type == EventType.Repaint)
                            {
                                if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData != null)
                                {
                                    Tilemap componentInParent = Selection.activeGameObject.GetComponentInParent <Tilemap>();
                                    if (componentInParent != null)
                                    {
                                        componentInParent.ClearAllEditorPreviewTiles();
                                    }
                                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                                    foreach (KeyValuePair <Vector2Int, UnityEngine.Object> current2 in ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData)
                                    {
                                        Vector3Int position = a + new Vector3Int(current2.Key.x, current2.Key.y, 0);
                                        if (current2.Value is TileBase)
                                        {
                                            TileBase tile = current2.Value as TileBase;
                                            if (componentInParent != null)
                                            {
                                                componentInParent.SetEditorPreviewTile(position, tile);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                            Dictionary <Vector2Int, TileBase> dictionary = TileDragAndDrop.ConvertToTileSheet(ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData);
                            Tilemap orCreateActiveTilemap = TileDragAndDropManager.GetOrCreateActiveTilemap();
                            orCreateActiveTilemap.ClearAllEditorPreviewTiles();
                            foreach (KeyValuePair <Vector2Int, TileBase> current3 in dictionary)
                            {
                                Vector3Int position2 = new Vector3Int(a.x + current3.Key.x, a.y + current3.Key.y, 0);
                                orCreateActiveTilemap.SetTile(position2, current3.Value);
                            }
                            ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = null;
                            GUI.changed = true;
                            Event.current.Use();
                        }
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        List <TileBase> validTiles = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences);
                        ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = TileDragAndDrop.CreateHoverData(null, null, validTiles);
                        if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0)
                        {
                            Event.current.Use();
                            GUI.changed = true;
                        }
                    }
                    if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData != null && (Event.current.type == EventType.DragExited || (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)))
                    {
                        if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0)
                        {
                            Tilemap componentInParent2 = Selection.activeGameObject.GetComponentInParent <Tilemap>();
                            if (componentInParent2 != null)
                            {
                                componentInParent2.ClearAllEditorPreviewTiles();
                            }
                            Event.current.Use();
                        }
                        ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = null;
                    }
                }
            }
        }