コード例 #1
0
 protected abstract void MoveStart(BoundsInt position);
コード例 #2
0
        public override void MoveStart(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            // Do not allow editing palettes
            if (brushTarget.layer == 31)
            {
                return;
            }

            Reset();
            UpdateSizeAndPivot(new Vector3Int(position.size.x, position.size.y, 1), Vector3Int.zero);

            if (brushTarget != null)
            {
                foreach (Vector3Int pos in position.allPositionsWithin)
                {
                    Vector3Int brushPosition = new Vector3Int(pos.x - position.x, pos.y - position.y, 0);
                    PickCell(pos, brushPosition, gridLayout, brushTarget.transform);
                    ClearSceneCell(gridLayout, brushTarget.transform, brushPosition);
                }
            }
        }
コード例 #3
0
    // Use this for initialization
    public TileSpriteController(World world) : base(world, "Tiles", world.Volume)
    {
        world.OnTileChanged     += OnChanged;
        world.OnTileTypeChanged += OnChanged;

        TileLookup = new Dictionary <string, TileBase>();
        foreach (var tiletype in PrototypeManager.TileType.Values)
        {
            UnityEngine.Tilemaps.Tile tile = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
            Sprite sprite = SpriteManager.GetSprite("Tile", tiletype.Type);
            tile.sprite = sprite;
            tile.name   = tiletype.Type;
            TileLookup[tiletype.Type] = tile;
        }

        TileLookup[TileType.Empty.Type] = null;

        objectParent.AddComponent <Grid>();

        errorTile        = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
        errorTile.sprite = SpriteManager.CreateErrorSprite();
        errorTile.name   = "ErrorTile";
        errorTile.color  = Color.white;

        tilemaps         = new Tilemap[world.Depth];
        tilemapRenderers = new TilemapRenderer[world.Depth];
        for (int z = 0; z < world.Depth; z++)
        {
            GameObject go = new GameObject("Tile layer " + (z + 1));
            go.transform.SetParent(objectParent.transform);
            go.transform.position -= new Vector3(.5f, .5f, -z);

            tilemaps[z]                        = go.AddComponent <Tilemap>();
            tilemaps[z].orientation            = Tilemap.Orientation.XY;
            tilemapRenderers[z]                = go.AddComponent <TilemapRenderer>();
            tilemapRenderers[z].sortingLayerID = SortingLayer.NameToID("Tiles");
            tilemapRenderers[z].sortingOrder   = -z;

            TileBase[] tiles  = new TileBase[world.Width * world.Height];
            BoundsInt  bounds = new BoundsInt(0, 0, 0, world.Width, world.Height, 1);

            for (int y = 0; y < world.Height; y++)
            {
                for (int x = 0; x < world.Width; x++)
                {
                    Tile worldTile = world.GetTileAt(x, y, z);

                    TileBase tilemapTile;
                    if (TileLookup.TryGetValue(worldTile.Type.Type, out tilemapTile) == false)
                    {
                        tilemapTile = errorTile;
                        UnityDebugger.Debugger.LogWarningFormat("TileSpriteController", "Could not find graphics tile for type {0}", worldTile.Type.Type);
                    }

                    tiles[x + (y * world.Width)] = tilemapTile;
                }
            }

            tilemaps[z].SetTilesBlock(bounds, tiles);
        }
    }
コード例 #4
0
        public virtual void BoxFillPreview(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            if (brushTarget != null)
            {
                Tilemap map = brushTarget.GetComponent <Tilemap>();
                if (map != null)
                {
                    foreach (Vector3Int location in position.allPositionsWithin)
                    {
                        Vector3Int          local = location - position.min;
                        GridBrush.BrushCell cell  = brush.cells[brush.GetCellIndexWrapAround(local.x, local.y, local.z)];
                        if (cell.tile != null)
                        {
                            SetTilemapPreviewCell(map, location, cell.tile, cell.matrix, cell.color);
                        }
                    }
                }
            }

            m_LastGrid        = gridLayout;
            m_LastBounds      = position;
            m_LastBrushTarget = brushTarget;
            m_LastTool        = GridBrushBase.Tool.Box;
        }
