/// <summary>
        /// Finds minimum and maximum extents of bounds that encapsulate one or more
        /// painted tiles.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <param name="min">Minimum tile index.</param>
        /// <param name="max">Maximum tile index.</param>
        /// <returns>
        /// A value of <c>true</c> if tile bounds were found; otherwise a value of <c>false</c>.
        /// A value of <c>false</c> is also returned for tile systems that contain no
        /// painted tiles.
        /// </returns>
        public static bool FindTileBounds(TileSystem system, out TileIndex min, out TileIndex max)
        {
            min = new TileIndex(int.MaxValue, int.MaxValue);
            max = new TileIndex(int.MinValue, int.MinValue);

            // Find first row that contains a tile.
            for (int row = 0; row < system.RowCount; ++row)
            {
                for (int column = 0; column < system.ColumnCount; ++column)
                {
                    if (system.GetTile(row, column) != null)
                    {
                        if (row < min.row)
                        {
                            min.row = row;
                        }
                        if (column < min.column)
                        {
                            min.column = column;
                        }
                        if (row > max.row)
                        {
                            max.row = row;
                        }
                        if (column > max.column)
                        {
                            max.column = column;
                        }
                    }
                }
            }

            return(min.row != int.MaxValue && min.column != int.MaxValue && max.row != int.MinValue && max.column != int.MaxValue);
        }
        /// <summary>
        /// Determines whether tiles will become out-of-bounds upon resizing tile system,
        /// or offsetting tiles within tile system.
        /// </summary>
        /// <remarks>
        /// <para>This can be used to present a confirmation message to warn user that
        /// tiles will be erased upon altering tile system using <see cref="Resize">Resize</see>.</para>
        /// </remarks>
        /// <example>
        /// <para>The following source demonstrates how to present a warning message prior
        /// to resizing a tile system. This example is for an editor script, though similar
        /// could be achieved at runtime.</para>
        /// <code language="csharp"><![CDATA[
        /// if (TileSystemUtility.WillHaveOutOfBoundTiles(system, 10, 10, 0, 0)) {
        ///     // Display confirmation message with user and abort if cancelled.
        ///     if (!EditorUtility.DisplayDialog(
        ///         "Resize",
        ///         "Tiles will be clipped if you proceed.",
        ///         "Proceed",
        ///         "Abort"
        ///     )) return;
        /// }
        ///
        /// TileSystemUtility.Resize(system, 10, 10, 0, 0, 10, 10, true);
        /// ]]></code>
        /// </example>
        /// <param name="system">Tile system.</param>
        /// <param name="newRows">New number of rows.</param>
        /// <param name="newColumns">New number of columns.</param>
        /// <param name="rowOffset">Number of rows of tiles to offset by.</param>
        /// <param name="columnOffset">Number of columns of tiles to offset by.</param>
        /// <returns>
        /// A value of <c>true</c> if tiles will become out-of-bounds; otherwise <c>false</c>.
        /// </returns>
        /// <seealso cref="Resize"/>
        public static bool WillHaveOutOfBoundTiles(TileSystem system, int newRows, int newColumns, int rowOffset, int columnOffset)
        {
            if (system.Chunks == null)
            {
                return(false);
            }

            rowOffset    = -rowOffset;
            columnOffset = -columnOffset;

            int offsetEndRow    = rowOffset + newRows;
            int offsetEndColumn = columnOffset + newColumns;

            for (int row = 0; row < system.RowCount; ++row)
            {
                for (int column = 0; column < system.ColumnCount; ++column)
                {
                    TileData tile = system.GetTile(row, column);
                    if (tile == null)
                    {
                        continue;
                    }

                    // Is tile out-of-bounds?
                    if (row < rowOffset || row >= offsetEndRow || column < columnOffset || column >= offsetEndColumn)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Gets indicator that should be drawn to represent tool nozzle.
        /// </summary>
        /// <remarks>
        /// <para>This method is called by <see cref="DrawNozzleIndicator"/> to determine
        /// which nozzle indicator should be used for the given context. For example, the
        /// wireframe indicator is sometimes more appropriate for 3D tiles whilst the flat
        /// indicator is better for 2D tiles.</para>
        /// <para>The outcome of this method can be customized by providing a specialized
        /// implementation. This can be useful to dynamically choose the indicator most
        /// relevant for an existing tile.</para>
        /// </remarks>
        /// <example>
        /// <para>The following example demonstrates how to pick an indicator based upon
        /// an existing tile. The method begins by assuming the user preferred nozzle
        /// indicator and proceeds to automatically pick between flat and wireframe when
        /// specified based upon the brush that was used to paint the existing tile.</para>
        /// <code language="csharp"><![CDATA[
        /// protected override NozzleIndicator GetNozzleIndicator(TileSystem system, int row, int column, BrushNozzle nozzle)
        /// {
        ///     NozzleIndicator mode = PreferredNozzleIndicator;
        ///
        ///     // Would user prefer tool to automatically pick indicator?
        ///     if (mode == NozzleIndicator.Automatic) {
        ///         mode = NozzleIndicator.Flat;
        ///
        ///         // Lookup the existing tile and switch to wireframe mode if
        ///         // associated brush indicates to do so.
        ///         TileData tile = system.GetTile(row, column);
        ///         if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor) {
        ///             mode = NozzleIndicator.Wireframe;
        ///         }
        ///     }
        ///
        ///     return mode;
        /// }
        /// ]]></code>
        /// </example>
        /// <param name="system">Tile system.</param>
        /// <param name="index">Index of tile.</param>
        /// <param name="nozzle">Type of brush nozzle.</param>
        protected virtual NozzleIndicator GetNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle)
        {
            NozzleIndicator mode = RtsPreferences.ToolPreferredNozzleIndicator;

            if (mode == NozzleIndicator.Automatic)
            {
                mode = NozzleIndicator.Flat;

                if (ToolUtility.SelectedBrush != null)
                {
                    if (ToolUtility.SelectedBrush.UseWireIndicatorInEditor)
                    {
                        mode = NozzleIndicator.Wireframe;
                    }
                }
                else
                {
                    // Determine based upon active tile (i.e. when using eraser).
                    var tile = system.GetTile(index);
                    if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor)
                    {
                        mode = NozzleIndicator.Wireframe;
                    }
                }
            }

            return(mode);
        }
        /// <summary>
        /// Generate new tile map and extract existing tiles for resized/offset tiles.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <param name="newRows">New number of rows.</param>
        /// <param name="newColumns">New number of columns.</param>
        /// <param name="rowOffset">Number of rows of tiles to offset by.</param>
        /// <param name="columnOffset">Number of columns of tiles to offset by.</param>
        private TileData[,] GenerateTileMap(TileSystem system, int newRows, int newColumns, int rowOffset, int columnOffset)
        {
            TileData[,] map = new TileData[newRows, newColumns];

            rowOffset    = -rowOffset;
            columnOffset = -columnOffset;

            int offsetEndRow    = rowOffset + newRows;
            int offsetEndColumn = columnOffset + newColumns;

            for (int row = 0; row < system.RowCount; ++row)
            {
                for (int column = 0; column < system.ColumnCount; ++column)
                {
                    var tile = system.GetTile(row, column);
                    if (tile == null)
                    {
                        continue;
                    }

                    // Reminder, out-of-bound tiles should already have been erased :)

                    // Extract tiles that are within bounds.
                    if (row >= rowOffset && row < offsetEndRow && column >= columnOffset && column < offsetEndColumn)
                    {
                        map[row - rowOffset, column - columnOffset] = tile;
                    }
                }
            }

            return(map);
        }
    void BuildStairs(int buildDirection, int originX, int originY)
    {
        map.BulkEditBegin();

        int y = 0;

        // while coordinates are blank, and within the map's bounds
        while (map.GetTile(originY + y, originX) == null &&
               TileInBounds(originX, originY + y))
        {
            for (int x = 0; x < y; x++)
            {
                switch (buildDirection)
                {
                case RIGHT:
                {
                    if (TileInBounds(originX + x, originY + y))
                    {
                        // build stairs
                        brush.PaintTile(map, originX + x, originY + y);
                        // erase walls to the right of stairs
                        map.ClearTile(originX + x + 1, originY + y);
                        map.ClearTile(originX + x + 2, originY + y);
                        map.ClearTile(originX + x + 3, originY + y);
                        map.ClearTile(originX + x + 4, originY + y);
                    }

                    // backfill stairs by one tile
                    brush.PaintTile(map, originX - 1, originY + y);
                    brush.PaintTile(map, originX - 2, originY + y);
                    break;
                }

                case LEFT:
                {
                    if (TileInBounds(originX - x, originY + y))
                    {
                        // build stairs
                        brush.PaintTile(map, originX - x, originY + y);
                        // erase walls to the left of stairs
                        map.ClearTile(originX - x - 1, originY + y);
                        map.ClearTile(originX - x - 2, originY + y);
                        map.ClearTile(originX - x - 3, originY + y);
                        map.ClearTile(originX - x - 4, originY + y);
                    }

                    // backfill stairs by one tile
                    brush.PaintTile(map, originX + 1, originY + y);
                    brush.PaintTile(map, originX + 2, originY + y);
                    break;
                }
                }
            }

            y++;
        }

        map.BulkEditEnd();
    }
 // Use this for initialization
 void Start()
 {
     GetComponent<Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
     GetComponent<Renderer>().receiveShadows = true;
     player = GameObject.Find("SB_Player");
     tileSystem = player.GetComponent<SB_PlayerController>().tileSystem;
     startPos = tileSystem.GetTile(startTile).gameObject.transform.position;
     startPos.y = .74f;
     transform.position = startPos;
     endPos = tileSystem.GetTile(endTile).gameObject.transform.position;
     endPos.y = .74f;
     gameCon = player.GetComponent<SB_GameController>();
     seeker = GetComponent<Seeker>();
     currentPos = 0;
     controller = GetComponent<CharacterController>();
     //A* function that generates the closest path from startPos to endPos.
     seeker.StartPath(startPos, endPos, OnPathComplete);
     to = true; from = false; updatedPos = false; moved = true; isAlarmed = false;
 }
 /// <summary>
 /// Extract tile data from tile system.
 /// </summary>
 /// <remarks>
 /// <para>This is particularly useful for scripts which need to temporarily retain
 /// a simple two-dimensional array of tile data whilst restructuring a tile system.</para>
 /// <para>This function loops through tiles and places the data of non-empty tiles
 /// into an array which is then returned. User scripts can modify returned array
 /// as needed without effecting the actual tile system. Changes to tile data will
 /// effect tile system.</para>
 /// </remarks>
 /// <param name="system">Tile system.</param>
 /// <returns>
 /// Two-dimensional array of tile data where empty tiles are <c>null</c>.
 /// </returns>
 public static TileData[,] ExtractTiles(TileSystem system)
 {
     TileData[,] map = new TileData[system.RowCount, system.ColumnCount];
     for (int row = 0; row < system.RowCount; ++row)
     {
         for (int column = 0; column < system.ColumnCount; ++column)
         {
             map[row, column] = system.GetTile(row, column);
         }
     }
     return(map);
 }
Beispiel #8
0
        public static GameObject GetTileBelow(this Transform transform, TileSystem tileSystem, int direction)
        {
            var convertedX = (int)Math.Floor(transform.position.x);
            var convertedY = (int)Math.Floor(Math.Abs(transform.position.y));

            TileData tile = tileSystem.GetTile(convertedY, convertedX + direction);

            if (tile != null)
            {
                return(tile.gameObject);
            }

            return(null);
        }
        public static GameObject GetTileBelow(this Transform transform, TileSystem tileSystem, int direction)
        {
            int convertedX = (int) Math.Floor(transform.position.x);
            int convertedY = (int) Math.Floor(Math.Abs(transform.position.y));

            TileData tile = tileSystem.GetTile(convertedY, convertedX + direction);

            if (tile != null)
            {
                return tile.gameObject;
            }

            return null;
        }
        // transform extensions for checking nearby tile data
        public static GameObject GetTileInfo(this Transform transform, TileSystem tileSystem, int xDirection, int yDirection)
        {
            // grabs tile info at a given transform:
            // x = 0, y = 0 will get you the tile the transform occupies
            // plus or minus x or y will get you tiles backwards, forwards, up or down

            int convertedX = (int) Math.Floor(transform.position.x);
            int convertedY = (int) Math.Ceiling(Math.Abs(transform.position.y));

            TileData tile = tileSystem.GetTile(convertedY + yDirection, convertedX + xDirection);

            if (tile != null)
            {
                return tile.gameObject;
            }

            return null;
        }
Beispiel #11
0
        // transform extensions for checking nearby tile data
        public static GameObject GetTileInfo(this Transform transform, TileSystem tileSystem, int xDirection, int yDirection)
        {
            // grabs tile info at a given transform:
            // x = 0, y = 0 will get you the tile the transform occupies
            // plus or minus x or y will get you tiles backwards, forwards, up or down

            var convertedX = (int)Math.Floor(transform.position.x);
            var convertedY = (int)Math.Ceiling(Math.Abs(transform.position.y));

            TileData tile = tileSystem.GetTile(convertedY + yDirection, convertedX + xDirection);

            if (tile != null)
            {
                return(tile.gameObject);
            }

            return(null);
        }
Beispiel #12
0
        /// <inheritdoc/>
        protected override NozzleIndicator GetNozzleIndicator(TileSystem system, TileIndex index, BrushNozzle nozzle)
        {
            NozzleIndicator mode = RtsPreferences.ToolPreferredNozzleIndicator;

            if (mode == NozzleIndicator.Automatic)
            {
                mode = NozzleIndicator.Flat;

                // Determine based upon active tile.
                var tile = system.GetTile(index);
                if (tile != null && tile.brush != null && tile.brush.UseWireIndicatorInEditor)
                {
                    mode = NozzleIndicator.Wireframe;
                }
            }

            return(mode);
        }
Beispiel #13
0
 public bool clear2Door()
 {
     try
     {
         floorGo[2].SetActive(true);
         TileSystem ts_object = floorGo[2].GetComponent <TileSystem>();
         GameObject door      = GameObject.Find("Floor2/chunk_0_0/door-01_3").gameObject;
         TileData   tile      = ts_object.GetTile(6, 1);
         GameObject.Destroy(door.gameObject);
         tile.Clear();
         //_GDM.sceneData[2][6, 1] = 1;
         floorGo[2].SetActive(false);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        private bool CanConstructAllBuildings()
        {
            TileSystem tileSystem = TileSystem.Instance;

            foreach (var cBuilding in _previewBuildings)
            {
                Vector3 buildingPosition = cBuilding.Building.transform.position;

                // if the tile is the same type of 'EntityID'
                if (tileSystem.GetTile(buildingPosition) != null && tileSystem.DoTileContainsEntityOfID(buildingPosition, EntityID))
                {
                    continue;
                }

                if (tileSystem.DoTilesFillConditions(buildingPosition, EntityData.TileSize, TileFlag.All))
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Erase all out-of-bound tiles.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <param name="newRows">New number of rows.</param>
        /// <param name="newColumns">New number of columns.</param>
        /// <param name="rowOffset">Number of rows of tiles to offset by.</param>
        /// <param name="columnOffset">Number of columns of tiles to offset by.</param>
        private void EraseOutOfBoundTiles(TileSystem system, int newRows, int newColumns, int rowOffset, int columnOffset)
        {
            if (system.Chunks == null)
            {
                return;
            }

            rowOffset    = -rowOffset;
            columnOffset = -columnOffset;

            int offsetEndRow    = rowOffset + newRows;
            int offsetEndColumn = columnOffset + newColumns;

            system.BeginBulkEdit();

            for (int row = 0; row < system.RowCount; ++row)
            {
                for (int column = 0; column < system.ColumnCount; ++column)
                {
                    var tile = system.GetTile(row, column);
                    if (tile == null)
                    {
                        continue;
                    }

                    // Is tile out-of-bounds?
                    if (row < rowOffset || row >= offsetEndRow || column < columnOffset || column >= offsetEndColumn)
                    {
                        system.EraseTile(row, column);
                        system.RefreshSurroundingTiles(row, column);
                    }
                }
            }

            system.EndBulkEdit();
        }
        private void ConstructBuilding(PreviewBuilding cBuilding)
        {
            GameObject building         = cBuilding.Building;
            Vector3    buildingPosition = building.transform.position;

            TileSystem tileSystem = TileSystem.Instance;

            // don't make construction unsuccessful because building on the same entiy
            if (tileSystem.GetTile(buildingPosition) != null && tileSystem.DoTileContainsEntityOfID(buildingPosition, EntityID))
            {
                // destroy, but don't interupt construction
                cBuilding.Destroy();
                return;
            }

            const TileFlag condition           = TileFlag.Free | TileFlag.Visible;
            bool           tileSetSuccessfully = tileSystem.TrySetTile(building, EntityData.TileSize, condition, EntityID);

            if (tileSetSuccessfully)
            {
                cBuilding.SetConstructionAsFinish(Team.Player);
                _constructionAchievedBuilding.Add(cBuilding);
            }
        }
Beispiel #17
0
    public bool CheckTile(string arrow)
    {
        PlayerTileIndex = _TileSystem
                          .ClosestTileIndexFromWorld(PlayerTransform.position);
        int x = PlayerTileIndex.row;
        int y = PlayerTileIndex.column;

        switch (arrow)
        {
        case "up":      x -= 1; break;

        case "down":    x += 1; break;

        case "left":    y -= 1; break;

        case "right":   y += 1; break;
        }
        if (x < 0 || y < 0 || x > 10 || y > 10)
        {
            return(false);
        }
        OtherTileData = _TileSystem.GetTile(x, y);
        if (OtherTileData != null)
        {
            if (OtherTileData.GetUserFlag(1))
            {
                _AM.talk(x, y, OtherTileData);
                return(false);
            }
            if (OtherTileData.GetUserFlag(2))
            {
                _AM.daoju(x, y, OtherTileData);
                return(true);
            }
            if (OtherTileData.GetUserFlag(3))
            {
                _AM.guaiwu(x, y, OtherTileData);
                return(false);
            }
            if (OtherTileData.GetUserFlag(4))
            {
                _AM.door(x, y, OtherTileData);
                return(false);
            }
            if (OtherTileData.GetUserFlag(5))
            {
                _AM.key(x, y, OtherTileData);
                return(true);
            }
            if (OtherTileData.GetUserFlag(6))
            {
                _AM.stair(x, y, OtherTileData);
                return(false);
            }
            if (OtherTileData.GetUserFlag(7))
            {
                _AM.tujian(x, y, OtherTileData);
                return(true);
            }
            if (OtherTileData.GetUserFlag(8))
            {
                _AM.feixing(x, y, OtherTileData);
                return(true);
            }
            if (OtherTileData.GetUserFlag(9))
            {
                _AM.guaiwu(x, y, OtherTileData);
                return(false);
            }
            if (OtherTileData.SolidFlag)
            {
                return(false);
            }
        }
        return(true);
    }
    /// <summary>
    /// Upgrade tile system from v1.0.0-v1.0.8 to v2.0.0.
    /// </summary>
    /// <remarks>
    /// <para>Replicates upgrade process that was included in v1.0.9+ but converts straight
    /// to v2.0.0 instead of v1.0.9.</para>
    /// </remarks>
    /// <param name="v1">Old tile system.</param>
    public static void UpgradeTileSystemA(MonoBehaviour v1)
    {
        RtsUpgradedBrushMap map = RtsBrushUpgradeUtility.BrushMappings;

        EditorUtility.DisplayProgressBar("Upgrade Tile System", "Initializing new data structure...", 0.0f);
        try {
            PropertyInfo piTileData_hasGameObject = typeof(TileData).GetProperty("HasGameObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            Vector3 tileSize = (Vector3)_fiTileSystem_tileSize.GetValue(v1);
            int     rows     = (int)_fiTileSystem_rows.GetValue(v1);
            int     columns  = (int)_fiTileSystem_columns.GetValue(v1);

            // Create v2.x tile system.
            TileSystem v2 = v1.gameObject.AddComponent <TileSystem>();
            v2.CreateSystem(tileSize.x, tileSize.y, tileSize.z, rows, columns, 30, 30);
            CopyProperties(v1, v2);

            // Assume value that was consistent with original default settings
            v2.applyRuntimeStripping = true;
            v2.StrippingPreset       = StrippingPreset.NoStripping;
            v2.BeginBulkEdit();

            Component[] instanceComponents = v1.GetComponentsInChildren(_tyTileInstance, true);

            float task      = 0.0f;
            float taskCount = instanceComponents.Length;
            float taskRatio = 1.0f / taskCount;

            TileData tile = new TileData();

            // Retrieve all tile instance components
            foreach (MonoBehaviour instance in instanceComponents)
            {
                EditorUtility.DisplayProgressBar("Upgrade Tile System", "Processing tile data...", (task++) * taskRatio);

                int row    = (int)_fiTileInstance_row.GetValue(instance);
                int column = (int)_fiTileInstance_column.GetValue(instance);

                tile.Clear();

                // Create and assign tile data
                tile.brush           = map.Lookup((Object)_piTileInstance_brush.GetValue(instance, null));
                tile.orientationMask = (byte)OrientationUtility.MaskFromName((string)_fiTileInstance_orientationName.GetValue(instance));
                tile.variationIndex  = (byte)(int)_fiTileInstance_variationIndex.GetValue(instance);
                tile.Empty           = false;
                tile.gameObject      = instance.gameObject;
                piTileData_hasGameObject.SetValue(tile, true, null);

                v2.SetTileFrom(row, column, tile);

                Chunk chunk = v2.GetChunkFromTileIndex(row, column);
                ForceRepaintForAtlasTiles(v2.GetTile(row, column), chunk);
                if (instance == null)
                {
                    continue;
                }

                // Cleanup original tile instance?
                if (!StrippingUtility.StripEmptyGameObject(instance.transform))
                {
                    // Reparent game object to its shiny new chunk!
                    instance.gameObject.transform.parent = chunk.transform;
                }

                // Destroy unwanted tile instance component
                Object.DestroyImmediate(instance);
            }

            int count = v2.EndBulkEdit();
            RemoveTileSystem(v1);

            if (count > 0)
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed and {1} tile(s) were force refreshed.", v2.name, count));
            }
            else
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed.", v2.name));
            }
        }
        finally {
            EditorUtility.ClearProgressBar();
        }
    }
Beispiel #19
0
 public static TileData GetTileInfo(this TileSystem map, int x, int y)
 {
     return(map.GetTile(y, x));
 }
        /// <summary>
        /// Determines orientation of the specified tile based upon the tiles which surround it.
        /// </summary>
        /// <param name="system">Tile system.</param>
        /// <param name="row">Zero-based index of tile row.</param>
        /// <param name="column">Zero-based index of tile column.</param>
        /// <param name="brush">Brush to consider orientation of.</param>
        /// <param name="rotation">Zero-based index of simple rotation (0 = 0�, 1 = 90�, 2 = 180�, 3 = 270�).</param>
        /// <returns>
        /// Bitmask representing orientation of tile.
        /// </returns>
        public static int DetermineTileOrientation(TileSystem system, int row, int column, Brush brush, int rotation = 0)
        {
            // Is orientation obvious?
            var coalescableBrush = brush as ICoalescableBrush;

            if (coalescableBrush == null || coalescableBrush.Coalesce == Coalesce.None)
            {
                return(0);//"00000000";
            }

            int orientation = 0, i = 0;

            // Take local copy of property values.
            Coalesce coalesce            = coalescableBrush.Coalesce;
            bool     coalesceWithRotated = coalescableBrush.CoalesceWithRotated;

            // Determine orientation of specified tile by analysing surrounding tiles.
            for (int ir = row - 1; ir <= row + 1; ++ir)
            {
                // Skip non-existent row!
                if (ir < 0 || ir >= system.RowCount)
                {
                    //orientation += "000";
                    i += 3;
                    continue;
                }

                for (int ic = column - 1; ic <= column + 1; ++ic)
                {
                    // Skip non-existent column!
                    if (ic < 0 || ic >= system.ColumnCount)
                    {
                        //orientation += "0";
                        ++i;
                        continue;
                    }

                    // Skip targetted tile!
                    if (ir == row && ic == column)
                    {
                        continue;
                    }

                    // Fetch tile from system.
                    TileData tile = system.GetTile(ir, ic);
                    if (tile != null && tile.brush != null && (rotation == tile.PaintedRotation || coalesceWithRotated))
                    {
                        switch (coalesce)
                        {
                        case Coalesce.Own:
                            if (tile.brush == brush)
                            {
                                orientation |= 1 << i;
                            }
                            break;

                        case Coalesce.Other:
                            if (tile.brush != brush)
                            {
                                orientation |= 1 << i;
                            }
                            break;

                        case Coalesce.Any:
                            orientation |= 1 << i;
                            break;

                        case Coalesce.Groups:
                            if (coalescableBrush.CoalesceWithBrushGroups.Contains(tile.brush.group))
                            {
                                orientation |= 1 << i;
                            }
                            break;

                        case Coalesce.OwnAndGroups:
                            if (tile.brush == brush || coalescableBrush.CoalesceWithBrushGroups.Contains(tile.brush.group))
                            {
                                orientation |= 1 << i;
                            }
                            break;
                        }
                    }

                    //orientation += "0";
                    ++i;
                }
            }

            if (coalescableBrush.CoalesceWithBorder)
            {
                orientation = CoalesceOrientationWithBorder(system, row, column, orientation);
            }

            // Counteract base rotation transform to orientation?
            return(OrientationUtility.RotateAntiClockwise(orientation, rotation));
        }
Beispiel #21
0
        public bool checkTile(string arrow)
        {
            playerTileIndex = tileSystem.ClosestTileIndexFromWorld(playerTransform.position);
            int x = playerTileIndex.row;
            int y = playerTileIndex.column;

            switch (arrow)
            {
            case "up":
                x -= 1;
                break;

            case "down":
                x += 1;
                break;

            case "left":
                y -= 1;
                break;

            case "right":
                y += 1;
                break;

            default:
                break;
            }
            if (x < 0 || y < 0 || x > 10 || y > 10)
            {
                return(false);
            }
            otherTileData = tileSystem.GetTile(x, y);
            if (otherTileData != null)
            {
                if (otherTileData.GetUserFlag(1))
                {
                    //AM.talk(x, y, otherTileData);
                    otherTileData.gameObject.GetComponent <Talk>().Execute(x, y, otherTileData);
                    return(false);
                }
                if (otherTileData.GetUserFlag(2))
                {
                    otherTileData.gameObject.GetComponent <Daoju>().Execute(x, y, otherTileData);
                    //AM.daoju(x, y, otherTileData);
                    return(true);
                }
                if (otherTileData.GetUserFlag(3))
                {
                    otherTileData.gameObject.GetComponent <Guaiwu>().Execute(x, y, otherTileData);
                    //AM.guaiwu();
                    return(false);
                }
                if (otherTileData.GetUserFlag(4))
                {
                    //AM.door(x, y, otherTileData);
                    otherTileData.gameObject.GetComponent <TRAnimation>().Execute(x, y, otherTileData);
                    return(false);
                }
                if (otherTileData.GetUserFlag(5))
                {
                    otherTileData.gameObject.GetComponent <Key>().Execute(x, y, otherTileData);
                    //AM.key(x, y, otherTileData);
                    return(true);
                }
                if (otherTileData.GetUserFlag(6))
                {
                    //AM.stair(x, y, otherTileData);
                    otherTileData.gameObject.GetComponent <Stair>().Execute(x, y, otherTileData);
                    return(false);
                }
                if (otherTileData.GetUserFlag(7))
                {
                    otherCommand.tujian(x, y, otherTileData);
                    return(true);
                }
                if (otherTileData.GetUserFlag(8))
                {
                    otherCommand.feixing(x, y, otherTileData);
                    return(true);
                }
                if (otherTileData.GetUserFlag(9))
                {
                    otherCommand.boss(x, y, otherTileData);
                    return(true);
                }
                if (otherTileData.SolidFlag)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
Beispiel #22
0
        public void LoadGame()
        {
            using (ES2Reader reader = ES2Reader.Create("player"))
            {
                PlayerInfo.Instance.Data.Level.Value      = reader.Read <int>("dengji");
                PlayerInfo.Instance.Data.Gold.Value       = reader.Read <int>("jinbi");
                PlayerInfo.Instance.Data.Experience.Value = reader.Read <int>("jingyan");
                PlayerInfo.Instance.Data.Life.Value       = reader.Read <int>("shengming");
                PlayerInfo.Instance.Data.Attack.Value     = reader.Read <int>("gongji");
                PlayerInfo.Instance.Data.Defence.Value    = reader.Read <int>("fangyu");
                PlayerInfo.Instance.Data.KeyYellow.Value  = reader.Read <int>("key_yellow");
                PlayerInfo.Instance.Data.KeyBlue.Value    = reader.Read <int>("key_blue");
                PlayerInfo.Instance.Data.KeyRed.Value     = reader.Read <int>("key_red");
                PlayerInfo.Instance.Data.HandBook.Value   = reader.Read <bool>("daoju_tujian");
                PlayerInfo.Instance.Data.Fly.Value        = reader.Read <bool>("daoju_feixing");
                GM.MaxFloor.Value = reader.Read <int>("maxFloor");
                Dialoguer.SetGlobalBoolean(0, reader.Read <bool>("hasJinglingTalked"));
                Dialoguer.SetGlobalBoolean(1, reader.Read <bool>("hasDaozeiTalked"));
                Dialoguer.SetGlobalBoolean(2, reader.Read <bool>("hasGoodJian"));
                Dialoguer.SetGlobalBoolean(3, reader.Read <bool>("hasGoodDun"));
                Dialoguer.SetGlobalBoolean(4, reader.Read <bool>("hasGangJian"));
                Dialoguer.SetGlobalBoolean(5, reader.Read <bool>("hasGangDun"));
            }
#if UNITY_WP8
            for (int i = 0; i < GM.MaxFloor + 1; i++)
            {
                GM.floorGO[i].SetActive(true);
                using (ES2Reader reader = ES2Reader.Create("floor" + i))
                {
                    TileSystem ts_object = GameObject.Find("Floor" + i).gameObject.GetComponent <TileSystem>();
                    for (int x = 0; x < 11; x++)
                    {
                        for (int y = 0; y < 11; y++)
                        {
                            int hasTile = reader.Read <int>(x + "v" + y);
                            if (sceneData[i] == null)
                            {
                                sceneData[i] = new int[11, 11];
                            }
                            sceneData[i][x, y] = hasTile;
                            if (sceneData[i][x, y] != null && sceneData[i][x, y] == 1)
                            {
                                TileData tile = ts_object.GetTile(x, y);
                                if (tile != null)
                                {
                                    GameObject.Destroy(tile.gameObject);
                                    tile.Clear();
                                }
                            }
                        }
                    }
                }
                GM.floorGO[i].SetActive(false);
            }
#else
            for (int i = 0; i < GM.MaxFloor.Value + 1; i++)
            {
                GM.floorGO[i].SetActive(true);
                sceneData[i] = ES2.Load2DArray <int>("floor" + i);
                TileSystem ts_object = GameObject.Find("Floor" + i).gameObject.GetComponent <TileSystem>();
                for (int x = 0; x < 11; x++)
                {
                    for (int y = 0; y < 11; y++)
                    {
                        if (sceneData[i][x, y] == 1)
                        {
                            TileData tile = ts_object.GetTile(x, y);
                            if (tile != null)
                            {
                                GameObject.Destroy(tile.gameObject);
                                tile.Clear();
                            }
                        }
                    }
                }
                GM.floorGO[i].SetActive(false);
            }
#endif
            GM.floorGO[0].SetActive(true);
            DM.state = "";
            PlayerPrefs.DeleteKey("loadgame");
            DM.tipContent = "读取成功";
            DM.tipTime    = 3;
        }