Beispiel #1
0
        private bool IsNeighborBoxMatched(int neighborRuleCode, TileBase nextTile)
        {
            ScriptedTile thisScriptedTile = this;

            switch (neighborRuleCode)
            {
            /*
             * Se o NeighborBox pede um MustHave, e o Tile (`nextTile`) respectivo ao NeighborBoxPositionOnMatrix
             * pertencer ao mesmo ScriptedTile, os outros NeighborBox devem continuar sendo verificados, pois, talvez,
             * todos os Neighbors serão correspondidos e, o Rule poderá substituir os dados do Tile.
             *
             * Se não for do mesmo ScriptedTile, o NeighborBox não é correspondido e a Rule não poderá substituir os dados do Tile.
             */
            case RuleTileData.NeighborRuleCode.MustHave:
                return(nextTile == thisScriptedTile);

            /*
             * Se o NeighborBox pede um MustNotHave, e o Tile (`nextTile`) respectivo ao NeighborBoxPositionOnMatrix
             * pertencer a outro ScriptedTile (outro Tile), os outros NeighborBox devem continuar sendo verificados, pois, talvez,
             * todos os Neighbors serão correspondidos e, o Rule poderá substituir os dados Tile.
             *
             * Se for do mesmo ScriptedTile, o NeighborBox não é correspondido e a Rule não poderá substituir os dados do Tile.
             */
            case RuleTileData.NeighborRuleCode.MustNotHave:
                return(nextTile != thisScriptedTile);
            }

            return(true);
        }
Beispiel #2
0
        public ReorderableList CreateReorderableListOfRules(ScriptedTile scriptedTile)
        {
            this.scriptedTile = scriptedTile;

            bool draggable           = true;
            bool displayHeader       = true;
            bool displayAddButton    = true;
            bool displayRemoveButton = true;

            if (this.scriptedTile != null)
            {
                ReorderableList reorderableListOfRules = new ReorderableList(
                    this.scriptedTile.rules,
                    typeof(ScriptedTile.Rule),
                    draggable,
                    displayHeader,
                    displayAddButton,
                    displayRemoveButton
                    );

                reorderableListOfRules.drawHeaderCallback    = OnDrawRLHeader;
                reorderableListOfRules.drawElementCallback   = OnDrawRLElement;
                reorderableListOfRules.elementHeightCallback = GetRLElementHeight;
                reorderableListOfRules.onChangedCallback     = OnRLUpdated;
                reorderableListOfRules.onAddCallback         = OnRLAddElement;

                return(reorderableListOfRules);
            }

            return(null);
        }
Beispiel #3
0
 public void ForceRefreshTiles(ScriptedTile scriptedTileTarget)
 {
     /**
      * This method force the `TileBase.RefreshTile()`.
      * Then the `ScriptedTile.GetTileData()` will be executed for all Tiles.
      */
     EditorUtility.SetDirty(scriptedTileTarget);
     SceneView.RepaintAll();
 }
Beispiel #4
0
        private void OnEnterOrLeaveWithAnyTilePaintToolInTilemap(Vector3Int tilePosition, ITilemap iTilemap)
        {
            /**
             * === Enter or leave on Tile empty or paited. ===
             *
             * O método `base.RefreshTile()` irá executar o `GetTileData()` se,
             * qualquer tile paint tool entrar ou sair de um Tile (empty or paited).
             *
             * === Enter on Tile painted. Or Paint a Tile. ===
             *
             * O método `base.RefreshTile()` irá executar os métodos `GetTileData()`, `StartUp()`, `GetTileAnimationData()` se,
             * qualquer tile paint tool entrar em um Tile (painted).
             *
             * Refresh apenas no Tile atual.
             */
            base.RefreshTile(tilePosition, iTilemap);

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

            // Refresh nos Tiles que estão ao redor do Tile atual.
            foreach (Vector3Int tileAroundOffsetPosition in neighborsBoxesPositionOnMatrix)
            {
                Vector3Int tileAroundPosition = GetNextTilePosition(tilePosition, tileAroundOffsetPosition);

                // O Refresh só acontecerá se o `aroundTile` for um ScriptedTile.

                TileBase     aTile        = tilemap.GetTile(tileAroundPosition);
                ScriptedTile scriptedTile = null;

                if (aTile is ScriptedTile)
                {
                    scriptedTile = aTile as ScriptedTile;

                    if (scriptedTile)
                    {
                        base.RefreshTile(tileAroundPosition, iTilemap);
                    }
                }
            }
        }