コード例 #5
0
        public override void Move(GridLayout gridLayout, GameObject brushTarget, BoundsInt from, BoundsInt to)
        {
            var offset = to.min - from.min;

            foreach (var i in cache.ToList())
            {
                cache[i.Key]          = null;
                cache[i.Key + offset] = i.Value;
            }
            base.Move(gridLayout, brushTarget, from, to);
        }
コード例 #6
0
        // Move中にずっと呼ばれる
        public override void Move(GridLayout gridLayout, GameObject brushTarget, BoundsInt from, BoundsInt to)
        {
            // パレット上の処理はベースクラスに任せる
            if (ExPrefabBrush.IsPalette(brushTarget))
            {
                base.Move(gridLayout, brushTarget, from, to);
                return;
            }

            // 1. 複数Tilemapの移動プレビュー
            MoveAllTilemapsRoutine(to, true, false);

            // 2. タイル以外の移動
            MoveGameObjectsRoutine(true, to);
        }
コード例 #7
0
    // Fills tile list with tiles
    public LiteRoomTile[,] GetTiles(BoundsInt bounds)
    {
        // create tile array
        LiteRoomTile[,] tile_list = new LiteRoomTile[x_, y_];
        Constants.TileType temp_tiletype;
        Constants.TileType top_tiletype;
        int xMaxMinusOne = bounds.xMax - 1;
        int yMaxMinusOne = bounds.yMax - 1;

        position_offset_ = new Vector3Int(bounds.xMin, bounds.yMin, 0);
        //int yMinPlusOne
        // get all tiles within bounds
        for (int x = 0, rx = bounds.xMin; x < bounds.size.x; x++, rx++)
        {
            for (int y = 0, ry = bounds.yMin; y < bounds.size.y; y++, ry++)
            {
                Vector3Int grid_position = new Vector3Int(rx, ry, 0);
                if (tilemap_.GetTile <Tile>(grid_position) != null)
                {
                    temp_tiletype = Constants.GetTypeFromSprite(GeneralFunctions.GetTileSpriteName(tilemap_, grid_position));
                    if (entity_tilemap.GetTile <Tile>(grid_position) != null)
                    {
                        top_tiletype = Constants.GetTypeFromSprite(GeneralFunctions.GetTileSpriteName(entity_tilemap, grid_position));
                    }
                    else
                    {
                        top_tiletype = Constants.TileType.NONE;
                    }
                    // if tiletype is door and is valid (i.e. at convex edge of room), add to door list
                    if (temp_tiletype == Constants.TileType.CONNECTOR)
                    {
                        // if connector is a corner tile
                        if (rx == bounds.xMin && ry == bounds.yMin)
                        {
                            continue;
                        }
                        else if (rx == bounds.xMin && ry == yMaxMinusOne)
                        {
                            continue;
                        }
                        else if (ry == yMaxMinusOne && rx == xMaxMinusOne)
                        {
                            continue;
                        }
                        else if (rx == xMaxMinusOne && ry == bounds.yMin)
                        {
                            continue;
                        }
                        // if connector is an edge tile
                        else if (rx == bounds.xMin)
                        {
                            sw_doors_.Add(new Door("SW", new Vector3Int(rx, ry, layer_height_)));
                        }
                        else if (rx == xMaxMinusOne)
                        {
                            ne_doors_.Add(new Door("NE", new Vector3Int(rx, ry, layer_height_)));
                        }
                        else if (ry == bounds.yMin)
                        {
                            se_doors_.Add(new Door("SE", new Vector3Int(rx, ry, layer_height_)));
                        }
                        else if (ry == yMaxMinusOne)
                        {
                            nw_doors_.Add(new Door("NW", new Vector3Int(rx, ry, layer_height_)));
                        }
                    }
                    // gets sprite name and checks with dictionary to get enum TileType
                    tile_list[x, y].Init(temp_tiletype, top_tiletype);
                }
                else
                {
                    tile_list[x, y].Init(Constants.TileType.NONE, Constants.TileType.NONE);
                }
            }
        }
        number_nw_doors = nw_doors_.Count;
        number_ne_doors = ne_doors_.Count;
        number_sw_doors = sw_doors_.Count;
        number_se_doors = se_doors_.Count;
        return(tile_list);
    }
