Ejemplo n.º 1
0
    //This RPC is meant to updated the states between client and master client that way they're always matching in terms of event states
    private void RPCSyncEventState(bool isMasterClient, LevelCreationState currentState)
    {
        if (isMasterClient)
        {
            m_MasterClientState = currentState;
        }

        else
        {
            m_ClientState = currentState;
        }
    }
Ejemplo n.º 2
0
    //This method will move through the steps of setting up the game generation states
    private void UpdateEventSequence()
    {
        bool canRunEvents = false;
        LevelCreationState currentState = m_ClientState;

        //what this code will do is compare the master client's event state and the client's event state. If the master client is behind or at the equivalent state then that means
        //that the master client can run. If the client is at an equivelent or lesser state then it can run. This is all relative to how values get recieved but should allow the client
        //and master client to run indepently but also while feeding from eachother.
        if (PhotonNetwork.isMasterClient)
        {
            canRunEvents = m_MasterClientState <= m_ClientState;
            currentState = m_MasterClientState;
        }
        else
        {
            canRunEvents = m_ClientState <= m_MasterClientState;
        }

        //DEBUGING PURPOSES ONLY
        if (DebugMode)
        {
            m_MasterClientState = m_ClientState;
            canRunEvents        = true;
        }
        if (PhotonNetwork.playerList.Length == 1)
        {
            canRunEvents = true;
        }

        if (canRunEvents)
        {
            switch (currentState)
            {
            case LevelCreationState.LevelGeneration:

                if (LevelGeneration != null)
                {
                    LevelGeneration(this, null);
                }
                Debug.Log("LevelGeneration completed, moving to LevelBaking.");
                break;

            case LevelCreationState.LevelBaking:

                if (LevelBaking != null)
                {
                    LevelBaking(this, null);
                }
                Debug.Log("LevelBaking complete, moving to LevelPopulation.");
                break;

            case LevelCreationState.LevelPopulation:

                if (LevelPopulation != null)
                {
                    LevelPopulation(this, null);
                }
                Debug.Log("LevelPopulation complete, moving to PlayerPopulation");
                break;

            case LevelCreationState.PlayerPopulation:

                if (PlayerPopulation != null)
                {
                    PlayerPopulation(this, null);
                }
                Debug.Log("PlayerPopulation complete, moving to PostPlayer.");
                break;

            case LevelCreationState.PostPlayer:

                if (PostPlayer != null)
                {
                    PostPlayer(this, null);
                }
                Debug.Log("PostPlayer complete, moving to FinalizeObjectPools.");
                break;

            case LevelCreationState.FinalizeObjectPools:
                if (FinalizeObjectPools != null)
                {
                    FinalizeObjectPools(this, null);
                }
                Debug.Log("Object pools are now synced, moving to final step.");
                break;

            case LevelCreationState.FinalStep:
                if (FinalStep != null)
                {
                    FinalStep(this, null);
                }
                m_EventsCompleted = true;
                Debug.Log("Final step completed, game can now begin.");
                return;
            }

            //if the master client is the one who finished the current event then that value needs to be incremented and then synced to the client
            if (PhotonNetwork.isMasterClient)
            {
                m_MasterClientState++;
                if (PhotonNetwork.inRoom)
                {
                    photonView.RPC("RPCSyncEventState", PhotonTargets.All, true, m_MasterClientState);
                }
            }
            //if the client is finished with the current event then that needs to be synced and the master client needs to know that the client is ready to begin the next event sequence
            else
            {
                m_ClientState++;
                if (PhotonNetwork.inRoom)
                {
                    photonView.RPC("RPCSyncEventState", PhotonTargets.All, false, m_ClientState);
                }
            }
        }
    }
Ejemplo n.º 3
0
 private void ResetGameManager()
 {
     m_EventsCompleted   = false;
     m_MasterClientState = LevelCreationState.LevelGeneration;
     m_ClientState       = LevelCreationState.LevelGeneration;
 }