Beispiel #5
0
        private void DrawNeighborsMatrixComponent(Rect neighborsMatrixComponentRectangle, BoundsInt neighborsMatrixBounds, ScriptedTile scriptedTile, ScriptedTile.Rule rule)
        {
            Handles.color = EditorGUIUtility.isProSkin ?
                            new Color(1f, 1f, 1f, 0.2f) :
                            new Color(0f, 0f, 0f, 0.2f);

            // Largura do Matrix GUI.
            float matrixWidth = neighborsMatrixComponentRectangle.width;
            // Altura do Matrix GUI.
            float matrixHeight = neighborsMatrixComponentRectangle.height;

            // Quantidade de colunas verticais do Matrix.
            float boundsWidth = neighborsMatrixBounds.size.x;
            // Quantidade de colunas horizontais do Matrix.
            float boundsHeight = neighborsMatrixBounds.size.y;

            int boundsMaxX = neighborsMatrixBounds.xMax;
            int boundsMaxY = neighborsMatrixBounds.yMax;
            int boundsMinX = neighborsMatrixBounds.xMin;
            int boundsMinY = neighborsMatrixBounds.yMin;

            // Largura de cada coluna do Matrix.
            float matrixColumnWidth = matrixWidth / boundsWidth;
            // Altura de cada coluna do Matrix.
            float matrixColumnHeight = matrixHeight / boundsHeight;

            float matrixGUITop    = neighborsMatrixComponentRectangle.yMin;
            float matrixGUIRight  = neighborsMatrixComponentRectangle.xMax;
            float matrixGUIBottom = neighborsMatrixComponentRectangle.yMax;
            float matrixGUILeft   = neighborsMatrixComponentRectangle.xMin;

            // Draw horizontal columns.
            for (int horizontalColumnIndex = 0; horizontalColumnIndex <= boundsHeight; horizontalColumnIndex++)
            {
                float columnHeight = matrixGUITop + horizontalColumnIndex * matrixColumnHeight;

                Vector3 startPoint = new Vector3(matrixGUILeft, columnHeight);
                Vector3 endPoint   = new Vector3(matrixGUIRight, columnHeight);

                Handles.DrawLine(startPoint, endPoint);
            }

            // Draw vertical columns.
            for (int verticalColumnIndex = 0; verticalColumnIndex <= boundsWidth; verticalColumnIndex++)
            {
                float columnWidth = matrixGUILeft + verticalColumnIndex * matrixColumnWidth;

                Vector3 startPoint = new Vector3(columnWidth, matrixGUITop);
                Vector3 endPoint   = new Vector3(columnWidth, matrixGUIBottom);

                Handles.DrawLine(startPoint, endPoint);
            }

            Handles.color = Color.white;

            Dictionary <Vector3Int, int> neighbors = rule.GetNeighbors();

            // In a NeighborBox.
            for (int neighborY = boundsMinY; neighborY < boundsMaxX; neighborY++)
            {
                for (int neighborX = boundsMinX; neighborX < boundsMaxY; neighborX++)
                {
                    Vector3Int neighborBoxPositionOnMatrix = new Vector3Int(neighborX, neighborY, 0);

                    float neighborBoxPositionX = matrixGUILeft + (neighborX - boundsMinX) * matrixColumnWidth;
                    float neighborBoxPositionY = matrixGUITop + (-neighborY + boundsMaxY - 1) * matrixColumnHeight;
                    float width  = matrixColumnWidth - 1;
                    float height = matrixColumnHeight - 1;

                    Rect neighborBoxRectangle = new Rect(
                        neighborBoxPositionX,
                        neighborBoxPositionY,
                        width,
                        height
                        );

                    InNeighborBox(neighborBoxPositionOnMatrix, neighborBoxRectangle, rule, neighbors);
                }
            }
        }