コード例 #8
0
 public static Rect ToRect(this BoundsInt bounds)
 {
     return(new Rect((Vector3)bounds.position, (Vector3)bounds.size));
 }
コード例 #9
0
 public static RectInt ToRectInt(this BoundsInt bounds)
 {
     return(new RectInt(bounds.position.To2Int(), bounds.size.To2Int()));
 }
コード例 #10
0
        public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing);
            if (coordinateBrush.z != 0)
            {
                var       zPosition   = new Vector3Int(position.min.x, position.min.y, coordinateBrush.z);
                BoundsInt newPosition = new BoundsInt(zPosition, position.size);
                Vector3[] cellLocals  = new Vector3[]
                {
                    grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.min.y, newPosition.min.z)),
                    grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.min.y, newPosition.min.z)),
                    grid.CellToLocal(new Vector3Int(newPosition.max.x, newPosition.max.y, newPosition.min.z)),
                    grid.CellToLocal(new Vector3Int(newPosition.min.x, newPosition.max.y, newPosition.min.z))
                };

                Handles.color = Color.blue;
                int i = 0;
                for (int j = cellLocals.Length - 1; i < cellLocals.Length; j = i++)
                {
                    Handles.DrawLine(cellLocals[j], cellLocals[i]);
                }
            }

            var labelText = "Pos: " + new Vector3Int(position.x, position.y, coordinateBrush.z);

            if (position.size.x > 1 || position.size.y > 1)
            {
                labelText += " Size: " + new Vector2Int(position.size.x, position.size.y);
            }

            Handles.Label(grid.CellToWorld(new Vector3Int(position.x, position.y, coordinateBrush.z)), labelText);
        }
