Пример #1
0
    private ClickInfo FindCellUnderMouse()
    {
        Ray        ray = Camera.main.ScreenPointToRay(UniversalInput.MousePos());
        RaycastHit hit;

        ClickInfo ret = null;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 8))
        {
            if (hit.transform.gameObject.tag == "Cell")
            {
                ret             = new ClickInfo(hit.transform.gameObject.GetComponent <CellData> ());
                ret.click_point = hit.point;
            }
            else if (hit.transform.gameObject.tag == "EndMove")            // ToDo move to another method
            {
                if (!IsDudeSelected())
                {
                    ChangeCommand();
                }
            }

            /*else
             * {
             * GameObject obj = hit.transform.gameObject;
             * while (obj.transform.parent != null)
             * {
             * obj = obj.transform.parent.gameObject;
             * }
             *      if( obj.GetComponent<DudeData>() )
             *              ret = GameBoard.instance.FindCell(obj.GetComponent<DudeData>().unit.oriented_cell.cell);
             * }*/
        }

        return(ret);
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (tool_tip != null && DateTime.Now > show_card_timer)
        {
            tool_tip.SetActive(true);

            Vector3 pos = gameObject.transform.position;
            if (gameObject.transform.parent != tool_tip.transform.parent)
            {
                pos    = UniversalInput.MousePos();
                pos.x += 60 * 3 / 2 + 20;              //ToDo remove 60x80 as default card size;

                if (pos.x + 60 * 3 / 2 > Screen.width)
                {
                    pos.x -= 2 * (60 * 3 / 2 + 20);
                }

                if (pos.y + 80 * 3 > Screen.height)
                {
                    pos.y = Screen.height - 80 * 3;
                }
                //pos = Camera.main.WorldToScreenPoint(gameObject.transform.position);
            }
            else
            {
                pos.x += 60;
                pos.y += 80;
            }

            tool_tip.transform.position = pos;

            //clone.transform.position = gameObject.GetComponent<RectTransform> ().rect.max;

            show_card_timer = DateTime.MaxValue;
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        Texture2D cursor          = null;
        bool      block_selection = false;

        foreach (var dude in dudes_list)
        {
            if (!dude.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("DudeIdle"))
            {
                block_selection = true;
                break;
            }
        }

        if (block_selection)
        {
            end_move_time = DateTime.Now;
        }
        else
        {
            block_selection = (DateTime.Now - end_move_time).TotalMilliseconds < 200; //ToDo fix it properly
        }
        if (!block_selection)                                                         //disable selection during animation
        {
            if (aiMoveQueue.Count > 0)
            {
                MakeMoveFromQueue();
                end_move_time = DateTime.Now;
                return;
            }

            if (IsAICalculating())
            {
                return;
            }

            if (UniversalInput.LMouseClick())
            {
                HitCell(FindCellUnderMouse());
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                ChangeCommand();
                return;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                ClearAvailableCells();
                return;
            }

            CheckToolTip();

            if (IsDudeSelected())
            {
                cells_list.ForEach(cell =>
                {
                    if (cell.GetStatus() != CellData.Status.Clear)
                    {
                        cell.SetStatus(CellData.Status.Available);
                    }
                }
                                   );
                GetComponent <RouteData>().Clear();

                var sel_moves = GetSelectedMove(FindCellUnderMouse());

                if (sel_moves != null && sel_moves.Count > 0)
                {
                    foreach (var move in sel_moves)
                    {
                        var from = move.GetUnitPlace(gameboard_impl);
                        if (from != null)
                        {
                            Array.ForEach(gameboard_impl.GetOccupatedCells(from),
                                          cell_place => FindCell(cell_place).SetStatus(CellData.Status.Selected));
                        }

                        var to = move.GetTargetCell(gameboard_impl);
                        if (to != null)
                        {
                            Array.ForEach(gameboard_impl.GetOccupatedCells(to),
                                          cell_place => FindCell(cell_place).SetStatus(CellData.Status.Selected));
                        }
                    }

                    Move sel_move = sel_moves[0];                    //ToDo Draw all

                    if (sel_move.Type == Move.MoveType.Kill)
                    {
                        CellData from_cell = FindCell((sel_move as SkipMoveImpl).UnitPlace); //ToDo incapsulate healing and isRangedAttack in kill move
                        cursor = attack_cursor;                                              //ToDo try to OnMouseEnter/OnMouseExit
                        if (from_cell != null && from_cell.cell.unit != null)
                        {
                            if ((sel_move as KillMoveImpl).isHealing)
                            {
                                cursor = cross_cursor;
                            }
                            else if (from_cell.cell.unit.isRangedAttack)
                            {
                                cursor = bow_attack_cursor;
                            }
                        }
                    }
                    else if (sel_move as KillMoveImpl != null)
                    {
                        cursor = (sel_move as KillMoveImpl).isHealing ? cross_cursor : attack_cursor;
                    }
                    else if (sel_move as MoveImpl != null)
                    {
                        cursor = walk_cursor;
                    }

                    if (sel_move as MoveImpl != null && (sel_move as MoveImpl).Steps > 0 && sel_moves.Count == 1)
                    {
                        GetComponent <RouteData>().CreateByCell(sel_move as MoveImpl);
                    }
                }
            }
        }

        Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto);
    }