コード例 #1
0
    public static IEnumerator MoveUnitTo(WorldPosition moveTo, float time)
    {
        inFirst = true;
        Unit    unit     = BoardManager.selectedUnit;
        Vector3 startPos = unit.worldPosition.ToVector3();
        var     tmpPos   = PositionConverter.ToWorldCoordinates(unit.currentPath[0]).ToVector3();
        Vector3 endPos   = new Vector3(tmpPos.x, moveTo.y, tmpPos.z);
        int     count    = 0;

        while (unit.currentPath.Count != 1)
        {
            unit.currentPath.RemoveAt(0);
            ++count;
            if (count == 1)
            {
                startPos = unit.worldPosition.ToVector3();
            }
            var tmpPos_ = PositionConverter.ToWorldCoordinates(unit.currentPath[0]).ToVector3();
            endPos = new Vector3(tmpPos_.x, moveTo.y, tmpPos_.z);

            for (float t = 0; t <= 1 * time; t += Time.deltaTime)
            {
                unit.transform.position = Vector3.Lerp(startPos, endPos, t / time);
                yield return(null);
            }
            startPos = endPos;
        }

        unit.currentPath     = null;
        inFirst              = false;
        Unit.isHumanMakeTurn = true;
    }
コード例 #2
0
    private void MoveTeamPosition(Node[] teamPosition, List <Unit> team)
    {
        for (int i = 0; i < team.Count; ++i)
        {
            float         y            = team[i].transform.position.y;
            WorldPosition unitWorldPos = PositionConverter.ToWorldCoordinates(new LocalPosition(teamPosition[i].x, teamPosition[i].y));
            unitWorldPos.y            = y;
            BoardManager.selectedUnit = team[i];

            if (BoardManager.Instance.isUnitOccupiedNodeByTeam(teamPosition[i], true))
            {
                Debug.Log(team[i].tag + ": attack to " + teamPosition[i].x + " " + teamPosition[i].y);
                Unit defUnit = BoardManager.Instance.GetUnitByNode(teamPosition[i], false);
                BoardManager.Instance.GeneratePathToEnemy(defUnit);
                var path = BoardManager.selectedUnit.currentPathToEnemy;
                if (path != null)
                {
                    unitWorldPos = PositionConverter.ToWorldCoordinates(new LocalPosition(path[path.Count - 1].x, path[path.Count - 1].y));
                }
                BoardManager.selectedUnit.Attack(defUnit);
            }
            else
            {
                BoardManager.Instance.GeneratePathTo(unitWorldPos.x, unitWorldPos.z);
                BoardManager.selectedUnit.MoveToEnterTile();
                team[i].transform.position = unitWorldPos.ToVector3();
                team[i].UpdatePosition(unitWorldPos);
            }
        }
    }
コード例 #3
0
 private void UpdateTeamPosition(Node[] teamPosition, List <Unit> team)
 {
     for (int i = 0; i < team.Count; ++i)
     {
         WorldPosition unitWorldPos = PositionConverter.ToWorldCoordinates(new LocalPosition(teamPosition[i].x, teamPosition[i].y));
         team[i].UpdatePosition(unitWorldPos);
     }
 }
コード例 #4
0
 private void UpdateTeamPosition(List <Unit> currentTeam, Node unitPosition, int initiative)
 {
     if (initiative < currentTeam.Count)
     {
         //todo: add ctor for nodes
         currentTeam[initiative].UpdatePosition(PositionConverter.ToWorldCoordinates(new LocalPosition(unitPosition.x, unitPosition.y)));
     }
 }
コード例 #5
0
 public void MoveToEnterTile()
 {
     if (currentPath != null)
     {
         WorldPosition moveTo = PositionConverter.ToWorldCoordinates(new LocalPosition(currentPath[currentPath.Count - 1].x, currentPath[currentPath.Count - 1].y));
         moveTo.y = transform.position.y;
         //StartCoroutine(MoveObject.MoveUnitTo(moveTo, 0.1f));
         //StartCoroutine(MoveObject.DoLast());
         transform.position = moveTo.ToVector3();
         UpdatePosition(moveTo);
     }
 }