コード例 #11
0
        /// <summary>Callback for drawing the Inspector GUI when there is an active GridSelection made in a Tilemap.</summary>
        public override void OnSelectionInspectorGUI()
        {
            BoundsInt selection = GridSelection.position;
            Tilemap   tilemap   = GridSelection.target.GetComponent <Tilemap>();

            int cellCount = selection.size.x * selection.size.y * selection.size.z;

            if (tilemap != null && cellCount > 0)
            {
                base.OnSelectionInspectorGUI();

                if (!EditorGUIUtility.editingTextField &&
                    Event.current.type == EventType.KeyDown &&
                    (Event.current.keyCode == KeyCode.Delete ||
                     Event.current.keyCode == KeyCode.Backspace))
                {
                    DeleteSelection(tilemap, selection);
                    Event.current.Use();
                }

                GUILayout.Space(10f);

                EditorGUILayout.LabelField(Styles.gridSelectionPropertiesLabel, EditorStyles.boldLabel);

                UpdateSelection(tilemap);

                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First());
                var      position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin);
                TileBase newTile  = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(tilemap, "Edit Tilemap");
                    foreach (var p in selection.allPositionsWithin)
                    {
                        tilemap.SetTile(p, newTile);
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First());
                    EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight));
                }

                bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor));
                using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First());
                    EditorGUI.BeginChangeCheck();
                    Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetColor(p, newColor);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First());
                    EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]);
                }

                bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform));
                using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First());
                    EditorGUI.BeginChangeCheck();
                    Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetTransformMatrix(p, newTransformMatrix);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = !colorFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0);
                    EditorGUI.showMixedValue = !transformFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0);
                }

                EditorGUI.showMixedValue = false;

                if (GUILayout.Button(Styles.deleteSelectionLabel))
                {
                    DeleteSelection(tilemap, selection);
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField(Styles.modifyTilemapLabel, EditorStyles.boldLabel);
                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();
                m_SelectedTransformTool = GUILayout.Toolbar(m_SelectedTransformTool, Styles.selectionTools);
                if (EditorGUI.EndChangeCheck())
                {
                    SceneView.RepaintAll();
                }
                EditorGUILayout.Space();

                GUILayout.BeginHorizontal();
                m_ModifyCells = (ModifyCells)EditorGUILayout.EnumPopup(m_ModifyCells);
                m_CellCount   = EditorGUILayout.IntField(m_CellCount);
                if (GUILayout.Button(Styles.modifyLabel))
                {
                    RegisterUndoForTilemap(tilemap, Enum.GetName(typeof(ModifyCells), m_ModifyCells));
                    switch (m_ModifyCells)
                    {
                    case ModifyCells.InsertRow:
                    {
                        tilemap.InsertCells(GridSelection.position.position, 0, m_CellCount, 0);
                        break;
                    }

                    case ModifyCells.InsertRowBefore:
                    {
                        tilemap.InsertCells(GridSelection.position.position, 0, -m_CellCount, 0);
                        break;
                    }

                    case ModifyCells.InsertColumn:
                    {
                        tilemap.InsertCells(GridSelection.position.position, m_CellCount, 0, 0);
                        break;
                    }

                    case ModifyCells.InsertColumnBefore:
                    {
                        tilemap.InsertCells(GridSelection.position.position, -m_CellCount, 0, 0);
                        break;
                    }

                    case ModifyCells.DeleteRow:
                    {
                        tilemap.DeleteCells(GridSelection.position.position, 0, m_CellCount, 0);
                        break;
                    }

                    case ModifyCells.DeleteRowBefore:
                    {
                        tilemap.DeleteCells(GridSelection.position.position, 0, -m_CellCount, 0);
                        break;
                    }

                    case ModifyCells.DeleteColumn:
                    {
                        tilemap.DeleteCells(GridSelection.position.position, m_CellCount, 0, 0);
                        break;
                    }

                    case ModifyCells.DeleteColumnBefore:
                    {
                        tilemap.DeleteCells(GridSelection.position.position, -m_CellCount, 0, 0);
                        break;
                    }
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
コード例 #12
0
 public static Vector2Int Center(BoundsInt bounds)
 {
     return(new Vector2Int((bounds.xMin + bounds.xMax) / 2, (bounds.yMin + bounds.yMax) / 2));
 }
コード例 #13
0
 protected virtual void OnBrushPickDragged(BoundsInt position)
 {
 }
コード例 #14
0
 protected abstract void MoveEnd(BoundsInt position);
コード例 #15
0
ファイル: GameObjectBrush.cs プロジェクト: Austinkemp10/Swarm
 /// <summary>
 /// MoveEnd is called when user has ended the move of the area previously selected with the selection marquee.
 /// The GameObjectBrush overrides this to provide GameObject moving functionality.
 /// </summary>
 /// <param name="gridLayout">Grid used for layout.</param>
 /// <param name="brushTarget">Target of the move operation. By default the currently selected GameObject.</param>
 /// <param name="position">Position where the move operation has ended.</param>
 public override void MoveEnd(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
 {
     Paint(gridLayout, brushTarget, position.min);
     Reset();
 }
コード例 #16
0
 protected override void OnBrushPickDragged(BoundsInt position)
 {
     m_ActivePick = new RectInt(position.min.x, position.min.y, position.size.x, position.size.y);
 }
コード例 #17
0
        // Move開始時に呼ばれる
        public override void MoveStart(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            // パレット上の処理はベースクラスに任せる
            if (ExPrefabBrush.IsPalette(brushTarget))
            {
                base.MoveStart(gridLayout, brushTarget, position);
                return;
            }

            cellsDict = new Dictionary <ExBrushTarget, TileBase[]>();

            // 1. 複数Tilemapの移動プレビュー
            MoveAllTilemapsRoutine(position, true, true);

            // 2. タイル以外の移動の準備
            MoveGameObjectsRoutine(false, position);
        }
コード例 #18
0
ファイル: LineBrush.cs プロジェクト: rakkarage/PathFinder
 public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
 {
     base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing);
     if (Brush.LineStartActive)
     {
         var tilemap = brushTarget.GetComponent <Tilemap>();
         if (tilemap != null)
         {
             tilemap.ClearAllEditorPreviewTiles();
         }
         var startPos = new Vector2Int(Brush.LineStart.x, Brush.LineStart.y);
         var endPos   = new Vector2Int(position.x, position.y);
         if (startPos == endPos)
         {
             PaintPreview(grid, brushTarget, position.min);
         }
         else
         {
             foreach (var p in LineBrush.GetPointsOnLine(startPos, endPos, Brush.FillGaps))
             {
                 PaintPreview(grid, brushTarget, new Vector3Int(p.x, p.y, position.z));
             }
         }
         if (Event.current.type == EventType.Repaint)
         {
             var min = Brush.LineStart;
             var max = Brush.LineStart + position.size;
             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();
         }
     }
 }
コード例 #19
0
        // 一部の条件の時のみ、プレビューの処理を無効化する
        public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            // パレット上の処理はベースクラスに任せる
            if (brushTarget.layer == 31)
            {
                base.OnPaintSceneGUI(gridLayout, brushTarget, position, tool, executing);
                return;
            }

            if (tool == GridBrushBase.Tool.Move)
            {
                if (executing)
                {
                    // Moveの実行中はExBrush側でプレビューを弄っているので、ここでは何もしない
                    // (ここでbase.OnPaintSceneGUI()を呼び出すと左下に1マスだけ選択タイルがプレビューされるという不具合が起こる)
                }
                else
                {
                    base.OnPaintSceneGUI(gridLayout, brushTarget, position, tool, executing);

                    // 移動中にEscキーを押してキャンセル(Revert)するとプレビューのクリア漏れが起こるが、
                    // これはデフォルトブラシでも同じ挙動だったので保留
                }
            }
            else
            {
                base.OnPaintSceneGUI(gridLayout, brushTarget, position, tool, executing);
            }
        }
コード例 #20
0
 // Start is called before the first frame update
 private void Start()
 {
     bound         = MatrixManager.MainStationMatrix.Bounds;
     escapeShuttle = FindObjectOfType <EscapeShuttle>();
 }
コード例 #21
0
        public override void OnSelectionInspectorGUI()
        {
            BoundsInt selection = GridSelection.position;
            Tilemap   tilemap   = GridSelection.target.GetComponent <Tilemap>();

            int cellCount = selection.size.x * selection.size.y * selection.size.z;

            if (tilemap != null && cellCount > 0)
            {
                base.OnSelectionInspectorGUI();
                GUILayout.Space(10f);

                if (m_SelectionTiles == null || m_SelectionTiles.Length != cellCount)
                {
                    m_SelectionTiles         = new TileBase[cellCount];
                    m_SelectionColors        = new Color[cellCount];
                    m_SelectionMatrices      = new Matrix4x4[cellCount];
                    m_SelectionFlagsArray    = new TileFlags[cellCount];
                    m_SelectionSprites       = new Sprite[cellCount];
                    m_SelectionColliderTypes = new Tile.ColliderType[cellCount];
                }

                int index = 0;
                foreach (var p in selection.allPositionsWithin)
                {
                    m_SelectionTiles[index]         = tilemap.GetTile(p);
                    m_SelectionColors[index]        = tilemap.GetColor(p);
                    m_SelectionMatrices[index]      = tilemap.GetTransformMatrix(p);
                    m_SelectionFlagsArray[index]    = tilemap.GetTileFlags(p);
                    m_SelectionSprites[index]       = tilemap.GetSprite(p);
                    m_SelectionColliderTypes[index] = tilemap.GetColliderType(p);
                    index++;
                }

                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First());
                var      position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin);
                TileBase newTile  = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase;
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(tilemap, "Edit Tilemap");
                    foreach (var p in selection.allPositionsWithin)
                    {
                        tilemap.SetTile(p, newTile);
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First());
                    EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight));
                }

                bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor));
                using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First());
                    EditorGUI.BeginChangeCheck();
                    Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetColor(p, newColor);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First());
                    EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]);
                }

                bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform));
                using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0))
                {
                    EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First());
                    EditorGUI.BeginChangeCheck();
                    Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(tilemap, "Edit Tilemap");
                        foreach (var p in selection.allPositionsWithin)
                        {
                            tilemap.SetTransformMatrix(p, newTransformMatrix);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUI.showMixedValue = !colorFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0);
                    EditorGUI.showMixedValue = !transformFlagsAllEqual;
                    EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0);
                }

                EditorGUI.showMixedValue = false;
            }
        }
