コード例 #1
0
ファイル: BoardTile.cs プロジェクト: njelly/GridStrategy
 // --------------------------------------------------------------------------------------------
 protected override void Build()
 {
     BoardTileView.Create(this, (BoardTileView view) =>
     {
         _view = view;
     });
 }
コード例 #2
0
 // --------------------------------------------------------------------------------------------
 public void HighlightBoardTile(IntVector2 coord)
 {
     if (BoardTileView.TryGetView(this.GetTile(coord), out BoardTileView view))
     {
         view.SetHighlight(BoardTileView.EHighlight.Neutral);
         HighlightedTile = view.BoardTile;
     }
 }
コード例 #3
0
        // --------------------------------------------------------------------------------------------
        public void ClearAllBoardTileHighlights()
        {
            foreach (BoardTile boardTile in _tiles)
            {
                if (BoardTileView.TryGetView(boardTile, out BoardTileView boardTileView))
                {
                    boardTileView.SetHighlight(BoardTileView.EHighlight.None);
                }
            }

            HighlightedTile = null;
        }
コード例 #4
0
        // --------------------------------------------------------------------------------------------
        public void HighlightBoardTilesForUseSkill(Skill skill)
        {
            List <BoardTile> targetableTiles = skill.GetTargetableTiles();

            foreach (BoardTile boardTile in targetableTiles)
            {
                if (BoardTileView.TryGetView(boardTile, out BoardTileView view))
                {
                    view.SetHighlight(skill.DamageDealt > 0 ? BoardTileView.EHighlight.Attack : BoardTileView.EHighlight.Heal);
                }
            }
        }
コード例 #5
0
        // --------------------------------------------------------------------------------------------
        public void HighlightBoardTilesForPlayCard(Card card)
        {
            List <BoardTile> targetableTiles = card.GetPlayableTiles();

            foreach (BoardTile boardTile in targetableTiles)
            {
                if (BoardTileView.TryGetView(boardTile, out BoardTileView view))
                {
                    view.SetHighlight(BoardTileView.EHighlight.Spawn);
                }
            }
        }
コード例 #6
0
ファイル: BoardTileView.cs プロジェクト: njelly/GridStrategy
        // --------------------------------------------------------------------------------------------
        public static void Create(BoardTile boardTile, InstantiateDelegate callback)
        {
            AppManager.AssetManager.Load(AssetPaths.Prefabs.BoardTileView, (bool successful, GameObject payload) =>
            {
                if (successful)
                {
                    GameObject viewGo = Instantiate(payload, boardTile.Transform, false);

                    BoardTileView view = viewGo.GetComponent <BoardTileView>();
                    view.BoardTile     = boardTile;
                    view._highlight    = EHighlight.None;

                    view.SetMaterial();

                    _boardTileToView.Add(boardTile, view);

                    callback(view);
                }
            });
        }
コード例 #7
0
        // --------------------------------------------------------------------------------------------
        private void HighlightBoardTilesForUnitMoveRecursive(Unit unit, Dictionary <BoardTile, int> visitedToCost, BoardTile current, int cost)
        {
            if (current == null)
            {
                return;
            }

            if (current.Occupant != null && current.Occupant != unit)
            {
                return;
            }

            if (cost > unit.MoveRange)
            {
                return;
            }

            if (visitedToCost.ContainsKey(current))
            {
                int previousCost = visitedToCost[current];
                if (cost < previousCost)
                {
                    visitedToCost[current] = cost;
                }
                else
                {
                    // we've alredy visited this tile and it was cheaper then, so we're done
                    return;
                }
            }
            else
            {
                visitedToCost.Add(current, cost);
            }

            if (BoardTileView.TryGetView(current, out BoardTileView view))
            {
                view.SetHighlight(BoardTileView.EHighlight.Move);
            }

            BoardTile northTile = GetTile(current.xCoord, current.yCoord + 1);

            if (northTile != null)
            {
                HighlightBoardTilesForUnitMoveRecursive(unit, visitedToCost, northTile, cost + northTile.GetMoveCostForUnit(unit));
            }

            BoardTile southTile = GetTile(current.xCoord, current.yCoord - 1);

            if (southTile != null)
            {
                HighlightBoardTilesForUnitMoveRecursive(unit, visitedToCost, southTile, cost + southTile.GetMoveCostForUnit(unit));
            }

            BoardTile eastTile = GetTile(current.xCoord + 1, current.yCoord);

            if (eastTile != null)
            {
                HighlightBoardTilesForUnitMoveRecursive(unit, visitedToCost, eastTile, cost + eastTile.GetMoveCostForUnit(unit));
            }

            BoardTile westTile = GetTile(current.xCoord - 1, current.yCoord);

            if (westTile != null)
            {
                HighlightBoardTilesForUnitMoveRecursive(unit, visitedToCost, westTile, cost + westTile.GetMoveCostForUnit(unit));
            }
        }