コード例 #6
0
    void CreateTileMap()
    {
        const int mountainLimit     = 6;
        int       countMountainTile = 0;

        System.Random rand = new System.Random();
        tiles = new int[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                #region get tile type
                TileType tt;
                int      tileType = 0;
                if (x > width / 3)
                {
                    tileType = rand.Next(2);
                }

                if (tileType == 1 && countMountainTile != mountainLimit)
                {
                    tt = tileTypes[1];
                    ++countMountainTile;
                }
                else
                {
                    tt = tileTypes[0];
                }
                #endregion

                LocalPosition tilePos = new LocalPosition(x, y);

                Transform tile = Instantiate(tt.tileVisualPrefab.transform) as Transform;

                tile.position = PositionConverter.ToWorldCoordinates(tilePos).ToVector3();
                tile.parent   = transform;
                tile.name     = "Hexagon" + tilePos.x + "|" + tilePos.y;

                ClickableAvailableTile ct;
                if (tile.GetComponent <ClickableAvailableTile>() != null)
                {
                    ct       = tile.GetComponent <ClickableAvailableTile>();
                    ct.tileX = tile.position.x;
                    ct.tileY = tile.position.z;
                }

                tiles[x, y] = TileType.GetTileTypeByTileName(tt.name);
            }
        }
    }
コード例 #7
0
 public void Approach()
 {
     if (currentPathToEnemy != null)
     {
         WorldPosition moveTo = PositionConverter.ToWorldCoordinates(new LocalPosition(
                                                                         currentPathToEnemy[currentPathToEnemy.Count - 1].x,
                                                                         currentPathToEnemy[currentPathToEnemy.Count - 1].y));
         moveTo.y = transform.position.y;
         //StartCoroutine(MoveObject.ApproachUnitTo(moveTo, 0.05f));
         //StartCoroutine(MoveObject.DoLast());
         transform.position = moveTo.ToVector3();
         UpdatePosition(moveTo);
     }
 }
コード例 #8
0
    public void DeselecteAvailableTile()
    {
        if (selectedUnit.availableMovementTiles != null)
        {
            foreach (var item in selectedUnit.availableMovementTiles)
            {
                Collider[]    colliders;
                WorldPosition tileWorldPos = PositionConverter.ToWorldCoordinates(new LocalPosition(item.x, item.y));
                colliders = Physics.OverlapSphere(tileWorldPos.ToVector3(), 0.125f /*Radius*/);

                if (colliders.Length >= 1)
                {
                    foreach (var collider in colliders)
                    {
                        var gameObject = collider.gameObject;
                        if (map.tiles[item.x, item.y] != (int)TileTypes.SWAMP)
                        {
                            GameObjectHighlighter.Deselect(selectedUnit.startColor, gameObject.GetComponent <Renderer>());
                        }
                    }
                }
            }
        }
    }
コード例 #9
0
    public void SelectAvailableTile()
    {
        LocalPosition unitPosition = PositionConverter.ToLocalCoordinates(selectedUnit.worldPosition);

        selectedUnit.availableMovementTiles = new List <Node>();
        Node currentTile = map.graph[unitPosition.x, unitPosition.y];

        GetAvailableMovementTiles(selectedUnit.availableMovementTiles, currentTile);

        foreach (var item in selectedUnit.availableMovementTiles)
        {
            Collider[]    colliders;
            WorldPosition tileWorldPos = PositionConverter.ToWorldCoordinates(new LocalPosition(item.x, item.y));
            colliders = Physics.OverlapSphere(tileWorldPos.ToVector3(), 0.125f /*Radius*/);

            if (colliders.Length >= 1)
            {
                foreach (var collider in colliders)
                {
                    var go = collider.gameObject;
                    if (go.name.StartsWith("Hexagon"))
                    {
                        if (map.tiles[item.x, item.y] != (int)TileTypes.SWAMP)
                        {
                            selectedUnit.startColor         = go.GetComponent <Renderer>().material.GetColor("_Color");
                            selectedUnit.availableTileColor = selectedUnit.startColor;
                            //TODO: think about  other variant of colorized tile
                            selectedUnit.availableTileColor.g = 0.6f;
                            selectedUnit.availableTileColor.b = 0.4f;
                            GameObjectHighlighter.Select(selectedUnit.startColor, selectedUnit.availableTileColor, go.GetComponent <Renderer>());
                        }
                    }
                }
            }
        }
    }