コード例 #22
0
    public int[,] genTilePos(int[,] oldMap)
    {
        int[,] newMap = new int[width, height];
        int       neighb;
        BoundsInt myB = new BoundsInt(-1, -1, 0, 3, 3, 1);


        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                neighb = 0;
                foreach (var b in myB.allPositionsWithin)
                {
                    if (b.x == 0 && b.y == 0)
                    {
                        continue;
                    }
                    if (x + b.x >= 0 && x + b.x < width && y + b.y >= 0 && y + b.y < height)
                    {
                        neighb += oldMap[x + b.x, y + b.y];
                    }
                    else
                    {
                        neighb++;
                    }
                }

                if (oldMap[x, y] == 1)
                {
                    if (neighb < deathLimit)
                    {
                        newMap[x, y] = 0;
                    }

                    else
                    {
                        newMap[x, y] = 1;
                    }
                }

                if (oldMap[x, y] == 0)
                {
                    if (neighb > birthLimit)
                    {
                        newMap[x, y] = 1;
                    }

                    else
                    {
                        newMap[x, y] = 0;
                    }
                }
            }
        }

        Debug.Log(newMap);



        return(newMap);
    }
コード例 #23
0
        public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            BoundsInt gizmoRect       = position;
            bool      refreshPreviews = false;

            if (Event.current.type == EventType.Layout)
            {
                int newPreviewRefreshHash = GetHash(gridLayout, brushTarget, position, tool, brush);
                refreshPreviews = newPreviewRefreshHash != m_LastPreviewRefreshHash;
                if (refreshPreviews)
                {
                    m_LastPreviewRefreshHash = newPreviewRefreshHash;
                }
            }
            if (tool == GridBrushBase.Tool.Move)
            {
                if (refreshPreviews && executing)
                {
                    ClearPreview();
                    PaintPreview(gridLayout, brushTarget, position.min);
                }
            }
            else if (tool == GridBrushBase.Tool.Paint || tool == GridBrushBase.Tool.Erase)
            {
                if (refreshPreviews)
                {
                    ClearPreview();
                    if (tool != GridBrushBase.Tool.Erase)
                    {
                        PaintPreview(gridLayout, brushTarget, position.min);
                    }
                }
                gizmoRect = new BoundsInt(position.min - brush.pivot, brush.size);
            }
            else if (tool == GridBrushBase.Tool.Box)
            {
                if (refreshPreviews)
                {
                    ClearPreview();
                    BoxFillPreview(gridLayout, brushTarget, position);
                }
            }
            else if (tool == GridBrushBase.Tool.FloodFill)
            {
                if (refreshPreviews)
                {
                    ClearPreview();
                    FloodFillPreview(gridLayout, brushTarget, position.min);
                }
            }

            base.OnPaintSceneGUI(gridLayout, brushTarget, gizmoRect, tool, executing);
        }
