public FireCell(Vector2Int _gridPosition, Vector3 _centerPoint, Vector3 _normal) { gridPosition = _gridPosition; centerPoint = _centerPoint; normal = _normal; adjacentCells = new List<Vector2Int>(); }
public Radar(Vector2Int location, User owner, int radius) : base(location, owner, StructureType.Radar) { Radius = radius; extraData = new RadarData(Radius); VisibleStructures = new List<Vector2Int>(); }
public static bool CanSeePoint(RadarData[] radar, Vector2Int point) { for (int i = 0; i < radar.Length; i++) { if (CanSeePoint(radar[i], point)) return true; } return false; }
public bool CanCreateStructure(Vector2Int location) { Vector2Int topLeft = new Vector2Int(location.x - AppSettings.MinOpDistance, location.y + AppSettings.MinOpDistance); Vector2Int bottomRight = new Vector2Int(location.x + AppSettings.MinOpDistance, location.y - AppSettings.MinOpDistance); Vector2Int[] nearOps = GetStructureLocations(topLeft, bottomRight); int opsInCircle = RadarUtility.GetVisibleObjects(new RadarUtility.RadarData(location, AppSettings.MinOpDistance), nearOps).Length; return opsInCircle == 0; }
public LowPolyTerrainTile GetTile(Vector2Int pos) { if (pos.x < 0 || pos.x >= Width || pos.y < 0 || pos.y >= Height) { return LowPolyTerrainTile.NullTile; } return Data[pos.y * Width + pos.x]; }
public void SetVisibleStructures(Vector2Int topLeft, Vector2Int bottomRight) { Vector2Int[] structurePositions = GameServer.Instance.Structures.GetStructureLocations(topLeft, bottomRight); Logger.Log("structures in square: " + structurePositions.Length); //VisibleStructures = new List<Vector2Int>(RadarUtility.GetVisibleObjects(new RadarUtility.RadarData(Location, Radius), structurePositions)); VisibleStructures = new List<Vector2Int>(GetVisibleLocations(structurePositions)); Logger.Log("Structures found: " + VisibleStructures.Count); }
public Structure(Vector2Int location, User owner, StructureType type) { _commands = new Dictionary<string, Command>(); Squads = new List<Squad>(); Enabled = true; Location = location; Owner = owner; Type = type; }
private void ClaimInDirection(GameLogic logic, Vector2Int direction) { Vector2Int toClaim = positionOnBoard + direction; while (logic.GameBoard.IsValidPlayerMove(toClaim)) { logic.GameBoard.SetOwner(toClaim, GameLogic.Owner.Player); toClaim += direction; } }
public static Vector2Int[] GetVisibleObjects(RadarData radar, Vector2Int[] points) { List<Vector2Int> seenPoints = new List<Vector2Int>(); for (int i = 0; i < points.Length; i++) { if (CanSeePoint(radar, points[i])) { seenPoints.Add(points[i]); } } return seenPoints.ToArray(); }
public static Vector2Int[] GetCardinalDirections() { Vector2Int[] directions = new Vector2Int[4]; directions[0] = Left; directions[1] = Right; directions[2] = Up; directions[3] = Down; return directions; }
protected override void LoadContent() { this._visualizationData = new VisualizationData(); this._referencePosition = new Vector2Int((int)this._player.Position.X - this._visualizationData.Frequencies.Count / 2, (int)this._player.Position.Z); MediaPlayer.Volume = 1f; MediaPlayer.IsVisualizationEnabled = true; new Thread(VisualizationReader) { IsBackground = true }.Start(); this._song = Game.Content.Load<Song>("yael"); MediaPlayer.Play(this._song); }
public bool HasPosition(Vector2Int position) { for (var i = 0; i < Positions.Count; i++) { if (Positions[i] == position) { return true; } } return false; }
public Squad[] GetTravelingSquads(Vector2Int topLeft, Vector2Int bottomRight) { List<Squad> result = new List<Squad>(); foreach (Squad squad in _squads.Values) { if (!squad.atStructure && squad.location.x >= topLeft.x && squad.location.x <= bottomRight.x && squad.location.y <= topLeft.y && squad.location.y >= bottomRight.y) { result.Add(squad); } } return result.ToArray(); }
public static PowerUp GetRandomPowerUp(Vector2Int position) { if (powerUps == null) { InitPowerUps(); } int index = UnityEngine.Random.Range(0, 3); PowerUp powerUp = powerUps[index].Create(); powerUp.PositionOnBoard = position; return powerUp; }
public void Initialize( int x, int y ) { _positionInt = new Vector2Int(x, y); _visualCube = GameObject.CreatePrimitive(PrimitiveType.Quad); _visualCube.transform.parent = this.transform; Destroy(_visualCube.collider); gameObject.AddComponent<BoxCollider2D>(); transform.position = new Vector3(0.5F + x + (x * 0.1F), 0.5F + y + (y * 0.1F), 0); Reset(); }
public void InitializeFireGrid() { activeCells = new List<FireCell> (); depletedCells = new List<FireCell> (); mapSize = ForestController.Instance.mapSize; mapSize.y = ForestController.Instance.maxTerrainHeight; cellsX = Mathf.FloorToInt(mapSize.x / gridSize); cellsY = Mathf.FloorToInt(mapSize.z / gridSize); cells = new FireCell[cellsX,cellsY]; if (particlesContainer) { Destroy(particlesContainer.gameObject); } particlesContainer = new GameObject ("Fire Particles Container").transform; particlesContainer.parent = transform; burntTextureSettings.InitializeTexture(cellsX, cellsY); cellExtents = new Vector3 (gridSize / 2f, mapSize.y / 2f, gridSize / 2f); RaycastHit hit; for (int x = 0; x < cellsX; x++) { for (int y = 0; y < cellsY; y++) { Vector2Int gridPosition = new Vector2Int (x, y); Vector3 centerPoint = new Vector3 (((float)x / (float)cellsX - .5f) * mapSize.x, mapSize.y + .5f, ((float)y / (float)cellsY - .5f) * mapSize.z); Vector3 normal = Vector3.up; if (Physics.Raycast(centerPoint, Vector3.down, out hit, mapSize.y + 20f, ForestController.Instance.terrainLayerMask)) { centerPoint = hit.point; normal = hit.normal; } cells[x, y] = new FireCell (gridPosition, centerPoint, normal); cells[x, y].InitializeFuelInfo(cellExtents, fuelFromCellDensity); GameObject newGroundParticles = GameObject.Instantiate(groundFireParticles, centerPoint, Quaternion.LookRotation(normal)) as GameObject; newGroundParticles.name = groundFireParticles.name + " [" + x.ToString() + "," + y.ToString() + "]"; newGroundParticles.transform.parent = particlesContainer; cells[x, y].groundParticles = newGroundParticles.GetComponent<FireParticleEffect>(); cells[x, y].groundParticles.cell = cells[x, y]; } } }
public void GenerateInitialWalls (Transform newTerrainObject, Vector3[] newTerrainVertices, Vector2Int newGridSize, Vector3 newMapSize) { terrainObject = newTerrainObject; terrainVertices = newTerrainVertices; gridSize = newGridSize; mapSize = newMapSize; normalBumpiness.Initialize(CustomMathf.GetRandomSeed()); vertexDisplacementSettings.displacementNoise.Initialize(CustomMathf.GetRandomSeed()); CreateWallObjects(); CreateWallMeshes(); }
private static void CheckQuadrant( HashSet<Vector2Int> visited, Vector2Int start, int dx, int dy, int extentX, int extentY, Action<Vector2Int> funcVisitTile, Func<Vector2Int, bool> funcTileBlocked) { var activeViews = new List<View>(); var shallowLine = new Line(0, 1, extentX, 0); var steepLine = new Line(1, 0, 0, extentY); activeViews.Add(new View(shallowLine, steepLine)); int viewIndex = 0; // Visit the tiles diagonally and going outwards // // . // . // . . // 9 . // 5 8 . // 2 4 7 // @ 1 3 6 . . . int maxI = extentX + extentY; int i = 1; while (i != maxI + 1 && activeViews.Count > 0) { int startJ = 0 > i - extentX ? 0 : i - extentX; int maxJ = i < extentY ? i : extentY; int j = startJ; while (j != maxJ + 1 && viewIndex < activeViews.Count) { int x = i - j; int y = j; VisitCoord(visited, start, x, y, dx, dy, viewIndex, activeViews, funcVisitTile, funcTileBlocked); j += 1; } i += 1; } }
public LowPolyTerrainTile(int x, int y) { Position = new Vector2Int(x, y); IsEven = ((x + y) % 2) == 0; var xpos = x * TriHalfWidth; var ypos = y * TriHeight; if (IsEven) { Corner1 = new Vector3(xpos, 0.0f, ypos + TriHeight); Corner2 = new Vector3(xpos + TriWidth, 0.0f, ypos + TriHeight); Corner3 = new Vector3(xpos + TriHalfWidth, 0.0f, ypos); } else { Corner1 = new Vector3(xpos, 0.0f, ypos); Corner2 = new Vector3(xpos + TriHalfWidth, 0.0f, ypos + TriHeight); Corner3 = new Vector3(xpos + TriWidth, 0.0f, ypos); } }
public SmoothColorFilterGrid (int _filterSize, int _totalWidth, int _totalHeight, Curve _smoothingCurve) { filterSize = _filterSize; totalWidth = _totalWidth; totalHeight = _totalHeight; filterGrid = new float[filterSize, filterSize]; center = (filterSize - 1) / 2; centerPoint = new Vector2Int (center, center); maxSampleDistance = (float)center * CustomMathf.sqrt2; samplePoint = new Vector2 (0,0); float sampleDistance = 0f; float sampleModifier = 0f; for (int x = 0; x < filterSize; x++) { for (int y = 0; y < filterSize; y++) { samplePoint.x = x; samplePoint.y = y; sampleDistance = 1f - ((samplePoint - centerPoint).magnitude / maxSampleDistance); filterGrid[x, y] = _smoothingCurve.GetValue(sampleDistance); sampleModifier += filterGrid[x, y]; } } //normalize the filter amount sampleModifier = 1f / sampleModifier; for (int x = 0; x < filterSize; x++) { for (int y = 0; y < filterSize; y++) { filterGrid[x, y] *= sampleModifier; } } }
public float[,] Flatten (float[,] grid, float _gridScaleX, float _gridScaleY) { gridScaleX = _gridScaleX; gridScaleY = _gridScaleY; filterSize = filterRadius * 2 + 1; width = grid.GetLength(0); height = grid.GetLength(1); center = (filterSize - 1) / 2; centerPoint = new Vector2Int (center, center); maxNeighborDistance = (float)center * CustomMathf.sqrt2; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { SamplePoint(ref grid, x, y); } } // int gridPoints = (width * height); // int samplePoints = gridPoints * filterSize * filterSize; // Debug.Log("Flattening " + gridPoints.ToString("E2") + " points (" + samplePoints.ToString("E2") + " samples) took " + (Time.realtimeSinceStartup - lastTime).ToString("E2") + " seconds"); return grid; }
public void ApplyColor (Vector2Int gridPosition, float color) { ApplyColor(gridPosition.x, gridPosition.y, color); }
public void CreateFire (Vector3 startingPoint) { Vector2Int startingCell = new Vector2Int(0,0); float closestDistance = Mathf.Infinity; //have to deactivate all cells before we add the adjacent cells in the next loop for (int x = 0; x < cellsX; x++) { for (int y = 0; y < cellsY; y++) { cells[x, y].activated = false; } } for (int x = 0; x < cellsX; x++) { for (int y = 0; y < cellsY; y++) { cells[x, y].InitializeFuelInfo(cellExtents, fuelFromCellDensity); AddAdjacentCells(cells[x, y]); float checkDistance = (cells[x, y].centerPoint - startingPoint).sqrMagnitude; if (checkDistance < closestDistance) { closestDistance = checkDistance; startingCell = cells[x, y].gridPosition; } } } IgniteCell(ref cells[startingCell.x, startingCell.y]); InvokeRepeating("UpdateFire", burnUpdateInterval, burnUpdateInterval); }
public bool ContainCoords(Vector2Int coords) { return(mapInfoHandler.ContainCoords(coords)); }
//should only be called by other UpdateDrawPosition methods, otherwise behaviour might be weird private void UpdateInternalPosition(int index, Vector2Int loc) { tokens[index].transform.position = ConvertLocationToTransformVector3(loc); }
void DrawAliveCell(Vector2Int pos) { Gizmos.color = cells[pos.x, pos.y].region < 0 ? Color.clear : colors[cells[pos.x, pos.y].region % colors.Count]; Gizmos.DrawCube(new Vector3(pos.x, pos.y, 0), Vector2.one); }
public abstract List<Vector2Int> GetAvailableMoves(Vector2Int position, Board board);
void InstantiateRoom(int x, int y, bool start, bool end, RoomPrefabs prefabs, AdjacencyList graph) { GameObject prefab = null; Quaternion q = Quaternion.identity; Vector2Int v = new Vector2Int(x, y); bool spawn_enemies = false; switch (graph[v].Count) { case 1: prefab = prefabs.OneDoor[Random.Range(0, prefabs.OneDoor.Length)]; q = Quaternion.AngleAxis(Vector2.SignedAngle(graph[v][0] - v, Vector2.up), Vector3.up); break; case 2: if (Mathf.Approximately(Vector2.Dot(graph[v][0] - v, graph[v][1] - v), 0)) { prefab = prefabs.TwoDoorL[Random.Range(0, prefabs.TwoDoorL.Length)]; Vector2Int u = (Vector2.SignedAngle(graph[v][0] - v, graph[v][1] - v) < 0f) ? graph[v][0] : graph[v][1]; q = Quaternion.AngleAxis(Vector2.SignedAngle(u - v, Vector2.up), Vector3.up); } else { prefab = prefabs.TwoDoorStraight[Random.Range(0, prefabs.TwoDoorStraight.Length)]; q = Quaternion.AngleAxis(Vector2.Angle(graph[v][0] - v, Vector2.up), Vector3.up); } spawn_enemies = (Random.Range(0, 4) == 0) ? false : true; break; case 3: prefab = prefabs.ThreeDoor[Random.Range(0, prefabs.ThreeDoor.Length)]; Vector2Int w = (Mathf.Approximately(Vector2.Dot(graph[v][0] - v, graph[v][1] - v), -1f)) ? graph[v][2] : (Mathf.Approximately(Vector2.Dot(graph[v][0] - v, graph[v][2] - v), -1f) ? graph[v][1] : graph[v][0] ); q = Quaternion.AngleAxis(Vector2.SignedAngle(w - v, Vector2.up), Vector3.up); spawn_enemies = (Random.Range(0, 4) == 0) ? false : true; break; default: prefab = prefabs.FourDoor[Random.Range(0, prefabs.FourDoor.Length)]; break; } if (start) { prefab = prefabs.OneDoor[0]; } if (end) { prefab = prefabs.OneDoor[0]; } Vector3 pos = (Vector3.right * x * (room_size + margin)) + (Vector3.forward * y * (room_size + margin)); GameObject room = Instantiate(prefab, pos, q); if (spawn_enemies) { int num_enemies = Random.Range(1, 4); Quaternion offset = Quaternion.AngleAxis(Random.Range(0f, 360f), Vector3.up); for (int i = 0; i < num_enemies; i++) { Instantiate(enemy_prefab, pos + (Quaternion.AngleAxis((float)(360 * (i + 1) / num_enemies), Vector3.up) * offset * (Vector3.forward * room_size / 3)), Quaternion.AngleAxis(Random.Range(0f, 360f), Vector3.up)); } } if (start) { player.transform.position = room.transform.position + Vector3.up; } if (end) { level_transition.transform.position = room.transform.position; } }
public bool Equals(Vector2Int other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.x == x && other.y == y; }
public void SetBoardPos(Vector2Int boardPos) { this.boardPos = boardPos; }
private void Update() { Vector3 currentPos = Camera.main.ScreenToViewportPoint(Input.mousePosition); if (currentPos.y < 0.75f && currentPos.y > 0.25f && !(currentPos.x > selectMenuMin.x && currentPos.x < selectMenuMax.x && currentPos.y > selectMenuMin.y && currentPos.y < selectMenuMax.y)) { Vector3Int cellPosition = grid.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)); Vector2Int worldPosition = new Vector2Int(cellPosition.x, -cellPosition.y + 50); if (xPos != worldPosition.x || yPos != worldPosition.y) { if (worldPosition.x < 0 || worldPosition.x > 49 || worldPosition.y < 0 || worldPosition.y > 49) { if (selector.activeSelf) { selector.SetActive(false); } } else { if (!selector.activeSelf) { selector.SetActive(true); } Vector3 newCursorPos = new Vector3((cellPosition.x * 0.16f) + 0.08f, (cellPosition.y * 0.16f) + 0.08f, -3.0f); selector.transform.position = newCursorPos; } xPos = worldPosition.x; yPos = worldPosition.y; updateCursorText(worldPosition); } if (Input.GetMouseButtonDown(0)) { distance = Vector3.zero; touchStartTile = worldPosition; if (touchStart == Vector3.zero) { touchStart = Camera.main.ViewportToScreenPoint(Input.mousePosition); } if (selectMenu.activeSelf) { //selectMenu.GetComponent<SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); selectMenu.SetActive(false); } } if (Input.GetMouseButton(0)) { distance += touchStart - Camera.main.ViewportToScreenPoint(Input.mousePosition); } if (Input.GetMouseButtonUp(0) && touchStartTile == worldPosition && touchStart != Vector3.zero) { //Debug.Log(distance); if (Mathf.Abs(distance.x) < 1000 && Mathf.Abs(distance.y) < 1000) { // this is the selected tile string xOut = worldPosition.x < 10 ? "0" + worldPosition.x.ToString() : worldPosition.x.ToString(); string yOut = worldPosition.y < 10 ? "0" + worldPosition.y.ToString() : worldPosition.y.ToString(); string sendingPos = xOut + yOut; selectableObs = objectLoader.GetSelectablesAtTile(sendingPos); if (selectableObs == null) { updateCurrentSelection(-1); touchStart = Vector3.zero; selectMenuMin = Vector2.zero; selectMenuMax = Vector2.zero; return; } if (selectableObs.Length > 1) { int maxStringLength = 0; foreach (ObjectsLoader.RoomObject t in selectableObs) { maxStringLength = maxStringLength > t.type.Length ? maxStringLength : t.type.Length; } float stringScaler = maxStringLength * 0.03f; float countScaler = selectableObs.Length * 0.08f; Action <int> callback = new Action <int>(updateCurrentSelection); float maxX = (currentPos.x + stringScaler) > 1 ? 1.0f : currentPos.x + stringScaler; float minY = (currentPos.y - countScaler) < 0.25f ? 0.25f : currentPos.y - countScaler; Vector2 maxMenuPos = new Vector2(maxX, minY + countScaler); Vector2 minMenuPos = new Vector2(maxMenuPos.x - stringScaler, minY + countScaler); selectMenu.SetActive(true); selectMenu.GetComponent <RectTransform>().anchorMin = minMenuPos; selectMenu.GetComponent <RectTransform>().anchorMax = maxMenuPos; selectMenu.GetComponent <SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); GameObject dropdownMenu; try { dropdownMenu = selectMenu.transform.Find("Dropdown List").gameObject; } catch { // TODO: instantiate a backup, this is a bug when clicking out of menu and it becomes permanantly destroyed Destroy(selectMenu); Debug.Log("fix this ControlsPanel.cs error"); selectMenu = Instantiate(SelectablesDropdown, this.gameObject.transform); selectMenu.SetActive(true); selectMenu.GetComponent <RectTransform>().anchorMin = minMenuPos; selectMenu.GetComponent <RectTransform>().anchorMax = maxMenuPos; selectMenu.GetComponent <SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); dropdownMenu = selectMenu.transform.Find("Dropdown List").gameObject; } GameObject selectMenuViewport = dropdownMenu.transform.Find("SelectablesViewport").gameObject; RectTransform openMenu = selectMenuViewport.GetComponent <RectTransform>(); Vector2 openMenuMin = Camera.main.ScreenToViewportPoint(openMenu.rect.min); //Vector2 openMenuMax = Camera.main.ScreenToViewportPoint(openMenu.rect.max); selectMenuMin = minMenuPos + openMenuMin; selectMenuMax = maxMenuPos; } if (selectableObs.Length == 1) { selectMenuMin = Vector2.zero; selectMenuMax = Vector2.zero; updateCurrentSelection(0); } } touchStart = Vector3.zero; } } if (ObjectsLoader.gameTime > lastTime) { if (currentSelection == null) { } else if (currentSelection._id != null) { if (currentSelection._id.Length > 0) { currentSelection = objectLoader.GetObjectByID(currentSelection._id); selectableObs = new ObjectsLoader.RoomObject[] { currentSelection }; updateCurrentSelection(0); } } lastTime = ObjectsLoader.gameTime; updateTimeText(); } }
public bool IdxIsOnGrid(Vector2Int idx) { return((idx.x < _width && idx.x > -1) && (idx.y < _height && idx.y > -1)); }
void Start() { direction = new Vector2Int((int)transform.forward.x, (int)transform.forward.z); cellData = new CellData(this.gameObject, 1); gameGrid.PlaceGameObjectOnCell(cellData, position.x, position.y); }
/*********************************************************************** * Mesh Generate ***********************************************************************/ #region . private void GeneratePlane(out Vector3[] verts, out int[] tris, out Vector2 gridUnit, out Vector2Int vCount) { Vector3 widthV3 = new Vector3(_width, 0f, _width); // width를 3D로 변환 Vector3 startPoint = -widthV3 * 0.5f; // 첫 버텍스의 위치 gridUnit = Vector2.one * (_width / _resolution); // 그리드 하나의 너비 vCount = new Vector2Int(_resolution + 1, _resolution + 1); // 각각 가로, 세로 버텍스 개수 int vertsCount = vCount.x * vCount.y; int trisCount = _resolution * _resolution * 6; verts = new Vector3[vertsCount]; tris = new int[trisCount]; // 1. 버텍스 초기화 for (int j = 0; j < vCount.y; j++) { for (int i = 0; i < vCount.x; i++) { int index = i + j * vCount.x; verts[index] = startPoint + new Vector3( gridUnit.x * i, 0f, gridUnit.y * j ); } } // 2. 트리스 초기화 int tIndex = 0; for (int j = 0; j < vCount.y - 1; j++) { for (int i = 0; i < vCount.x - 1; i++) { int vIndex = i + j * vCount.x; tris[tIndex + 0] = vIndex; tris[tIndex + 1] = vIndex + vCount.x; tris[tIndex + 2] = vIndex + 1; tris[tIndex + 3] = vIndex + vCount.x; tris[tIndex + 4] = vIndex + vCount.x + 1; tris[tIndex + 5] = vIndex + 1; tIndex += 6; } } }
public Extend(Vector2Int pos) : base(pos) { }
public Edge(Vector2Int v, Vector2Int u) { this.v = v; this.u = u; }
public override bool CheckKineticPowerCanBeUsed(Vector2Int originCellNum, bool isRight) { // スタック中は動けないのでtrueを戻す if (CheckFlag(LANDSTAR_STAT.STUCKED)) { return(true); } var starMaker = StarMaker.Instance; var direction = StarMaker.GetDirection(originCellNum, CellNum); Vector2Int cp0 = CellNum; Vector2Int cp1 = CellNum; // チェックするコマを算出. if (isRight) { if (direction == Direction.Right) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Bottom); cp1 += StarMaker.GetDifferenceByDirection(Direction.LeftBottom); } else if (direction == Direction.RightTop) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Bottom); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Bottom); } else if (direction == Direction.Top) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Right); cp1 += StarMaker.GetDifferenceByDirection(Direction.RightBottom); } else if (direction == Direction.LeftTop) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Right); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Right); } else if (direction == Direction.Left) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Top); cp1 += StarMaker.GetDifferenceByDirection(Direction.RightTop); } else if (direction == Direction.LeftBottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Top); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Top); } else if (direction == Direction.Bottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Left); cp1 += StarMaker.GetDifferenceByDirection(Direction.LeftTop); } else if (direction == Direction.RightBottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Left); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Left); } else { return(false); // この条件に正であることはありえない. } } else { if (direction == Direction.Right) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Top); cp1 += StarMaker.GetDifferenceByDirection(Direction.LeftTop); } else if (direction == Direction.RightTop) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Left); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Left); } else if (direction == Direction.Top) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Left); cp1 += StarMaker.GetDifferenceByDirection(Direction.LeftBottom); } else if (direction == Direction.LeftTop) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Bottom); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Bottom); } else if (direction == Direction.Left) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Bottom); cp1 += StarMaker.GetDifferenceByDirection(Direction.RightBottom); } else if (direction == Direction.LeftBottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Right); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Right); } else if (direction == Direction.Bottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Right); cp1 += StarMaker.GetDifferenceByDirection(Direction.RightTop); } else if (direction == Direction.RightBottom) { cp0 += StarMaker.GetDifferenceByDirection(Direction.Top); cp1 = cp0 + StarMaker.GetDifferenceByDirection(Direction.Top); } else { return(false); // この条件に正であることはありえない. } } // マップ領域内かチェック if (!(starMaker.CheckLimitOfMap(cp0) && starMaker.CheckLimitOfMap(cp1))) { return(false); } // 絶対にtrueなパターンのチェック if (starMaker.GetStar(cp0, StarType.BlackHole)) // 先1マス目がブラックホール { return(true); } // 移動経路に邪魔する要素があるかチェック if (0 < starMaker.GetStarList(cp0, StarType.Rock).Count) // 先1マスにRockがある { return(false); } else if (starMaker.GetStarList(cp0, StarType.Land).Exists(obj => obj.GetComponent <LandStarController>().CheckFlag(LANDSTAR_STAT.STUCKED)) || // いずれのマスにミルキーウェイにつかまっているLandがある starMaker.GetStarList(cp1, StarType.Land).Exists(obj => obj.GetComponent <LandStarController>().CheckFlag(LANDSTAR_STAT.STUCKED))) { return(false); } else if (starMaker.GetStarList(cp0, StarType.Land).Exists(obj => !obj.GetComponent <LandStarController>().CheckFlag(LANDSTAR_STAT.STUCKED)) && // 1マス先に動けるLandがいて、2マス先にミルキーウェイがある. 0 < starMaker.GetStarList(cp1, StarType.MilkyWay).Count) { return(false); } return(true); }
public Vector3 GetBoardTilePosition(Vector2Int index) { return(BoardTiles[index.x][index.y].GetPositionRT()); }
//Accept message from Tokens, then run the relevant code public void InformTokenSelected(GameObject token, int x, int y) { //Checks to see if tokens are currently being animated, if so ignore selection if (IsCurrentlyAnimating()) { return; } Vector2Int loc = new Vector2Int(x, y); int index = ConvertLocationToIndex(loc); if (selected == -1) { //Nothing was selected, this token becomes selected if (!(token.CompareTag(tokenBlockTag))) //the selected token is not a block, so it can be normally selected. { token.GetComponent <TokenSelectedScript>().setSelected(true); selected = index; } } else if (selected == index) { //same token was clicked again, deselect that token deselect(); } else { //different token clicked, a move is attempted, then deselect //only do anything if the move is legal if (isAdjacent(selected, index)) { //GameObject prevSelectedToken = tokens[selected]; //BASIC MOVE swap(ConvertIndexToLocation(deselect()), loc); //set flags playerMoved = true; //attemptingMove = true; //POINT WHERE THIS CODE SHOUDL END /* * //check for matches on both ends of swap, process matches if they are larger than 0 * List<int> match1 = getMatch(selected); * List<int> match2 = getMatch(index); * * if (match1.Count > 0 || match2.Count > 0) //if there was a match produced, process * { * if (match1.Count > 0) processMatch(match1); * if (match2.Count > 0) processMatch(match2); * } else //if no match was produced, swap them back * { * swap(ConvertIndexToLocation(selected), loc); * } * //set tokens to deselected internally * //token.GetComponent<TokenSelectedScript>().setSelected(false); //currently unnecessary * prevSelectedToken.GetComponent<TokenSelectedScript>().setSelected(false); * * //set no token selected in GM * selected = -1; * * RepopulateBoard(); */ } else //if move wasn't legal, deselect the selected token to reset. { deselect(); } } }
//Converts a given {x,y} location on board to int value in index int ConvertLocationToIndex(Vector2Int loc) { return(loc.x + (loc.y * boardWidth)); }
IEnumerator GetRoom() { BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { if (!cells[x, y].isAlive) { continue; } if (cells[x, y].region != -1) { continue; } List <Vector2Int> openList = new List <Vector2Int>(); List <Vector2Int> closedList = new List <Vector2Int>(); openList.Add(new Vector2Int(x, y)); while (openList.Count > 0) { cells[openList[0].x, openList[0].y].region = currentRegion; closedList.Add(openList[0]); foreach (Vector2Int b in bounds.allPositionsWithin) { //Check not self if (b.x == 0 && b.y == 0) { continue; } //Check if is on cross if (b.x != 0 && b.y != 0) { continue; } Vector2Int pos = new Vector2Int(openList[0].x + b.x, openList[0].y + b.y); //Check inside bounds if (pos.x < 0 || pos.x >= size || pos.y < 0 || pos.y >= size) { continue; } //Check is alive if (!cells[pos.x, pos.y].isAlive) { continue; } //check region not yet associated if (cells[pos.x, pos.y].region != -1) { continue; } //Check if already visited if (closedList.Contains(pos)) { continue; } //Check if already set to be visited if (openList.Contains(pos)) { continue; //Error } openList.Add(new Vector2Int(pos.x, pos.y)); } openList.RemoveAt(0); yield return(null); } currentRegion++; yield return(new WaitForSeconds(0.1f)); } } }
public StructureCommand(string sessionKey, Vector2Int location, string command, string args) { this.sessionKey = sessionKey; this.location = location; this.command = command; this.args = args; }
// Moves the Piece to the starting position public void Spawn(Vector2Int newPoss) { poss = newPoss; Target = PiecesManager.GetTarget(newPoss); }
public None(Vector2Int location, User owner) : base(location, owner, StructureType.Outpost) { }
// Generates the gaussian pyramid of source into destination // We can't do it in place as the color pyramid has to be read while writing to the color // buffer in some cases (e.g. refraction, distortion) // Returns the number of mips public int RenderColorGaussianPyramid(CommandBuffer cmd, Vector2Int size, Texture source, RenderTexture destination) { // Select between Tex2D and Tex2DArray versions of the kernels int kernelIndex = (source.dimension == TextureDimension.Tex2DArray) ? kKernelTex2DArray : kKernelTex2D; // Sanity check if (kernelIndex == kKernelTex2DArray) { Debug.Assert(source.dimension == destination.dimension, "MipGenerator source texture does not match dimension of destination!"); Debug.Assert(m_ColorGaussianKernel.Length == kernelCount); } // Only create the temporary target on-demand in case the game doesn't actually need it if (m_TempColorTargets[kernelIndex] == null) { m_TempColorTargets[kernelIndex] = RTHandles.Alloc( Vector2.one * 0.5f, filterMode: FilterMode.Bilinear, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useMipMap: false, enableMSAA: false, xrInstancing: kernelIndex == kKernelTex2DArray, useDynamicScale: true, name: "Temp Gaussian Pyramid Target" ); } #if UNITY_SWITCH bool preferFragment = true; #else bool preferFragment = false; #endif int srcMipLevel = 0; int srcMipWidth = size.x; int srcMipHeight = size.y; int slices = destination.volumeDepth; if (preferFragment) { Debug.Assert(!TextureXR.useTexArray, "Fragment version of mip generator is not compatible with texture array!"); int tempTargetWidth = srcMipWidth >> 1; int tempTargetHeight = srcMipHeight >> 1; // Copies src mip0 to dst mip0 m_PropertyBlock.SetTexture(HDShaderIDs._BlitTexture, source); m_PropertyBlock.SetVector(HDShaderIDs._BlitScaleBias, new Vector4(1f, 1f, 0f, 0f)); m_PropertyBlock.SetFloat(HDShaderIDs._BlitMipLevel, 0f); cmd.SetRenderTarget(destination, 0); cmd.DrawProcedural(Matrix4x4.identity, HDUtils.GetBlitMaterial(source.dimension), 0, MeshTopology.Triangles, 3, 1, m_PropertyBlock); // Note: smaller mips are excluded as we don't need them and the gaussian compute works // on 8x8 blocks // TODO: Could be further optimized by merging the smaller mips to reduce the amount of dispatches // Specifically, levels 2x2 and 1x1 (or their variations, depending on the aspect ratio) should not be used. while (srcMipWidth >= 8 || srcMipHeight >= 8) { int dstMipWidth = Mathf.Max(1, srcMipWidth >> 1); int dstMipHeight = Mathf.Max(1, srcMipHeight >> 1); // Downsample. // Note: this code is not valid on D3D11 because destination is used both as an input and target m_PropertyBlock.SetTexture(HDShaderIDs._BlitTexture, destination); m_PropertyBlock.SetVector(HDShaderIDs._BlitScaleBias, new Vector4(1f, 1f, 0f, 0f)); m_PropertyBlock.SetFloat(HDShaderIDs._BlitMipLevel, srcMipLevel); cmd.SetRenderTarget(destination, srcMipLevel + 1); cmd.DrawProcedural(Matrix4x4.identity, HDUtils.GetBlitMaterial(source.dimension), 1, MeshTopology.Triangles, 3, 1, m_PropertyBlock); // Blur horizontal. m_PropertyBlock.SetTexture(HDShaderIDs._Source, destination); m_PropertyBlock.SetVector(HDShaderIDs._SrcScaleBias, new Vector4(1f, 1f, 0f, 0f)); m_PropertyBlock.SetVector(HDShaderIDs._SrcUvLimits, new Vector4(1f, 1f, 1f / dstMipWidth, 0f)); m_PropertyBlock.SetFloat(HDShaderIDs._SourceMip, srcMipLevel + 1); cmd.SetRenderTarget(m_TempColorTargets[kernelIndex], 0); cmd.SetViewport(new Rect(0, 0, dstMipWidth, dstMipHeight)); cmd.DrawProcedural(Matrix4x4.identity, m_ColorPyramidPSMat, 0, MeshTopology.Triangles, 3, 1, m_PropertyBlock); // Blur vertical. m_PropertyBlock.SetTexture(HDShaderIDs._Source, m_TempColorTargets[kernelIndex]); m_PropertyBlock.SetVector(HDShaderIDs._SrcScaleBias, new Vector4((float)dstMipWidth / tempTargetWidth, (float)dstMipHeight / tempTargetHeight, 0f, 0f)); m_PropertyBlock.SetVector(HDShaderIDs._SrcUvLimits, new Vector4((dstMipWidth - 0.5f) / tempTargetWidth, (dstMipHeight - 0.5f) / tempTargetHeight, 0f, 1f / tempTargetHeight)); m_PropertyBlock.SetFloat(HDShaderIDs._SourceMip, 0); cmd.SetRenderTarget(destination, srcMipLevel + 1); cmd.DrawProcedural(Matrix4x4.identity, m_ColorPyramidPSMat, 0, MeshTopology.Triangles, 3, 1, m_PropertyBlock); srcMipLevel++; srcMipWidth = srcMipWidth >> 1; srcMipHeight = srcMipHeight >> 1; } } else { var cs = m_ColorPyramidCS; int downsampleKernel = m_ColorDownsampleKernel[kernelIndex]; int downsampleKernelMip0 = m_ColorDownsampleKernelCopyMip0[kernelIndex]; int gaussianKernel = m_ColorGaussianKernel[kernelIndex]; while (srcMipWidth >= 8 || srcMipHeight >= 8) { int dstMipWidth = Mathf.Max(1, srcMipWidth >> 1); int dstMipHeight = Mathf.Max(1, srcMipHeight >> 1); cmd.SetComputeVectorParam(cs, HDShaderIDs._Size, new Vector4(srcMipWidth, srcMipHeight, 0f, 0f)); // First dispatch also copies src to dst mip0 if (srcMipLevel == 0) { cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Source, source, 0); cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Mip0, destination, 0); cmd.SetComputeTextureParam(cs, downsampleKernelMip0, HDShaderIDs._Destination, m_TempColorTargets[kernelIndex]); cmd.DispatchCompute(cs, downsampleKernelMip0, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, slices); } else { cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Source, destination, srcMipLevel); cmd.SetComputeTextureParam(cs, downsampleKernel, HDShaderIDs._Destination, m_TempColorTargets[kernelIndex]); cmd.DispatchCompute(cs, downsampleKernel, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, slices); } cmd.SetComputeVectorParam(cs, HDShaderIDs._Size, new Vector4(dstMipWidth, dstMipHeight, 0f, 0f)); cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Source, m_TempColorTargets[kernelIndex]); cmd.SetComputeTextureParam(cs, gaussianKernel, HDShaderIDs._Destination, destination, srcMipLevel + 1); cmd.DispatchCompute(cs, gaussianKernel, (dstMipWidth + 7) / 8, (dstMipHeight + 7) / 8, slices); srcMipLevel++; srcMipWidth = srcMipWidth >> 1; srcMipHeight = srcMipHeight >> 1; } } return(srcMipLevel + 1); }
//calc index based on loc, then call UpdateDrawPosition(index, loc) public void UpdateInternalPosition(Vector2Int loc) { UpdateInternalPosition(ConvertLocationToIndex(loc), loc); }
public StructureSquads(Vector2Int location, SquadInfo[] squads) { this.location = location; this.squads = squads; }
public Node(Vector2Int position, bool canWake) { this.Position = position; this.CanWake = canWake; }
public FireCell GetCellFromV2Int (Vector2Int gridPoint) { return cells[gridPoint.x, gridPoint.y]; }
public MineGuessingDSSP(Vector2Int[] operators, Vector2Int BoardSize, BaseGuessor Guessor, float uncoverMaxValue) : base(operators, BoardSize, Guessor, 0, 0) { ClosedHiddenNeighbores = new Dictionary <Vector2Int, List <Vector2Int> >(BoardSize.x); HiddenClosedRelations = new Dictionary <Vector2Int, List <Vector2Int> >(BoardSize.x); this.uncoverMaxValue = uncoverMaxValue; }
private bool IsRoomSpawnPositionOk(string strRoom, Vector2Int originBoardPosition) { // calculate tile board position (global position) // look up any existing tile at that position // check if existing tile can overlap with this tile // type1 == type2: OK <-- Both tiles are either floor tiles or wall tiles // type1 != type2: NOT OK <-- Some exceptions to this are for e.g. the case below of two diff types of door tiles but since they are matching door tiles its OK // type1 == matchingDoor(type2): OK <-- Both tiles are doors and they are the matching type of doors // if both doors but don't match: NOT OK // if type1 is Floor tile and type2 is not floor tile: NOT OK Vector2Int curTileRoomPos = Vector2Int.zero; // for each tile in strRoom for (int i = 0; i < strRoom.Length; i++) { char curTileType = strRoom[i]; if (curTileType == '\n') { curTileRoomPos.x = 0; curTileRoomPos.y++; continue; } Vector2Int curTileBoardPos = curTileRoomPos + originBoardPosition; // gets the tile's position on tile board (global position) // check if a tile already exists on curTileBoardPos // if YES, check if existing tile CAN or CANNOT overlap with curTileType for (int j = 0; j < board.rooms.Count; j++) { Room curRoom = board.rooms[j]; Tile existingTile = curRoom.tiles.Find(dt => dt.TileBoardPosition == curTileBoardPos); // A tile already exists in the same tile board position as the curTileBoardPos if (existingTile != null) { // Both tile types are different if (existingTile.tileType != curTileType) { Door door = existingTile.GetComponent <Door>(); bool existingTileIsDoor = door != null; bool curTileIsDoor = IsDoor(curTileType); // Neither tile is door and both tile types are different : NOT OK -- Case A if (!curTileIsDoor && !existingTileIsDoor) { return(false); } // If ONLY ONE of the two tiles is of door type : NOT OK -- Case D if ((curTileIsDoor && !existingTileIsDoor) || (!curTileIsDoor && existingTileIsDoor)) { return(false); } // if both tiles are a door if (curTileIsDoor && existingTileIsDoor) { // if both tiles are doors but not of matching type : NOT OK -- Case E if (GetMatchingDoor(door) != curTileType) { return(false); } else { // if both tiles are doors and of matching type BUT the existing door tile is already connected to some other door : NOT OK -- Case F if (door.connectedDoor != null) { return(false); } } // if we get here then both tiles are doors AND of matching type AND the existing door tile is unconnected : OK -- Case G } } // Both tile types are the same else { Door door = existingTile.GetComponent <Door>(); // if both tiles are a door since they are of the same tile type they cannot be matching doors : NOT OK -- Case C if (door) { return(false); } // if we get here then both tiles are not doors but still of similar type (wall tiles, floor tiles) : OK -- Case B } } // if we get here then there is no existing tile in place of curTileBoardPos : OK -- Case H } curTileRoomPos.x++; } return(true); }
private HashSet <State> PossibleTiles(List <List <Tile> > currentTiles, Vector2Int pos, List <Tile> availableTiles) { HashSet <State> possibleStates = new HashSet <State>(); bool leftEdge = pos.X == 0; bool rightEdge = pos.X == currentTiles.Count - 1; bool topEdge = pos.Y == 0; bool bottomEdge = pos.Y == currentTiles.Count - 1; foreach (Tile availableTile in availableTiles) { foreach (object _ in Permute(availableTile)) { // horizontal check if (leftEdge) { if (!IsUniqueEdge(availableTile.Left)) { continue; } } else { if (rightEdge && !IsUniqueEdge(availableTile.Right)) { continue; } if (currentTiles[pos.Y][pos.X - 1].Right != availableTile.Left) { continue; } } // vertical check if (topEdge) { if (!IsUniqueEdge(availableTile.Top)) { continue; } } else { if (bottomEdge && !IsUniqueEdge(availableTile.Bottom)) { continue; } if (currentTiles[pos.Y - 1][pos.X].Bottom != availableTile.Top) { continue; } } possibleStates.Add(availableTile.State); } } return(possibleStates); }
public PathTypes GetPathTypeOnSection(Vector2Int one, Vector2Int two, bool end, Vector2Int dir) { PathTypes ret = PathTypes.UpLeft; if (end) { if (one.x != two.x) { if (one.x > two.x) { ret = PathTypes.ArrowHorizontalLeft; } if (one.x < two.x) { ret = PathTypes.ArrowHorizontalRight; //ret = PathTypes.ArrowVerticalDown; } } else { if (one.y > two.y) { ret = PathTypes.ArrowVerticalDown; //ret = PathTypes.ArrowHorizontalRight; } if (one.y < two.y) { ret = PathTypes.ArrowVerticaUp; } } } else { if (dir != Vector2Int.zero && dir != two - one) { dir = two - one; Debug.Log(dir); if (dir.x == 1) { ret = PathTypes.UpLeft; } else if (dir.x == -1) { ret = PathTypes.UpRight; //ret = PathTypes.DownRight; } if (two.x < Path[0].x) { if (dir.y == -1) { ret = PathTypes.UpRight; //ret = PathTypes.UpRight; } else { ret = PathTypes.DownRight; } } else { if (dir.y == -1) { ret = PathTypes.UpLeft; //ret = PathTypes.UpRight; } else { ret = PathTypes.DownLeft; } } } else { if (one.x == two.x) { ret = PathTypes.Vertical; } else if (one.y == two.y) { ret = PathTypes.Horrizontal; } } } return(ret); }
public TileInfo AddOrGetTile(Vector2Int position) { return(GetTile(position) ?? AddTile(position)); }
private bool CanClaimDirection(GameLogic logic, Vector2Int direction) { Vector2Int opposite = positionOnBoard - direction; return logic.GameBoard.IsInBounds(opposite) && logic.GameBoard.GetOwner(opposite) == GameLogic.Owner.Player; }
/// <summary> /// Ensures that this turf can be placed on specified cell. Can be called before Instantiate /// </summary> /// <param name="scene"></param> /// <param name="cell">Target position</param> /// <returns>True if placement is available</returns> public virtual bool ValidatePlacement(Scene scene, Vector2Int cell) { return(!IsLayerOccupied(scene, cell)); }
public bool FindPath(Vector2Int gridstart, Vector2Int gridend, ref List <Node> pathref) { // create open set List <Node> open_set = new List <Node>(); Node start_node = grid_.GetNode(gridstart.x - grid_offset_.x, gridstart.y - grid_offset_.y); Node end_node = grid_.GetNode(gridend.x - grid_offset_.x, gridend.y - grid_offset_.y); if ((start_node.gridX_ < 0 || start_node.gridX_ > grid_.grid_size_x) || (start_node.gridY_ < 0 || start_node.gridY_ > grid_.grid_size_y) || (end_node.gridX_ < 0 || end_node.gridX_ > grid_.grid_size_x) || (end_node.gridY_ < 0 || end_node.gridY_ > grid_.grid_size_y)) { // out of bounds Debug.Log("Queried coordinates were out of bounds of mapped grid."); return(false); } open_set.Add(start_node); start_node.inOpen_ = true; nodes_to_reset_.Add(start_node); while (open_set.Count > 0) { Node current_node = open_set[GetLowestFNode(open_set)]; // erase current node from open set open_set.Remove(current_node); // remove current node from open set current_node.inOpen_ = false; // add current node to close set by flag current_node.inClosed_ = true; // if current node equals to end node, we have reached destination if (current_node == end_node) { pathref = RetracePath(start_node, end_node); return(true); } // else continue search foreach (Node n in grid_.GetNeighbours(current_node)) { // if not traversable or in closed set, skip if (!n.isWalkable_ || n.inClosed_) { continue; } // if new g cost < g cost (need updating), or if not in open set, update/calculate f cost, add to open set // calculate new g cost of neighbour relative to current node int new_g_cost = current_node.gCost_ + GetDistanceBetweenNodes(current_node, n); if (new_g_cost < n.gCost_ || !n.inOpen_) { n.gCost_ = new_g_cost; n.hCost_ = GetDistanceBetweenNodes(n, end_node); n.parent_ = current_node; if (!n.inOpen_) { open_set.Add(n); n.inOpen_ = true; } nodes_to_reset_.Add(n); } } } return(false); }
protected override IEnumerator Generate(WorldManager worldManager) { if (!WorldInfo.generateBuildings) { FinishGenerating(worldManager); yield break; } else { System.Random rand = new System.Random(seed); var world = ObjectStore.instance.worldManager; int worldSize = (int)world.worldSize; buildings = new List <Building>(); Village[] villages = FindObjectsOfType <Village>(); int n = 0; for (int i = 0; i < maxNumberOfBuildings && n < 100;) { UIManager.UpdateLoadScreenText($"Building dungeon {i}."); bool canBuild = true; Vector2Int position = new Vector2Int(rand.Next(1, worldSize), rand.Next(1, worldSize)); var height = world.worldData.heightMap[position.x, position.y]; if (height < minBuildingHeight || height > maxBuildingHeight) { canBuild = false; } if (buildings.Count > 0) { foreach (Building building in buildings) { Vector2Int otherPos = new Vector2Int((int)building.transform.position.x, (int)building.transform.position.y); if (Vector2Int.Distance(position, otherPos) < minimumBuildingDistance) { canBuild = false; } if (!canBuild) { break; } } } if (villages.Length > 0) { foreach (Village village in villages) { Vector2Int otherPos = new Vector2Int((int)village.transform.position.x, (int)village.transform.position.y); if (Vector2Int.Distance(position, otherPos) < minimumBuildingDistance) { canBuild = false; } if (!canBuild) { break; } } } if (!canBuild) { n++; } else { var go = Instantiate(buildingPrefab, new Vector3(position.x, position.y, 0), Quaternion.identity); var v = go.GetComponent <Building>(); v.direction = Village.Direction.Up; buildings.Add(v); v.Initialise(worldManager); i++; n = 0; worldManager.worldData.SetWorldMapIcon(position.x, position.y, mapIcon); } yield return(null); } FinishGenerating(worldManager); } }
public BoardTile GetBoardTile(Vector2Int index) { return(BoardTiles[index.x][index.y]); }
//Vector3 is the transform.position of the an object at cell at loc. This can give positions outside of board. Vector3 ConvertLocationToTransformVector3(Vector2Int loc) { return(new Vector3((loc.x * cellWidth) + boardX + (cellWidth / 2), (loc.y * cellHeight) + boardY + (cellHeight / 2), 0)); }