Exemplo n.º 1
0
 public void SelectFriend(int index)
 {
     JoinButton.SetActive(true);
     joinButtonText.text = $"Join {SteamFriends.GetFriendPersonaName(steamFriends[index].steamID)}";
     selectedFriend      = steamFriends[index].steamID;
     Log("User has selected " + SteamFriends.GetFriendPersonaName(steamFriends[index].steamID));
     Networker.SendP2P(steamFriends[index].steamID, new Message_LobbyInfoRequest(), EP2PSend.k_EP2PSendReliable); //Getting lobby info.
     selectionTF.position = steamFriends[index].transform.position;
     selectionTF.GetComponent <Image>().color = new Color(0.3529411764705882f, 0.196078431372549f, 0);
 }
Exemplo n.º 2
0
    private void CreateUI()
    {
        Log("Creating Multiplayer UI");
        Transform ScenarioDisplay = GameObject.Find("InteractableCanvas").transform.GetChild(0).GetChild(6).GetChild(0).GetChild(1);

        if (ScenarioDisplay.name != "ScenarioDisplay")
        {
            Log($"ScenarioDisplay was wrong ({ScenarioDisplay.name}), trying other method");
            ScenarioDisplay = GameObject.Find("InteractableCanvas").transform.GetChild(0).GetChild(7).GetChild(0).GetChild(1);
            Log($"ScenarioDisplay now == {ScenarioDisplay.name}");
        }
        //Creating the MP button
        Transform mpButton = Instantiate(ScenarioDisplay.GetChild(6).gameObject, ScenarioDisplay).transform;

        Log("Multiplayer Button" + mpButton.name);
        mpButton.gameObject.SetActive(true);
        mpButton.name = "MPButton";
        mpButton.GetComponent <RectTransform>().localPosition = new Vector3(601, -325);
        mpButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 206.7f);
        mpButton.GetComponentInChildren <Text>().text         = "MP";
        mpButton.GetComponent <Image>().color    = Color.cyan;
        mpButton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
        VRInteractable mpInteractable = mpButton.GetComponent <VRInteractable>();

        mpInteractable.interactableName = "Multiplayer";
        mpInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();


        Log("Creating Mp Menu");//Creating Mp Menu
        GameObject MPMenu     = Instantiate(ScenarioDisplay.gameObject, ScenarioDisplay.parent);
        GameObject ScrollView = null;

        for (int i = 0; i < MPMenu.transform.childCount; i++)
        {
            if (MPMenu.transform.GetChild(i).name != "Scroll View")
            {
                Destroy(MPMenu.transform.GetChild(i).gameObject);
            }
            else
            {
                ScrollView = MPMenu.transform.GetChild(i).gameObject;
                scrollRect = ScrollView.GetComponent <ScrollRect>();
            }
        }
        content     = ScrollView.transform.GetChild(0).GetChild(0).gameObject;
        selectionTF = content.transform.GetChild(0);
        selectionTF.GetComponent <Image>().color = new Color(0, 0, 0, 0);
        Log("Copying the List from select Campaign for friends");//Copying the List from select Campaign for friends
        friendsTemplate = content.transform.GetChild(1).gameObject;
        buttonHeight    = ((RectTransform)friendsTemplate.transform).rect.height;


        Log("Getting the headers from the campaign display"); //Getting the headers from the campaign display
        GameObject lableTemplate = ScenarioDisplay.parent.GetChild(0).GetChild(5).GetChild(0).GetChild(0).GetChild(2).gameObject;

        lableVTOL = Instantiate(lableTemplate, content.transform);
        lableVTOL.GetComponentInChildren <Text>().text = "In VTOL VR";
        lableVTOL.SetActive(true);

        Log("Back Button");//Back Button
        GameObject BackButton = Instantiate(mpButton.gameObject, MPMenu.transform);

        BackButton.GetComponent <RectTransform>().localPosition = new Vector3(-508, -325);
        BackButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        BackButton.GetComponentInChildren <Text>().text         = "Back";
        BackButton.GetComponent <Image>().color = Color.red;
        VRInteractable BackInteractable = BackButton.GetComponent <VRInteractable>();

        BackInteractable.interactableName = "Back";
        BackInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        BackInteractable.OnInteract.AddListener(delegate { Log("Before Back"); MPMenu.SetActive(false); ScenarioDisplay.gameObject.SetActive(true); });
        Log("Host");//Host
        GameObject HostButton = Instantiate(mpButton.gameObject, MPMenu.transform);

        HostButton.GetComponent <RectTransform>().localPosition = new Vector3(0, -325);
        HostButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        HostButton.GetComponentInChildren <Text>().text         = "Host";
        HostButton.GetComponent <Image>().color = Color.green;
        VRInteractable HostInteractable = HostButton.GetComponent <VRInteractable>();

        HostInteractable.interactableName = "Host Game";
        HostInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        HostInteractable.OnInteract.AddListener(delegate { Log("Before Host"); Host(); });
        Log("Join");//Join
        JoinButton = Instantiate(mpButton.gameObject, MPMenu.transform);
        JoinButton.GetComponent <RectTransform>().localPosition = new Vector3(489, -325);
        JoinButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        joinButtonText      = JoinButton.GetComponentInChildren <Text>();
        joinButtonText.text = "Join";
        joinButtonText.resizeTextForBestFit     = true;
        JoinButton.GetComponent <Image>().color = Color.green;
        VRInteractable JoinInteractable = JoinButton.GetComponent <VRInteractable>();

        JoinInteractable.interactableName = "Join Game";
        JoinInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        JoinInteractable.OnInteract.AddListener(delegate { Log("Before Join"); Join(); });
        JoinButton.SetActive(false);
        Log("Lobby Info Text");
        GameObject lobbyInfoGO = Instantiate(mpButton.transform.GetChild(0).gameObject, MPMenu.transform);

        lobbyInfoGO.GetComponent <RectTransform>().localPosition = new Vector3(-168.3f, -30.9f);
        lobbyInfoGO.GetComponent <RectTransform>().sizeDelta     = new Vector2(942.9f, 469.8f);
        lobbyInfoText           = lobbyInfoGO.GetComponent <Text>();
        lobbyInfoText.text      = "Select a friend or host a lobby.";
        lobbyInfoText.alignment = TextAnchor.UpperLeft;
        lobbyInfoText.transform.localRotation = Quaternion.Euler(lobbyInfoText.transform.localRotation.eulerAngles.x + 90,
                                                                 lobbyInfoText.transform.localRotation.y,
                                                                 lobbyInfoText.transform.localRotation.z);
        Log("Last one");
        mpInteractable.OnInteract.AddListener(delegate { Log("Before Opening MP"); RefershFriends(); MPMenu.SetActive(true); ScenarioDisplay.gameObject.SetActive(false); OpenMP(); });
        GameObject.Find("InteractableCanvas").GetComponent <VRPointInteractableCanvas>().RefreshInteractables();
        Log("Finished");
    }