コード例 #24
0
 public void SetTilesBlock(BoundsInt position, TileBase[] tileArray)
 {
     INTERNAL_CALL_SetTileAssetsBlock(position.min, position.size, tileArray);
 }
コード例 #25
0
        public override void Pick(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, Vector3Int pickStart)
        {
            // Do standard pick if user has selected a custom bounds
            if (position.size.x > 1 || position.size.y > 1 || position.size.z > 1)
            {
                base.Pick(gridLayout, brushTarget, position, pickStart);
                return;
            }

            Tilemap tilemap = brushTarget.GetComponent <Tilemap>();

            if (tilemap == null)
            {
                return;
            }

            Reset();

            // Determine size of picked locations based on gap and limit
            Vector3Int limitOrigin = position.position - limit;
            Vector3Int limitSize   = Vector3Int.one + limit * 2;
            BoundsInt  limitBounds = new BoundsInt(limitOrigin, limitSize);
            BoundsInt  pickBounds  = new BoundsInt(position.position, Vector3Int.one);

            m_VisitedLocations.SetAll(false);
            m_VisitedLocations.Set(GetIndex(position.position, limitOrigin, limitSize), true);
            m_NextPosition.Clear();
            m_NextPosition.Push(position.position);

            while (m_NextPosition.Count > 0)
            {
                Vector3Int next = m_NextPosition.Pop();
                if (tilemap.GetTile(next) != null)
                {
                    Encapsulate(ref pickBounds, next);
                    BoundsInt gapBounds = new BoundsInt(next - gap, Vector3Int.one + gap * 2);
                    foreach (var gapPosition in gapBounds.allPositionsWithin)
                    {
                        if (!limitBounds.Contains(gapPosition))
                        {
                            continue;
                        }
                        int index = GetIndex(gapPosition, limitOrigin, limitSize);
                        if (!m_VisitedLocations.Get(index))
                        {
                            m_NextPosition.Push(gapPosition);
                            m_VisitedLocations.Set(index, true);
                        }
                    }
                }
            }

            UpdateSizeAndPivot(pickBounds.size, position.position - pickBounds.position);

            foreach (Vector3Int pos in pickBounds.allPositionsWithin)
            {
                Vector3Int brushPosition = new Vector3Int(pos.x - pickBounds.x, pos.y - pickBounds.y, pos.z - pickBounds.z);
                if (m_VisitedLocations.Get(GetIndex(pos, limitOrigin, limitSize)))
                {
                    PickCell(pos, brushPosition, tilemap);
                }
            }
        }
