private void HandleInputForHexagon(GameObject obj) { Hexagon target = obj.gameObject.GetComponent <Hexagon>(); if (target != null) { if (target.isPlayer && currentTurn > target.spawningTurn) { SelectPlayerHexagon(target); } else if (targetSelection != null && selectedHexagon != null && selectedHexagon.TestIsNeighbour(target) && target.state == ELandState.Visible) { ENeighborPosition neighborPosition = target.GetNeighborPositionInRelationTo(selectedHexagon); targetSelection.gameObject.SetActive(false); targetSelection.transform.localScale = Vector3.zero; targetSelection.transform.SetParent(obj.transform); targetSelection.transform.position = Vector3.zero; targetSelection.transform.localPosition = ConvertNeightPositionToActionOrientation(neighborPosition); targetSelection.Activate(target.isEnemy ? ETargetSelectionType.EnemyLand : ETargetSelectionType.EmptyLand); if (targetSelection.transform.localPosition.y > 0) { targetSelection.RearrangeContentTop(); } else { targetSelection.RearrangeContentBottom(); } targetSelection.gameObject.SetActive(true); if (previewMove != null) { previewMove.Reposition(target.transform.position); previewMove.gameObject.SetActive(true); previewMove.ResetFunctionalities(); } if (targetSelection != null && selectedHexagon.troop > 1) { targetSelection.EnableAddButton(); targetSelection.DisableSubtractButton(); targetSelection.DisableConfirmButton(); } lastHexagon = target; } } }
private void AddIfNull(ENeighborPosition position, int id, out int neighborId) { if (neighbors != null) { int outId; neighbors.TryGetValue(position, out outId); neighbors.Add(position, id); neighborId = id; return; } neighborId = -1; }
private Vector3 ConvertNeightPositionToActionOrientation(ENeighborPosition neighborPosition) { Vector3 pos = Vector3.zero; switch (neighborPosition) { case ENeighborPosition.TopLeft: case ENeighborPosition.TopRight: pos = topPosition; break; case ENeighborPosition.BottomLeft: case ENeighborPosition.BottomRight: pos = bottomPosition; break; } return(pos); }
private Vector3 GetNeighborPositionByDirection(Hexagon hexBase, ENeighborPosition neighborPos) { Vector3 direction = Vector3.zero; float x = hexBase.transform.localPosition.x; float y = hexBase.transform.localPosition.y; float b = 0.32f; float h = b * 3; float w = b * 2; float sw = b * 4; y += w; switch (neighborPos) { case ENeighborPosition.Left: direction = new Vector3(x - sw, y, 0); break; case ENeighborPosition.TopLeft: direction = new Vector3(x - w, y + h, 0); break; case ENeighborPosition.TopRight: direction = new Vector3(x + w, y + h, 0); break; case ENeighborPosition.Right: direction = new Vector3(x + sw, y, 0); break; case ENeighborPosition.BottomRight: direction = new Vector3(x + w, y - h, 0); break; case ENeighborPosition.BottomLeft: direction = new Vector3(x - w, y - h, 0); break; } return(direction); }