Exemplo n.º 3
0
    public void RefershFriends()
    {
        Log("Refreshing Friends");
        int friendsCount = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate);

        if (friendsCount == -1)
        {
            LogError("Friendcount == -1, user isn't logged into steam");
            return;
        }

        /*
         * First we are going to sort the list into four sections
         * Friends playing vtol vr
         * Friends in game
         * Friends online
         * Friends offline
         */
        CSteamID        lastFriendID;
        List <CSteamID> vtolvrFriends = new List <CSteamID>();

        Log("Getting all friends");
        for (int i = 0; i < friendsCount; i++)
        {
            lastFriendID = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate);
            if (SteamFriends.GetFriendGamePlayed(lastFriendID, out FriendGameInfo_t gameInfo))
            {
                if (gameInfo.m_gameID.AppID().m_AppId == 667970)
                {
                    //User is in VTOLVR
                    vtolvrFriends.Add(lastFriendID);
                    continue;
                }
            }
        }
        Log("Adding friends to list");
        //Now we want to create the ingame list
        friendsTemplate.SetActive(true);
        GameObject           lastFriendGO;
        VRUIListItemTemplate uiListItem;
        int totalFriends = 0;

        lableVTOL.transform.localPosition = new Vector3(0, -totalFriends * buttonHeight);
        for (int i = 0; i < vtolvrFriends.Count; i++)
        {
            totalFriends++;
            lastFriendGO = Instantiate(friendsTemplate, content.transform);
            steamFriends.Add(new FriendItem(vtolvrFriends[i], lastFriendGO.transform));
            lastFriendGO.transform.localPosition = new Vector3(0f, -totalFriends * buttonHeight);
            uiListItem = lastFriendGO.GetComponent <VRUIListItemTemplate>();
            uiListItem.Setup(SteamFriends.GetFriendPersonaName(vtolvrFriends[i]), totalFriends - 1, SelectFriend);
            uiListItem.labelText.color = Color.green;
        }

        Log("Updating Scroll Rect");
        scrollRect.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (2f + steamFriends.Count) * buttonHeight);
        scrollRect.ClampVertical();

        JoinButton.SetActive(false);
        friendsTemplate.SetActive(false);
        Log("Refreahing Interactables");
        GameObject.Find("InteractableCanvas").GetComponent <VRPointInteractableCanvas>().RefreshInteractables();
        Log($"Total Friends:{totalFriends} In VTOLVR:{vtolvrFriends.Count}");
        Networker.ResetNetworkUID();
    }
