Example #1
0
    protected virtual void InitBoardItems()
    {
        UnityCustoms.DestroyAllChilds(board_items_parent = GameObject.Find(ChessConstants.BoardItemsObjectName));
        UnityCustoms.DestroyGameObjects(ChessConstants.BoardItemsObjectName);
        board_items_parent = new GameObject(ChessConstants.BoardItemsObjectName);
        board_items_parent.transform.SetParent(GameObject.Find(ChessConstants.BoardObjectName).transform);

        boardItemsMono = new List <BoardItemMonoBase>();

        for (int i = 0; i < boardSizeX; i++)
        {
            for (int j = 0; j < boardSizeY; j++)
            {
                GameObject item_obj = GameObject.Instantiate(
                    (i + j) % 2 == 0 ? MainMenu.Singleton.GetCurrentBoardPrefabs().dark_board_item : MainMenu.Singleton.GetCurrentBoardPrefabs().bright_board_item) as GameObject;
                item_obj.name = "board_item_x_" + i + "_y_" + j;

                BoardItemMono item_scr = item_obj.GetComponent <BoardItemMono>();
                item_scr.SetPosition(new Vector2Int(i, j));
                boardItemsMono.Add(item_scr);
                item_obj.transform.SetParent(board_items_parent.transform);
                item_obj.transform.position = GetBoardPosition(i, j);
                UnityCustoms.SetSpriteRendererObjectSize(item_obj, boardSpriteSize);
            }
        }
    }
Example #2
0
    public void SetPointByScreenNormalizedCoords()
    {
        Vector2 size  = UnityCustoms.GetGameWindowSize();
        float   x_pos = x_screen_coord * size.x;
        float   y_pos = y_screen_coord * size.y;

        point    = cam.ScreenToWorldPoint(new Vector3(x_pos, y_pos, 0));
        point.z += 2;
    }
Example #3
0
    public void DrawScaledCubeInScreenCenter()
    {
        if (squarePoints == null || squarePoints.Length == 0)
        {
            squarePoints = new Vector3[4];
        }

        float c_to_center = 0f;
        var   size        = UnityCustoms.GetGameWindowSize();

        if (size.x > size.y)
        {
            if (proportion < size.x / size.y)
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, size.y - c_to_center, 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, size.y - c_to_center, 2f));
            }
            else
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
            }
        }
        else
        {
            if (proportion > size.x / size.y)
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
            }
            else
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, size.y - c_to_center, 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, size.y - c_to_center, 2f));
            }
        }
    }
Example #4
0
    protected override void InitBoardItems()
    {
        UnityCustoms.DestroyAllChilds(board_items_parent = GameObject.Find(ChessConstants.BoardItemsObjectName));
        UnityCustoms.DestroyGameObjects(ChessConstants.BoardItemsObjectName);
        board_items_parent = new GameObject(ChessConstants.BoardItemsObjectName);
        board_items_parent.transform.SetParent(GameObject.Find(ChessConstants.BoardObjectName).transform);

        boardItemsMono = new List <BoardItemMonoBase>();

        for (int i = 0; i < boardSizeX; i++)
        {
            for (int j = 0; j < boardSizeY; j++)
            {
                GameObject item_obj = new GameObject("board_item_x_" + i + "_y_" + j);
                var        item_scr = item_obj.AddComponent <BoardItemMonoCircled>();
                item_scr.SetPosition(new Vector2Int(i, j));
                boardItemsMono.Add(item_scr);
                item_obj.transform.SetParent(board_items_parent.transform);
                //item_obj.transform.position = GetBoardPosition(i, j);
                UnityCustoms.SetSpriteRendererObjectSize(item_obj, boardSpriteSize);
            }
        }
    }
