Beispiel #1
0
        void EditTileState(Tile tile, int mouseClick = 0, Vector3 hitPos = default(Vector3))
        {
            Undo.RecordObject(tile, "Tile");

            if (tileState == _TileStateE.Unwalkable)
            {
                if (tile.HasObstacle())
                {
                    Debug.LogWarning("Cannot set tile to unwalkable. Clear obstacle on tile first", this); return;
                }
                Undo.RecordObject(tile.gameObject, "Tile");
                tile.walkable = false;
                tile.gameObject.SetActive(false);
            }
            else if (tileState == _TileStateE.Default)
            {
                if (tile.HasObstacle())
                {
                    Debug.LogWarning("Cannot set tile to walkable. Clear obstacle on tile first", this); return;
                }
                Undo.RecordObject(tile.gameObject, "Tile");
                tile.walkable = true;
                tile.gameObject.SetActive(true);
            }
            else if (tileState == _TileStateE.WallH || tileState == _TileStateE.WallF)
            {
                if (tile.HasObstacle())
                {
                    Debug.LogWarning("Cannot add/remove wall. Clear obstacle on tile first", this); return;
                }

                Grid    grid  = instance.GetGrid();
                Vector3 dir   = hitPos - tile.GetPos();
                float   angle = 0;
                if (instance.tileType == _TileType.Square)
                {
                    angle = Utilities.VectorToAngle90(new Vector2(dir.x, dir.z));
                }
                else if (instance.tileType == _TileType.Hex)
                {
                    angle = Utilities.VectorToAngle60(new Vector2(dir.x, dir.z));
                }

                Tile neighbourTile = grid.GetNeighbourInDir(tile, angle);
                if (neighbourTile == null)
                {
                    Debug.LogWarning("Cannot add/remove wall. There's no adjacent tile", this); return;
                }
                if (neighbourTile.HasObstacle())
                {
                    Debug.LogWarning("Cannot add/remove wall. Clear obstacle on neighbour tile first", this); return;
                }

                if (mouseClick == 0)
                {
                    tile.AddWall(angle, neighbourTile, tileState == _TileStateE.WallH ? 1 : 2);
                }
                else
                {
                    tile.RemoveWall(angle, neighbourTile);
                }
            }
            else if (tileState == _TileStateE.ObstacleH || tileState == _TileStateE.ObstacleF)
            {
                if (mouseClick == 1)
                {
                    tile.RemoveObstacle();
                }
                else
                {
                    ClearSpawnTile(tile);
                    ClearDeployableTile(tile);
                    tile.AddObstacle(tileState == _TileStateE.ObstacleH ? 1 : 2, instance.grid.GetTileSize());
                }
            }
            else if (tileState == _TileStateE.SpawnArea)
            {
                if (tile.HasObstacle())
                {
                    return;
                }

                if (spawnAreaFactionID >= factionManager.factionList.Count)
                {
                    return;
                }
                if (spawnAreaInfoID >= factionManager.factionList[spawnAreaFactionID].spawnInfoList.Count)
                {
                    return;
                }

                Undo.RecordObject(factionManager, "FactionManager");

                Faction fac = null;

                if (mouseClick == 1)
                {
                    ClearSpawnTile(tile);
                }
                else
                {
                    fac = factionManager.factionList[spawnAreaFactionID];
                    if (tile.spawnAreaID != fac.ID)
                    {
                        ClearSpawnTile(tile);
                    }

                    if (!fac.spawnInfoList[spawnAreaInfoID].startingTileList.Contains(tile))
                    {
                        fac.spawnInfoList[spawnAreaInfoID].startingTileList.Add(tile);
                        tile.spawnAreaID = fac.ID;
                    }
                }
            }
            else if (tileState == _TileStateE.Deployment)
            {
                if (tile.HasObstacle())
                {
                    return;
                }

                if (deployAreaFactionID >= factionManager.factionList.Count)
                {
                    return;
                }

                Undo.RecordObject(factionManager, "FactionManager");

                Faction fac = null;

                if (mouseClick == 1)
                {
                    ClearDeployableTile(tile);
                }
                else
                {
                    fac = factionManager.factionList[deployAreaFactionID];
                    if (tile.deployAreaID != fac.ID)
                    {
                        ClearDeployableTile(tile);
                    }

                    if (!fac.deployableTileList.Contains(tile))
                    {
                        fac.deployableTileList.Add(tile);
                        tile.deployAreaID = fac.ID;
                    }
                }
            }
        }