Exemplo n.º 1
0
    public void TriggeredStart()
    {
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);

        Enum.TryParse(SceneManager.GetActiveScene().name, out state);

        if (state == SceneState.Title)
        {
            hostInputField = GameObject.Find("HostInputField").GetComponent <TMP_InputField>();
            portInputField = GameObject.Find("PortInputField").GetComponent <TMP_InputField>();

            hostInputField.text = GetYAMLObject(@"YAML\ClientConfig.yml").GetData <string>("Host");
            portInputField.text = GetYAMLObject(@"YAML\ClientConfig.yml").GetData <int>("Port").ToString();

            GameObject.Find("Button").GetComponent <Button>().onClick.AddListener(ConnectClick);
            successImage = GameObject.Find("Button").transform.Find("Background").Find("SuccessImage").gameObject;
            successTimer = 0;

            blackScreen = GameObject.Find("BlackScreen").GetComponent <Image>();

            applyPlayerSelectObj = false;
            playerSelectObj      = null;
        }
        else if (state == SceneState.Lobby)
        {
            RectTransform iconRoot = GameObject.Find("IconRoot").GetComponent <RectTransform>();
            int           count    = 0;
            Vector2       initPos  = new Vector2(32f, -32f);
            foreach (UnitType type in Enum.GetValues(typeof(UnitType)))
            {
                if (type >= UnitType.HatsuneMiku)
                {
                    int x = count % 8;
                    int y = count / 8;

                    GameObject instance = Instantiate(championSelectIconPrefab, iconRoot);
                    instance.GetComponent <RectTransform>().anchorMin        = new Vector2(0, 1);
                    instance.GetComponent <RectTransform>().anchorMax        = new Vector2(0, 1);
                    instance.GetComponent <RectTransform>().pivot            = new Vector2(0, 1);
                    instance.GetComponent <RectTransform>().anchoredPosition = initPos + new Vector2(x * 100, y * -100);

                    instance.GetComponent <ChampionSelectIcon>().SetData(type, this);

                    count++;
                }
            }

            lobbyTitle = GameObject.Find("LobbyTitle").GetComponent <Text>();
            blueContentRectTransform  = GameObject.Find("BlueContent").GetComponent <RectTransform>();
            redContentRectTransform   = GameObject.Find("RedContent").GetComponent <RectTransform>();
            selectedChampionIconImage = GameObject.Find("SelectedChampionIconImage").GetComponent <Image>();
            nameInputField            = GameObject.Find("NameInputField").GetComponent <InputField>();
            setNameButton             = GameObject.Find("SetNameButton").GetComponent <Button>();
            GameObject.Find("SetNameButton").GetComponent <Button>().onClick.AddListener(SetNameButtonPressed);
            teamButton = GameObject.Find("TeamButton").GetComponent <Button>();
            GameObject.Find("TeamButton").GetComponent <Button>().onClick.AddListener(SetTeamButtonPressed);
            readyButton = GameObject.Find("ReadyButton").GetComponent <Button>();
            GameObject.Find("ReadyButton").GetComponent <Button>().onClick.AddListener(ReadyButtonPressed);
            chatUI = GameObject.Find("ChatUI").GetComponent <ChatUI>();
            chatUI.SetClientNetwork(client);
            GameObject.Find("SendButton").GetComponent <Button>().onClick.AddListener(chatUI.Send);

            if (!applyPlayerSelectObj && playerSelectObj != null)
            {
                type = playerSelectObj.Type;
                SetUnitTypeIcon(type);

                _name = playerSelectObj.Name;
                nameInputField.text = playerSelectObj.Name;

                _team = playerSelectObj.Team;
                SetTeamButtonColor(_team);

                _ready = playerSelectObj.Ready;
                SetReadyButtonColor(_ready);

                applyPlayerSelectObj = true;
                playerSelectObj      = null;
            }
        }
        else
        {
            unitManager = GameObject.Find("UnitManager").GetComponent <UnitManager>();
            chatUI      = GameObject.Find("ChatUI").GetComponent <ChatUI>();
            chatUI.SetClientNetwork(client);

            applyPlayerSelectObj = false;
            playerSelectObj      = null;
        }
    }