Exemplo n.º 4
0
    private void CreateUI()
    {
        while (!SceneManager.GetActiveScene().isLoaded)
        {
            Debug.Log("Waiting for scene to be loaded");
        }
        Log("Creating Multiplayer UI");
        CheckUpToDate();

        Transform ScenarioDisplay      = null;
        bool      foundDisplay         = false;
        bool      foundCampaginDisplay = false;
        int?      campaignDisplayCount = null;

        Debug.Log("Looping through canvases to find the Scenario Display");


        // Get the interactable canvas
        for (int i = 0; i < GameObject.Find("InteractableCanvas").transform.GetChild(0).childCount; i++)
        {
            // Loop through each child to find the Campaign Select Canavas
            ScenarioDisplay = GameObject.Find("InteractableCanvas").transform.GetChild(0).GetChild(i);
            if (ScenarioDisplay.name == "CampaignSelector")
            {
                foundCampaginDisplay = true;
                campaignDisplayCount = i;
                // Get the next page in the campaign selector (The scenario display)
                ScenarioDisplay = ScenarioDisplay.GetChild(0).GetChild(1);

                // If the name is ScenarioDisplay, we found it! Breaking out of the for loop to continue on...
                if (ScenarioDisplay.name == "ScenarioDisplay")
                {
                    foundDisplay = true;
                    break;
                }
            }
        }
        Debug.Log($"Found Campaign Display? { foundCampaginDisplay.ToString() }");

        if (campaignDisplayCount != null)
        {
            Debug.Log($"Found Campaign Display { campaignDisplayCount.ToString() } canvases down.");
        }

        Debug.Log($"Found Scenario Display? { foundDisplay.ToString() }");

        //Creating the MP button
        Transform mpButton = Instantiate(ScenarioDisplay.GetChild(10).gameObject, ScenarioDisplay).transform;

        Log("Multiplayer Button" + mpButton.name);
        mpButton.gameObject.SetActive(true);
        mpButton.name = "MPButton";
        mpButton.GetComponent <RectTransform>().localPosition = new Vector3(601, -325);
        mpButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 206.7f);
        mpButton.GetComponentInChildren <Text>().text         = "MP";
        mpButton.GetComponent <Image>().color    = Color.cyan;
        mpButton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
        VRInteractable mpInteractable = mpButton.GetComponent <VRInteractable>();

        if (UpToDate)
        {
            mpButton.GetComponent <Image>().color = Color.cyan;
            mpInteractable.interactableName       = "Multiplayer";
        }
        else
        {
            mpButton.GetComponent <Image>().color = Color.red;
            mpInteractable.interactableName       = "Outdated";
        }
        mpInteractable.OnInteract = new UnityEngine.Events.UnityEvent();


        Log("Creating Mp Menu");//Creating Mp Menu
        GameObject MPMenu     = Instantiate(ScenarioDisplay.gameObject, ScenarioDisplay.parent);
        GameObject ScrollView = null;

        for (int i = 0; i < MPMenu.transform.childCount; i++)
        {
            if (MPMenu.transform.GetChild(i).name != "Scroll View")
            {
                Destroy(MPMenu.transform.GetChild(i).gameObject);
            }
            else
            {
                ScrollView = MPMenu.transform.GetChild(i).gameObject;
                scrollRect = ScrollView.GetComponent <ScrollRect>();
            }
        }
        content     = ScrollView.transform.GetChild(0).GetChild(0).gameObject;
        selectionTF = content.transform.GetChild(0);
        selectionTF.GetComponent <Image>().color = new Color(0, 0, 0, 0);
        Log("Copying the List from select Campaign for friends"); //Copying the List from select Campaign for friends
        friendsTemplate = content.transform.GetChild(1).gameObject;
        buttonHeight    = ((RectTransform)friendsTemplate.transform).rect.height;

        Log("Getting the headers from the campaign display for the join log"); //Getting the headers from the campaign display
        GameObject lableTemplateHeader = ScenarioDisplay.Find("Title").gameObject;

        lableVTOLMPHeader = Instantiate(lableTemplateHeader, MPMenu.transform);

        lableVTOLMPHeader.GetComponent <RectTransform>().localPosition         = new Vector3(-200, 320);
        lableVTOLMPHeader.GetComponentInChildren <Text>().text                 = "Welcome to VTOL VR Multiplayer!";
        lableVTOLMPHeader.GetComponentInChildren <Text>().resizeTextForBestFit = true;
        lableVTOLMPHeader.GetComponentInChildren <Text>().color                = new Color32(252, 183, 34, 255);
        lableVTOLMPHeader.GetComponentInChildren <Text>().fontSize             = 55;
        lableVTOLMPHeader.SetActive(true);


        Log("Getting the headers from the campaign display for the join log"); //Getting the headers from the campaign display
        GameObject lableTemplateIntro = ScenarioDisplay.Find("Title").gameObject;

        lableVTOLMPIntro = Instantiate(lableTemplateIntro, MPMenu.transform);

        lableVTOLMPIntro.GetComponent <RectTransform>().localPosition = new Vector3(-200, 200);
        lableVTOLMPIntro.GetComponent <RectTransform>().sizeDelta     = new Vector2(850, 500.3f);
        if (UpToDate)
        {
            lableVTOLMPIntro.GetComponentInChildren <Text>().text = $"Hello and welcome to multiplayer version {ModVersionString.ModVersionNumber}!\n\nThis is an alpha release and very much so a work in progress. Expect bugs!\n\nPlease report any issues at https://vtolvr-mods.com or on the modding discord here: https://discord.gg/pW4rkYf";
        }
        else
        {
            lableVTOLMPIntro.GetComponentInChildren <Text>().text = $"Hello and welcome to multiplayer version {ModVersionString.ModVersionNumber}!\n\nThis is an outdated version, please update the mod to be able to play with other players who have higher versions, and while you're at it, expect bugs!\n\nPlease report any issues at https://vtolvr-mods.com or on the modding discord here: https://discord.gg/pW4rkYf";
        }
        //lableVTOLJoinLog.GetComponentInChildren<Text>().resizeTextForBestFit = true;
        lableVTOLMPIntro.GetComponentInChildren <Text>().color    = new Color32(255, 255, 255, 255);
        lableVTOLMPIntro.GetComponentInChildren <Text>().fontSize = 20;
        lableVTOLMPIntro.SetActive(true);

        Log("Getting the headers from the campaign display for the join log"); //Getting the headers from the campaign display
        GameObject lableTemplateLog = ScenarioDisplay.Find("Title").gameObject;

        lableVTOLJoinLog = Instantiate(lableTemplateLog, MPMenu.transform);

        lableVTOLJoinLog.GetComponent <RectTransform>().localPosition = new Vector3(-200, 00);
        lableVTOLJoinLog.GetComponent <RectTransform>().sizeDelta     = new Vector2(850, 300f);
        lableVTOLJoinLog.GetComponentInChildren <Text>().text         = "";
        //lableVTOLJoinLog.GetComponentInChildren<Text>().resizeTextForBestFit = true;
        lableVTOLJoinLog.GetComponentInChildren <Text>().color    = new Color32(255, 0, 0, 255);
        lableVTOLJoinLog.GetComponentInChildren <Text>().fontSize = 20;
        lableVTOLJoinLog.SetActive(true);

        contentJoinLog = lableVTOLJoinLog.GetComponentInChildren <Text>();

        Log("Getting the headers from the campaign display"); //Getting the headers from the campaign display
        GameObject lableTemplate = ScenarioDisplay.parent.GetChild(0).GetChild(5).GetChild(0).GetChild(0).GetChild(2).gameObject;

        lableVTOL = Instantiate(lableTemplate, content.transform);
        lableVTOL.GetComponentInChildren <Text>().text = "In VTOL VR";
        lableVTOL.SetActive(true);

        Log("Back Button");//Back Button
        GameObject BackButton = Instantiate(mpButton.gameObject, MPMenu.transform);

        BackButton.GetComponent <RectTransform>().localPosition = new Vector3(-508, -325);
        BackButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        BackButton.GetComponentInChildren <Text>().text         = "Back";
        BackButton.GetComponent <Image>().color = Color.red;
        VRInteractable BackInteractable = BackButton.GetComponent <VRInteractable>();

        BackInteractable.interactableName = "Back";
        BackInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        BackInteractable.OnInteract.AddListener(delegate { Log("Before Back"); MPMenu.SetActive(false); ScenarioDisplay.gameObject.SetActive(true); });
        Log("Host");//Host
        GameObject HostButton = Instantiate(mpButton.gameObject, MPMenu.transform);

        HostButton.GetComponent <RectTransform>().localPosition = new Vector3(0, -325);
        HostButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        HostButton.GetComponentInChildren <Text>().text         = "Host";
        HostButton.GetComponent <Image>().color = Color.green;
        VRInteractable HostInteractable = HostButton.GetComponent <VRInteractable>();

        HostInteractable.interactableName = "Host Game";
        HostInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        HostInteractable.OnInteract.AddListener(delegate { Log("Before Host"); Host(); });
        Log("Join");//Join
        JoinButton = Instantiate(mpButton.gameObject, MPMenu.transform);
        JoinButton.GetComponent <RectTransform>().localPosition = new Vector3(489, -325);
        JoinButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(70, 256.3f);
        joinButtonText      = JoinButton.GetComponentInChildren <Text>();
        joinButtonText.text = "Join";
        joinButtonText.resizeTextForBestFit     = true;
        JoinButton.GetComponent <Image>().color = Color.blue;
        VRInteractable JoinInteractable = JoinButton.GetComponent <VRInteractable>();

        JoinInteractable.interactableName = "Join Game";
        JoinInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        JoinInteractable.OnInteract.AddListener(delegate { Log("Before Join"); Join(); });
        JoinButton.SetActive(false);
        Log("Lobby Info Text");
        GameObject lobbyInfoGO = Instantiate(mpButton.transform.GetChild(0).gameObject, MPMenu.transform);

        lobbyInfoGO.GetComponent <RectTransform>().localPosition = new Vector3(-168.3f, -30.9f);
        lobbyInfoGO.GetComponent <RectTransform>().sizeDelta     = new Vector2(942.9f, 469.8f);
        lobbyInfoText           = lobbyInfoGO.GetComponent <Text>();
        lobbyInfoText.text      = "Select a friend or host a lobby.";
        lobbyInfoText.alignment = TextAnchor.UpperLeft;
        lobbyInfoText.transform.localRotation = Quaternion.Euler(lobbyInfoText.transform.localRotation.eulerAngles.x + 90,
                                                                 lobbyInfoText.transform.localRotation.y,
                                                                 lobbyInfoText.transform.localRotation.z);
        Log("Last one");
        mpInteractable.OnInteract.AddListener(delegate { Log("Before Opening MP"); RefershFriends(); MPMenu.SetActive(true); ScenarioDisplay.gameObject.SetActive(false); OpenMP(); });
        GameObject.Find("InteractableCanvas").GetComponent <VRPointInteractableCanvas>().RefreshInteractables();
        Log("Finished");

        Log("Refresh");//Host
        GameObject RefreshButton = Instantiate(mpButton.gameObject, MPMenu.transform);

        RefreshButton.GetComponent <RectTransform>().localPosition = new Vector3(510, 322);
        RefreshButton.GetComponent <RectTransform>().sizeDelta     = new Vector2(50, 250f);
        RefreshButton.GetComponentInChildren <Text>().text         = "Refresh";
        RefreshButton.GetComponent <Image>().color = Color.red;
        VRInteractable RefreshInteractable = RefreshButton.GetComponent <VRInteractable>();

        RefreshInteractable.interactableName = "Refresh Friends";
        RefreshInteractable.OnInteract       = new UnityEngine.Events.UnityEvent();
        RefreshInteractable.OnInteract.AddListener(delegate { Log("Before Host"); RefershFriends(); });
    }