コード例 #26
0
        public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing);
            if (lineBrush.lineStartActive)
            {
                Tilemap tilemap = brushTarget.GetComponent <Tilemap>();
                if (tilemap != null)
                {
                    lastTilemap = tilemap;
                }

                // 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)
                {
                    PaintPreview(grid, brushTarget, position.min);
                }
                else
                {
                    foreach (var point in LineBrush.GetPointsOnLine(startPos, endPos, lineBrush.fillGaps))
                    {
                        Vector3Int paintPos = new Vector3Int(point.x, point.y, position.z);
                        PaintPreview(grid, brushTarget, paintPos);
                    }
                }

                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();
                }
            }
        }
コード例 #27
0
        public override void OnPaintSceneGUI(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing)
        {
            BoundsInt gizmoRect = position;

            if (tool == GridBrushBase.Tool.Paint || tool == GridBrushBase.Tool.Erase)
            {
                gizmoRect = new BoundsInt(position.min - brush.pivot, brush.size);
            }

            base.OnPaintSceneGUI(gridLayout, brushTarget, gizmoRect, tool, executing);
        }
コード例 #28
0
ファイル: GameObjectBrush.cs プロジェクト: Austinkemp10/Swarm
        /// <summary>
        /// MoveStart is called when user starts moving the area previously selected with the selection marquee.
        /// The GameObjectBrush overrides this to provide GameObject moving functionality.
        /// </summary>
        /// <param name="gridLayout">Grid used for layout.</param>
        /// <param name="brushTarget">Target of the move operation. By default the currently selected GameObject.</param>
        /// <param name="position">Position where the move operation has started.</param>
        public override void MoveStart(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            Reset();
            UpdateSizeAndPivot(new Vector3Int(position.size.x, position.size.y, 1), Vector3Int.zero);

            if (brushTarget == hiddenGrid)
            {
                brushTarget = null;
            }

            var targetTransform = brushTarget != null ? brushTarget.transform : null;

            foreach (Vector3Int pos in position.allPositionsWithin)
            {
                Vector3Int brushPosition = new Vector3Int(pos.x - position.x, pos.y - position.y, 0);
                PickCell(pos, brushPosition, gridLayout, targetTransform);
                ClearSceneCell(gridLayout, targetTransform, brushPosition);
            }
        }
コード例 #29
0
 private void EnsureInit(MatrixInfo matrixInfo)
 {
     bound            = MatrixManager.MainStationMatrix.Bounds;
     escapeShuttle    = FindObjectOfType <EscapeShuttle>();
     boundsConfigured = true;
 }
コード例 #30
0
 protected abstract void Move(BoundsInt from, BoundsInt to);