コード例 #8
0
ファイル: BoardTileView.cs プロジェクト: njelly/GridStrategy
 // --------------------------------------------------------------------------------------------
 public static bool TryGetView(BoardTile boardTile, out BoardTileView view)
 {
     return(_boardTileToView.TryGetValue(boardTile, out view));
 }
コード例 #9
0
 // --------------------------------------------------------------------------------------------
 public void OnPointerDownOverBoardTileView(BoardTileView boardTileView)
 {
 }
コード例 #10
0
ファイル: Unit.cs プロジェクト: njelly/GridStrategy
        // --------------------------------------------------------------------------------------------
        public void Move(IntVector2[] path, bool animate, Action onComplete)
        {
            if (!CanMove)
            {
                Debug.LogError($"Unit {id} cannot move");
                return;
            }

            _onMoveComplete = () =>
            {
                onComplete?.Invoke();
                _onMoveComplete = null;
            };

            HasMoved = true;

            if (animate)
            {
                if (_moveAnim != null)
                {
                    Debug.LogError("move anim in progress!");
                    return;
                }

                _moveAnim = new TofuAnimation();

                Parent.RemoveChild(this, false);

                for (int i = 1; i < path.Length; i++)
                {
                    Vector3 fromPos = _game.board.GetTile(path[i - 1]).Transform.position;
                    Vector3 toPos   = _game.board.GetTile(path[i]).Transform.position;
                    float   time    = (toPos - fromPos).magnitude / _data.travelSpeed;

                    if (i != 1)
                    {
                        // we don't need to call Then() on the first loop
                        _moveAnim.Then();
                    }

                    _moveAnim.Execute(() =>
                    {
                        SetFacing(VectorToFacing(toPos - fromPos), false);
                    })
                    .Value01(time, EEaseType.Linear, (float newValue) =>
                    {
                        Transform.position = Vector3.LerpUnclamped(fromPos, toPos, newValue);

                        Ray ray           = new Ray(Transform.position + Vector3.up, Vector3.down);
                        RaycastHit[] hits = Physics.RaycastAll(ray, 2f);
                        for (int j = 0; j < hits.Length; j++)
                        {
                            BoardTileView boardTileView = hits[j].collider.GetComponentInParent <BoardTileView>();
                            if (boardTileView == null)
                            {
                                continue;
                            }
                            if (boardTileView.BoardTile != BoardTile)
                            {
                                OccupyBoardTile(boardTileView.BoardTile, false);
                            }

                            break;
                        }
                    });
                }

                _moveAnim.Then()
                .Execute(() =>
                {
                    StopOnTile();
                })
                .Play();
            }
            else
            {
                for (int i = 0; i < path.Length; i++)
                {
                    BoardTile boardTile = _game.board.GetTile(path[i]);
                    StopOnTile();
                }

                _onMoveComplete?.Invoke();
            }
        }