Example #5
0
    public void RecoveryChessItem(ChessItemProperties props)
    {
        GameObject chess_obj = null;

        if (!props.isNullObject)
        {
            if (new byte[]
            {
                (byte)ClassicChessItemType.pawn,
                (byte)LosAlamosChessItemType.pawn,
                (byte)ChaturangaChessItemType.pawn,
                (byte)CircledChessItemType.pawn_left,
                (byte)CircledChessItemType.pawn_right
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].pawn) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.rook,
                (byte)LosAlamosChessItemType.rook,
                (byte)ChaturangaChessItemType.rook,
                (byte)CircledChessItemType.rook
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].rook) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.knight,
                (byte)LosAlamosChessItemType.knight,
                (byte)ChaturangaChessItemType.knight,
                (byte)CircledChessItemType.knight
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].knight) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.bishop,
                (byte)CircledChessItemType.bishop
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].bishop) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.queen,
                (byte)LosAlamosChessItemType.queen,
                (byte)ChaturangaChessItemType.queen,
                (byte)CircledChessItemType.queen
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].queen) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }
            else if (new byte[]
            {
                (byte)ClassicChessItemType.king,
                (byte)LosAlamosChessItemType.king,
                (byte)ChaturangaChessItemType.king,
                (byte)CircledChessItemType.king
            }.Contains(props.type))
            {
                chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].king) as GameObject;
                chess_obj.name = props.side.ToString() + "_chess_";
            }

            ChessItemMono chess_scr = chess_obj.GetComponent <ChessItemMono>();
            chess_scr.props = props;
            chessItemsMono.Add(chess_scr);
            chess_obj.transform.SetParent(board_items_parent.transform);
            Vector3 pos = GetBoardPosition(props.pos.x, props.pos.y);
            chess_obj.transform.position = new Vector3(pos.x, pos.y, pos.z - 0.1f);

            UnityCustoms.SetSpriteRendererObjectSize(chess_obj, boardSpriteSize);
            chess_scr.RecoveryFigure();
        }
    }
Example #6
0
    protected virtual void InitChessItems()
    {
        UnityCustoms.DestroyAllChilds(chess_items_parent = GameObject.Find(ChessConstants.ChessItemsObjectName));
        UnityCustoms.DestroyGameObjects(ChessConstants.ChessItemsObjectName);
        chess_items_parent = new GameObject(ChessConstants.ChessItemsObjectName);
        chess_items_parent.transform.SetParent(GameObject.Find(ChessConstants.BoardObjectName).transform);

        chessItemsMono = new List <ChessItemMonoBase>();
        int idx = 0;

        for (int i = 0; i < boardSizeX; i++)
        {
            for (int j = 0; j < boardSizeY; j++)
            {
                GameObject          chess_obj = null;
                ChessItemProperties props     = board[i, j];
                if (!props.isNullObject)
                {
                    if (new byte[]
                    {
                        (byte)ClassicChessItemType.pawn,
                        (byte)LosAlamosChessItemType.pawn,
                        (byte)ChaturangaChessItemType.pawn,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].pawn) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.rook,
                        (byte)LosAlamosChessItemType.rook,
                        (byte)ChaturangaChessItemType.rook,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].rook) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.knight,
                        (byte)LosAlamosChessItemType.knight,
                        (byte)ChaturangaChessItemType.knight,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].knight) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.bishop,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].bishop) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.queen,
                        (byte)LosAlamosChessItemType.queen,
                        (byte)ChaturangaChessItemType.queen,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].queen) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }
                    else if (new byte[]
                    {
                        (byte)ClassicChessItemType.king,
                        (byte)LosAlamosChessItemType.king,
                        (byte)ChaturangaChessItemType.king,
                    }.Contains(props.type))
                    {
                        chess_obj      = GameObject.Instantiate(MainMenu.Singleton.GetCurrentBoardPrefabs().chessPackList[(byte)props.side].king) as GameObject;
                        chess_obj.name = props.side.ToString() + "_chess_" + idx++;
                    }


                    ChessItemMonoBase chess_scr = chess_obj.GetComponent <ChessItemMono>();
                    chess_scr.props = props;
                    chessItemsMono.Add(chess_scr);
                    chess_obj.transform.SetParent(chess_items_parent.transform);
                    Vector3 pos = GetBoardPosition(i, j);
                    chess_obj.transform.position = new Vector3(pos.x, pos.y, pos.z - 0.1f);
                    UnityCustoms.SetSpriteRendererObjectSize(chess_obj, boardSpriteSize);
                }
            }
        }
    }
Example #7
0
 private GameObject Init_()
 {
     InitStatics();
     UnityCustoms.DestroyGameObjects(ChessConstants.MatchViewObjectName);
     return(new GameObject(ChessConstants.MatchViewObjectName));
 }