Example #1
0
    private bool m_wasChanged; // Store if the hat was changed last update frame

    private void AddPlayer()
    {
        // Loop through how many controllers are plugged in to the system
        for (int i = 0; i < XCI.GetNumPluggedCtrlrs(); i++)
        {
            // Check that we havent hit the max number of players allowed to play
            if (m_playersAdded + 1 <= Menus.GetMaxNumOfPlayers())
            {
                // Store the controller to the first enum plus the loops iteration
                XboxController controller = XboxController.First + i;

                // Check for A button press and that the program has gotten over the pressDelay
                if (XCI.GetButtonDown(XboxButton.A, controller))
                {
                    // Check for how many players are already activated
                    for (int j = 0; j < Menus.GetActivatedPlayerAmount(); j++)
                    {
                        // Keep the same controller from joining the game multiple times
                        StaticVariables holder = Menus.GetPlayerInformation(j);
                        if (holder.Controller == controller)
                        {
                            Debug.Log("Controller Already Added.");
                            return;
                        }
                    }

                    // Check that the controller isn't already added
                    if ((i + 1) < XCI.GetNumPluggedCtrlrs()) // If this works I'm going to slap my knee and yell Yee-Haw.
                    {
                        // Add the new player to the playerList
                        StaticVariables newPlayer = new StaticVariables();
                        newPlayer.Controller = controller;
                        newPlayer.Player = m_playersAdded;
                        newPlayer.Hat = m_hats[(int)e_Hats.NONE];
                        newPlayer.HatID = (e_Hats.NONE);
                        newPlayer.PlayerMaterial = m_playerMats[m_playersAdded];
                        Menus.AddToPlayerList(newPlayer, m_playersAdded);

                        // Enable the panel to occupy the index position by a controller
                        m_unreadyPlayers[m_playersAdded].SetActive(true);

                        // Disable the 'Joining' panel
                        m_joinPanel[m_playersAdded].SetActive(false);

                        // Display some dope hats
                        newPlayer.Hat = Instantiate(m_hats[(int)e_Hats.NONE]);
                        newPlayer.Hat.transform.SetParent(m_unreadyAttachPoints[m_playersAdded]);
                        newPlayer.Hat.transform.ResetTransform();

                        // Create the confirm panel
                        m_listOfUI[m_playersAdded].SetActive(true);

                        // Change the shirt colour of the player
                        Material newMat = Instantiate(newPlayer.PlayerMaterial);
                        newMat.SetColor(newPlayer.PlayerMaterial.name, newPlayer.PlayerMaterial.color);

                        SkinnedMeshRenderer thisRenderer = m_unreadyShirt[m_playersAdded].GetComponent<SkinnedMeshRenderer>();
                        thisRenderer.material = newMat;

                        // Increase the amount of players added
                        m_playersAdded++;
                    }
                    else // Handle the last controller plugged in
                    {
                        // Add the new player to the playerList
                        StaticVariables newPlayer = new StaticVariables();
                        newPlayer.Controller = controller;
                        newPlayer.Player = m_playersAdded;
                        newPlayer.Hat = m_hats[((int)e_Hats.NONE)];
                        newPlayer.HatID = (e_Hats.NONE);
                        //if(m_playersAdded == 0 && )

                        //Need to look at colour assaignment here.
                        newPlayer.PlayerMaterial = m_playerMats[m_playersAdded];

                        //if (m_playersAdded == 0)// Means it's blue. 0123
                        //{
                        //    newPlayer.HatMaterial = m_hatMaterials[((int)newPlayer.HatID)];
                        //}
                        //else
                        //{
                        //    newPlayer.HatMaterial = m_hatMaterials[(m_playersAdded * 4) + (int)newPlayer.HatID]; // Do cool math here
                        //}
                        Menus.AddToPlayerList(newPlayer, m_playersAdded);

                        // Enable the panel to occupy the index position by a controller
                        m_unreadyPlayers[m_playersAdded].SetActive(true);

                        // Disable the 'Joining' panel
                        m_joinPanel[m_playersAdded].SetActive(false);

                        // Display some dope hats
                        newPlayer.Hat = Instantiate(m_hats[(int)newPlayer.HatID]);
                        newPlayer.Hat.transform.SetParent(m_unreadyAttachPoints[m_playersAdded]);
                        newPlayer.Hat.transform.ResetTransform();

                        // Create the confirm panel
                        m_listOfUI[m_playersAdded].SetActive(true);

                        // Change the shirt colour of the player
                        Material newMat = Instantiate(newPlayer.PlayerMaterial);
                        newMat.SetColor(newPlayer.PlayerMaterial.name, newPlayer.PlayerMaterial.color);

                        SkinnedMeshRenderer thisRenderer = m_unreadyShirt[newPlayer.Player].GetComponent<SkinnedMeshRenderer>();
                        thisRenderer.material = newMat;

                        //Material newHat = Instantiate(newPlayer.HatMaterial);
                        //newHat.SetColor(newPlayer.HatMaterial.name, newPlayer.HatMaterial.color);

                        //MeshRenderer hatRenderer = newPlayer.Hat.GetComponent<Reference>().m_reference.GetComponent<MeshRenderer>();
                        //hatRenderer.material = newHat;

                        // Increase the amount of players added
                        m_playersAdded++;
                    }
                }
            }
        }
    }