Beispiel #1
0
    void Start()
    {
        mocker.mockPlayerSquadrons();
        DiceRollerBase.setUpDiceRollerBase(ForceMode.VelocityChange, 10.0f);

        string total = "squadron size: " + MatchDatas.getTotalSquadPoints();

        // TODO Show each player's name, squad point total, chosen side, chosen ships (images...)
        int playerIndex = 0;

        foreach (Player player in MatchDatas.getPlayers())
        {
            Transform     playerPanelPrefab = Resources.Load <Transform>(PLAYER_PANEL_PREFAB_NAME);
            RectTransform rt = (RectTransform)playerPanelPrefab;
            float         playerPanelWidth = rt.rect.width;

            Transform playerPanel = (Transform)GameObject.Instantiate(
                playerPanelPrefab,
                new Vector3((playerIndex * playerPanelWidth) + PLAYER_PANEL_X_OFFSET, PLAYER_PANEL_Y_OFFSET, DEFAULT_Z_OFFSET),
                Quaternion.identity
                );

            playerPanel.transform.SetParent(mainCanvas.transform, false);

            /*PilotRemoveEvents pilotRemoveEvent = shipPanel.transform.Find("DeleteButton").gameObject.GetComponent<PilotRemoveEvents>();
             * pilotRemoveEvent.setPilot(loadedShip.getPilot());*/

            /*Sprite sprite = Resources.Load<Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + loadedShip.getShip().ShipId);
             * shipPanel.transform.Find("Avatar").gameObject.GetComponent<Image>().sprite = sprite;
             * Image image = shipPanel.transform.Find("Avatar").gameObject.GetComponent<Image>();
             * image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);*/

            playerPanel.transform.Find("PlayerName").gameObject.GetComponent <UnityEngine.UI.Text>().text = player.getPlayerName();
            playerPanel.transform.Find("PlayerSide").gameObject.GetComponent <UnityEngine.UI.Text>().text = player.getChosenSide();
            playerPanel.transform.Find("SquadTotal").gameObject.GetComponent <UnityEngine.UI.Text>().text = TEXT_SQUAD_TOTAL + player.getCumulatedSquadPoints() + TEXT_POINTS;

            int rowIndex = 0;
            int colIndex = 0;

            foreach (LoadedShip ship in player.getSquadron())
            {
                Transform shipIconPrefab = Resources.Load <Transform>(SHIP_ICON_PREFAB_NAME);

                Transform shipIcon = (Transform)GameObject.Instantiate(
                    shipIconPrefab,
                    new Vector3((colIndex * SHIP_ICON_WIDTH) + SHIP_ICON_X_OFFSET, (rowIndex * SHIP_ICON_HEIGHT) + SHIP_ICON_Y_OFFSET, DEFAULT_Z_OFFSET),
                    Quaternion.identity
                    );

                shipIcon.transform.SetParent(playerPanel.transform.Find("ShipIcons"), false);

                Sprite sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + ship.getShip().ShipId);
                shipIcon.gameObject.GetComponent <Image>().sprite = sprite;
                Image image = shipIcon.gameObject.GetComponent <Image>();
                image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);

                if (colIndex < 5)
                {
                    colIndex++;
                }
                else
                {
                    colIndex = 0;
                    rowIndex++;
                }
            }

            playerIndex++;
        }
    }