Пример #1
0
    protected void Awake()
    {
        if (SP != null && SP != this && SP.gameObject != null)
        {
            GameObject.DestroyImmediate(SP.gameObject);
        }

        SP = this;
        DontDestroyOnLoad(this.gameObject);

        this.updateInterval            = 1000 / PhotonNetworkManager.sendRate;
        this.updateIntervalOnSerialize = 1000 / PhotonNetworkManager.sendRateOnSerialize;

        PhotonMenuManager.StartFallbackSendAckThread();
    }
Пример #2
0
    public void ApplyUserIdAndConnect()
    {
        string nickName = "DemoNick";

        if (this.InputField != null && !string.IsNullOrEmpty(this.InputField.text))
        {
            nickName = this.InputField.text;
            PlayerPrefs.SetString(NickNamePlayerPrefsKey, nickName);
        }
        //if (string.IsNullOrEmpty(UserId))
        //{
        //    this.UserId = nickName + "ID";
        //}

        if (PhotonNetworkManager.AuthValues == null)
        {
            PhotonNetworkManager.AuthValues = new AuthenticationValues();
        }
        //else
        //{
        //    Debug.Log("Re-using AuthValues. UserId: " + PhotonNetwork.AuthValues.UserId);
        //}


        PhotonNetworkManager.AuthValues.UserId = nickName;

        Debug.Log("Nickname: " + nickName + " userID: " + this.UserId, this);



        PhotonNetworkManager.playerName = nickName;
        PhotonNetworkManager.ConnectUsingSettings("0.5");

        // this way we can force timeouts by pausing the client (in editor)
        PhotonMenuManager.StopFallbackSendAckThread();
    }
Пример #3
0
 /// <summary>Called by Unity when the application is closed. Disconnects.</summary>
 protected void OnApplicationQuit()
 {
     PhotonMenuManager.AppQuits = true;
     PhotonMenuManager.StopFallbackSendAckThread();
     PhotonNetworkManager.Disconnect();
 }
Пример #4
0
 /// <summary>Called by Unity when the play mode ends. Used to cleanup.</summary>
 protected void OnDestroy()
 {
     //Debug.Log("OnDestroy on PhotonHandler.");
     PhotonMenuManager.StopFallbackSendAckThread();
     //PhotonNetwork.Disconnect();
 }
Пример #5
0
 public void OnClickReConnectAndRejoin()
 {
     PhotonNetworkManager.ReconnectAndRejoin();
     PhotonMenuManager.StopFallbackSendAckThread();  // this is used in the demo to timeout in background!
 }
Пример #6
0
 public void OnClickConnect()
 {
     PhotonNetworkManager.ConnectUsingSettings(null);
     PhotonMenuManager.StopFallbackSendAckThread();  // this is used in the demo to timeout in background!
 }
Пример #7
0
    public void Update()
    {
        // Check if we are out of context, which means we likely got back to the demo hub.
        if (this.DisconnectedPanel == null)
        {
            Destroy(this.gameObject);
        }

        // for debugging, it's useful to have a few actions tied to keys:
        if (Input.GetKeyUp(KeyCode.L))
        {
            PhotonNetworkManager.LeaveRoom();
        }
        if (Input.GetKeyUp(KeyCode.C))
        {
            PhotonNetworkManager.ConnectUsingSettings(null);
            PhotonMenuManager.StopFallbackSendAckThread();
        }


        if (!PhotonNetworkManager.inRoom)
        {
            return;
        }

        // disable the "reconnect panel" if PUN is connected or connecting
        if (PhotonNetworkManager.connected && this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(false);
        }
        if (!PhotonNetworkManager.connected && !PhotonNetworkManager.connecting && !this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(true);
        }


        if (PhotonNetworkManager.room.PlayerCount > 1)
        {
            if (this.turnManager.IsOver)
            {
                return;
            }

            /*
             * // check if we ran out of time, in which case we loose
             * if (turnEnd<0f && !IsShowingResults)
             * {
             *              Debug.Log("Calling OnTurnCompleted with turnEnd ="+turnEnd);
             *              OnTurnCompleted(-1);
             *              return;
             * }
             */

            if (this.TurnText != null)
            {
                this.TurnText.text = this.turnManager.Turn.ToString();
            }

            if (this.turnManager.Turn > 0 && this.TimeText != null && !IsShowingResults)
            {
                this.TimeText.text = this.turnManager.RemainingSecondsInTurn.ToString("F1") + " SECONDS";

                TimerFillImage.anchorMax = new Vector2(1f - this.turnManager.RemainingSecondsInTurn / this.turnManager.TurnDuration, 1f);
            }
        }

        this.UpdatePlayerTexts();

        // show local player's selected hand
        Sprite selected = SelectionToSprite(this.localSelection);

        if (selected != null)
        {
            this.localSelectionImage.gameObject.SetActive(true);
            this.localSelectionImage.sprite = selected;
        }

        // remote player's selection is only shown, when the turn is complete (finished by both)
        if (this.turnManager.IsCompletedByAll)
        {
            selected = SelectionToSprite(this.remoteSelection);
            if (selected != null)
            {
                this.remoteSelectionImage.color  = new Color(1, 1, 1, 1);
                this.remoteSelectionImage.sprite = selected;
            }
        }
        else
        {
            ButtonCanvasGroup.interactable = PhotonNetworkManager.room.PlayerCount > 1;

            if (PhotonNetworkManager.room.PlayerCount < 2)
            {
                this.remoteSelectionImage.color = new Color(1, 1, 1, 0);
            }

            // if the turn is not completed by all, we use a random image for the remote hand
            else if (this.turnManager.Turn > 0 && !this.turnManager.IsCompletedByAll)
            {
                // alpha of the remote hand is used as indicator if the remote player "is active" and "made a turn"
                PhotonPlayer remote = PhotonNetworkManager.player.GetNext();
                float        alpha  = 0.5f;
                if (this.turnManager.GetPlayerFinishedTurn(remote))
                {
                    alpha = 1;
                }
                if (remote != null && remote.IsInactive)
                {
                    alpha = 0.1f;
                }

                this.remoteSelectionImage.color  = new Color(1, 1, 1, alpha);
                this.remoteSelectionImage.sprite = SelectionToSprite(randomHand);
            }
        }
    }