Internal Monobehaviour that allows Photon to run an Update loop.
Inheritance: Photon.MonoBehaviour, IPhotonPeerListener
    private void Awake()
    {
        if (SP != null && SP != this && SP.gameObject != null)
        {
            GameObject.DestroyImmediate(SP.gameObject);
        }

        SP = this;
        DontDestroyOnLoad(this.gameObject);

        this.updateInterval = 1000 / PhotonNetwork.sendRate;
        this.updateIntervalOnSerialize = 1000 / PhotonNetwork.sendRateOnSerialize;
    }
Exemple #2
0
    protected void Awake()
    {
        if (SP != null && SP != this && SP.gameObject != null)
        {
            GameObject.DestroyImmediate(SP.gameObject);
        }

        SP = this;
        DontDestroyOnLoad(this.gameObject);

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

        PhotonHandler.StartFallbackSendAckThread();
    }
    private void Awake()
    {
        if (SP != null && SP != this)
        {
            Debug.LogError("Error: we already have an PhotonMono around!");
            Destroy(this.gameObject);
        }

        DontDestroyOnLoad(this);
        SP = this;

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

    }
 // Token: 0x0600B224 RID: 45604 RVA: 0x00415FAC File Offset: 0x004141AC
 protected void DOFKFBFNNNO()
 {
     PhotonHandler.StopFallbackSendAckThread();
 }
Exemple #5
0
    /// <summary>
    /// Static constructor used for basic setup.
    /// </summary>
    static PhotonNetwork()
    {
        #if UNITY_EDITOR
        if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
        {
            //Debug.Log(string.Format("PhotonNetwork.ctor() Not playing {0} {1}", UnityEditor.EditorApplication.isPlaying, UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode));
            return;
        }

        // This can happen when you recompile a script IN play made
        // This helps to surpress some errors, but will not fix breaking
        PhotonHandler[] photonHandlers = GameObject.FindObjectsOfType(typeof(PhotonHandler)) as PhotonHandler[];
        if (photonHandlers != null && photonHandlers.Length > 0)
        {
            Debug.LogWarning("Unity recompiled. Connection gets closed and replaced. You can connect as 'new' client.");
            foreach (PhotonHandler photonHandler in photonHandlers)
            {
                //Debug.Log("Handler: " + photonHandler + " photonHandler.gameObject: " + photonHandler.gameObject);
                photonHandler.gameObject.hideFlags = 0;
                GameObject.DestroyImmediate(photonHandler.gameObject);
                Component.DestroyImmediate(photonHandler);
            }
        }
        #endif

        Application.runInBackground = true;

        // Set up a MonoBehaviour to run Photon, and hide it
        GameObject photonGO = new GameObject();
        photonMono = (PhotonHandler)photonGO.AddComponent<PhotonHandler>();

        #if !(UNITY_WINRT || UNITY_WP8 || UNITY_PS3 || UNITY_WIIU)
        photonGO.AddComponent<PingCloudRegions>();
        #endif
        photonGO.name = "PhotonMono";
        photonGO.hideFlags = HideFlags.HideInHierarchy;

        // Set up the NetworkingPeer
        networkingPeer = new NetworkingPeer(photonMono, string.Empty, ConnectionProtocol.Udp);
        networkingPeer.LimitOfUnreliableCommands = 40;

        // Local player
        CustomTypes.Register();
    }
 public void OnClickConnect()
 {
     PhotonNetwork.ConnectUsingSettings(null);
     PhotonHandler.StopFallbackSendAckThread();  // this is used in the demo to timeout in background!
 }
Exemple #7
0
 /// <summary>Called by Unity when the application is closed. Disconnects.</summary>
 protected void OnApplicationQuit()
 {
     PhotonHandler.AppQuits = true;
     PhotonHandler.StopFallbackSendAckThread();
     PhotonNetwork.Disconnect();
 }
Exemple #8
0
 protected void OnDestroy()
 {
     PhotonHandler.StopFallbackSendAckThread();
 }
 // Token: 0x0600B259 RID: 45657 RVA: 0x00416B1D File Offset: 0x00414D1D
 protected void MAHCPFOCOHK()
 {
     PhotonHandler.MBIFDLCKGKN = true;
     PhotonHandler.NMCMGIBJMIF();
     PhotonNetwork.Disconnect();
 }
 // Token: 0x0600B252 RID: 45650 RVA: 0x00416856 File Offset: 0x00414A56
 protected void LCKEHMMIFEI()
 {
     PhotonHandler.NMCMGIBJMIF();
 }
 // Token: 0x0600B250 RID: 45648 RVA: 0x00416691 File Offset: 0x00414891
 protected void PDNMKEKIGJH()
 {
     PhotonHandler.MBIFDLCKGKN = true;
     PhotonHandler.StopFallbackSendAckThread();
     PhotonNetwork.Disconnect();
 }
 // Token: 0x0600B24C RID: 45644 RVA: 0x00416856 File Offset: 0x00414A56
 protected void OJIHBHNJFBB()
 {
     PhotonHandler.NMCMGIBJMIF();
 }
 // Token: 0x0600B24A RID: 45642 RVA: 0x00416856 File Offset: 0x00414A56
 protected void PEJANHIKFAE()
 {
     PhotonHandler.NMCMGIBJMIF();
 }
 // Token: 0x0600B246 RID: 45638 RVA: 0x004167F7 File Offset: 0x004149F7
 protected void KHDPHGCGNHH()
 {
     PhotonHandler.HIGFHHADAKA();
 }
 // Token: 0x0600B26D RID: 45677 RVA: 0x0041702C File Offset: 0x0041522C
 protected void MFKCAFGHNNB()
 {
     PhotonHandler.MBIFDLCKGKN = false;
     PhotonHandler.FOKEFGDCAGK();
     PhotonNetwork.Disconnect();
 }
Exemple #16
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))
        {
            PhotonNetwork.LeaveRoom();
        }
        if (Input.GetKeyUp(KeyCode.C))
        {
            PhotonNetwork.ConnectUsingSettings(null);
            PhotonHandler.StopFallbackSendAckThread();
        }


        if (!PhotonNetwork.inRoom)
        {
            return;
        }

        // 重新連線的UI
        if (PhotonNetwork.connected && this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(false);
        }
        if (!PhotonNetwork.connected && !PhotonNetwork.connecting && !this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(true);
        }

        //如果房間人數大於1,回傳當前回合以及時間
        if (PhotonNetwork.room.PlayerCount > 1)
        {
            if (this.turnManager.IsOver)
            {
                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,預設為None
        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 = PhotonNetwork.room.PlayerCount > 1;

            if (PhotonNetwork.room.PlayerCount < 2)//如果房間人數少於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 = PhotonNetwork.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);
            }
        }
    }
 public void OnClickReConnectAndRejoin()
 {
     PhotonNetwork.ReconnectAndRejoin();
     PhotonHandler.StopFallbackSendAckThread();  // this is used in the demo to timeout in background!
 }
 // Token: 0x0600B25E RID: 45662 RVA: 0x00416856 File Offset: 0x00414A56
 protected void AAPKEGAJABJ()
 {
     PhotonHandler.NMCMGIBJMIF();
 }
Exemple #19
0
 /// <summary>Called by Unity when the play mode ends. Used to cleanup.</summary>
 protected void OnDestroy()
 {
     //Debug.Log("OnDestroy on PhotonHandler.");
     PhotonHandler.StopFallbackSendAckThread();
     //PhotonNetwork.Disconnect();
 }
Exemple #20
0
    public void Update()
    {
        // for debugging, it's useful to have a few actions tied to keys:
        if (Input.GetKeyUp(KeyCode.L))
        {
            PhotonNetwork.LeaveRoom();
        }
        if (Input.GetKeyUp(KeyCode.C))
        {
            PhotonNetwork.ConnectUsingSettings(null);
            PhotonHandler.StopFallbackSendAckThread();
        }

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

        if (PhotonNetwork.inRoom)
        {
            if (this.TurnText != null)
            {
                this.TurnText.text = this.turnManager.Turn.ToString();
            }
            if (this.turnManager.Turn > 0 && this.TimeText != null)
            {
                float turnEnd = this.turnManager.GetRemainingSeconds();
                this.TimeText.text = turnEnd.ToString("F1") + " SECONDS";
            }
            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
            {
                if (PhotonNetwork.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 = PhotonNetwork.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);
                }
            }
        }
    }
Exemple #21
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))
        {
            PhotonNetwork.LeaveRoom();
        }
        if (Input.GetKeyUp(KeyCode.C))
        {
            PhotonNetwork.ConnectUsingSettings(null);  //подключаемся
            PhotonHandler.StopFallbackSendAckThread(); // заморозил соединение
        }


        if (!PhotonNetwork.inRoom)
        {
            return;
        }

        // disable the "reconnect panel" if PUN is connected or connecting
        if (PhotonNetwork.connected && this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(false);             // завершен поворот?
        }
        if (!PhotonNetwork.connected && !PhotonNetwork.connecting && !this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(true);
        }


        if (PhotonNetwork.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 = PhotonNetwork.room.PlayerCount > 1;

            if (PhotonNetwork.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 = PhotonNetwork.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);
            }
        }
    }
Exemple #22
0
 /// <summary>
 /// 连接
 /// </summary>
 public void OnClickConnect()
 {
     PhotonNetwork.ConnectUsingSettings(null);
     PhotonHandler.StopFallbackSendAckThread();          // 这在案例中被用于后台超时!
 }
Exemple #23
0
    public void Update()
    {
        // 检查我们是否脱离了环境.
        if (this.DisconnectedPanel == null)
        {
            Destroy(this.gameObject);
        }

        // 为了方便调试, 弄一些快捷键是很有用的:
        if (Input.GetKeyUp(KeyCode.L))          //L键离开房间
        {
            PhotonNetwork.LeaveRoom();
        }
        if (Input.GetKeyUp(KeyCode.C))         //C键连接
        {
            PhotonNetwork.ConnectUsingSettings(null);
            PhotonHandler.StopFallbackSendAckThread();
        }


        if (!PhotonNetwork.inRoom)              //不在房间则退出
        {
            return;
        }

        // 如果PUN已连接或正在连接则禁用"reconnect panel"(重连面板)
        if (PhotonNetwork.connected && this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(false);
        }
        if (!PhotonNetwork.connected && !PhotonNetwork.connecting && !this.DisconnectedPanel.gameObject.GetActive())
        {
            this.DisconnectedPanel.gameObject.SetActive(true);
        }


        if (PhotonNetwork.room.PlayerCount > 1)
        {
            if (this.turnManager.IsOver)
            {
                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") + " 秒";                     //更新回合剩余时间

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

        this.UpdatePlayerTexts();               //更新玩家文本信息



        // 远程玩家的选择只在回合结束时(双方都完成回合)展示
        if (this.turnManager.IsCompletedByAll)
        {
        }
        else
        {
            ButtonCanvasGroup.interactable = PhotonNetwork.room.PlayerCount > 1;                //玩家数量大于1才可以触发按钮

            if (PhotonNetwork.room.PlayerCount < 2)
            {
            }

            // 如果所有玩家都没有完成该回合,我们为远程玩家的手势使用一个随机图片
            else if (this.turnManager.Turn > 0 && !this.turnManager.IsCompletedByAll)
            {
                // 远程玩家手势图片的阿尔法值(透明度)被用于表明远程玩家是否“活跃”以及“完成回合”
                PhotonPlayer remote = PhotonNetwork.player.GetNext();
                float        alpha  = 0.5f;
                if (this.turnManager.GetPlayerFinishedTurn(remote))
                {
                    alpha = 1;                          //完成回合为1
                }
                if (remote != null && remote.IsInactive)
                {
                    alpha = 0.1f;
                }
            }
        }
    }
Exemple #24
0
    IEnumerator Connect()
    {
        //  serverAddress = serverAddress2;
        tableRead.strInfo = StaticLoc.Loc.Get("meg0101");
        Ping ping    = new Ping(serverAddress.Split(':')[0]);
        Ping ping2   = new Ping(serverAddress2.Split(':')[0]);
        int  timeOut = 0;

        int p1 = 0;
        int p2 = 0;

        while (true)
        {
            if (ping.isDone || ping2.isDone)
            {
                break;
            }
            if (timeOut > 30)
            {
                break;
            }

            timeOut++;
            Debug.Log(string.Format("---------------------Ping:{0},{1};Ping2:{2},{3}", ping.isDone, ping.time, ping2.isDone, ping2.time));
            yield return(new WaitForSeconds(0.1f));
        }
        p1 = ping.time;
        p2 = ping2.time;
        Debug.Log(string.Format("---------------------PingEnd:{0},{1};Ping2:{2},{3}", ping.isDone, p1, ping2.isDone, p2));
        if (p1 == -1 && p2 == -1)
        {
            tableRead.strInfo = StaticLoc.Loc.Get("meg0096");
            //ShowConnectFail(StaticLoc.Loc.Get("meg0096")+StaticLoc.Loc.Get("meg0103"));

            tableRead.ReadTimeOut(StaticLoc.Loc.Get("meg0096") + StaticLoc.Loc.Get("meg0103"));
        }
        else if (p2 != -1 && p1 != -1)
        {
            if (p1 > p2)
            {
                serverAddress = serverAddress2;
            }
        }
        else if (p2 != -1)
        {
            serverAddress = serverAddress2;
        }

        ping.DestroyPing();
        ping2.DestroyPing();

        Debug.Log("===============ConnectIP:" + serverAddress);
        tableRead.strInfo = StaticLoc.Loc.Get("meg0095");
        //NGUIDebug.Log ("--------------------------RadyConnect");
        yuan.YuanClass.SwitchList(listBtnServer, false, true);
//		if(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
//		{
//
//          //YuanUnityPhoton.GetYuanUnityPhotonInstantiate().peer.Disconnect();
//			ZealmConnector.closeConnection();
//			while(YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
//			{
//				yield return new WaitForSeconds(0.1f);
//			}
//		}
//
//			if(InRoom.GetInRoomInstantiate ().ServerConnected)
//			{
//		        //InRoom.GetInRoomInstantiate().peer.Disconnect();
//			ZealmConnector.closeConnection();
//				while(InRoom.GetInRoomInstantiate ().ServerConnected)
//				{
//					yield return new WaitForSeconds(0.1f);
//				}
//			}

        ZealmConnector.closeConnection();
        //try
        //{
        //NGUIDebug.Log ("-------------------------------IP:"+serverAddress);
        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = serverAddress;
//	        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "117.131.207.219" + ":5059";
//        YuanUnityPhoton.NewYuanUnityPhotonInstantiate().ServerAddress = "192.168.1.100" + ":5059";
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerApplication = "YuanPhotonServerRoom";
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().MMManage          = this.mmManage;
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().tableRead         = this.tableRead;
        //NGUIDebug.Log ("--------------------------StratConnect");

        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().Connect();
        PhotonHandler.ShowLog("SetConnectionIP:" + serverAddress);
        PlayerPrefs.SetString("ConnectionIP", serverAddress);
        while (!YuanUnityPhoton.GetYuanUnityPhotonInstantiate().ServerConnected)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        //NGUIDebug.Log ("--------------------------Connected");
        if (StartGame)
        {
            StartGame = false;
            YuanUnityPhoton.GetYuanUnityPhotonInstantiate().SetPlayerBehavior(yuan.YuanPhoton.ConsumptionType.GameSchedule, ((int)GameScheduleType.OpenGame).ToString(), SystemInfo.deviceUniqueIdentifier);
        }
//			Debug.Log("Con2222222");
        //}
        //catch(System.Exception ex)
        //{
        //Debug.LogError (ex.ToString ());
        //}

/**************************************************
 *      //	if(InRoom.GetInRoomInstantiate ().peer.PeerState==ExitGames.Client.Photon.PeerStateValue.Connected)
 *      //	{
 *  //      InRoom.GetInRoomInstantiate().peer.Disconnect();
 *      //		while(InRoom.GetInRoomInstantiate ().peer.PeerState!=ExitGames.Client.Photon.PeerStateValue.Disconnected)
 *      //		{
 *      //			yield return new WaitForSeconds(0.1f);
 *      //		}
 *      //	}
 *******************************************************/
        try
        {
            InRoom.NewInRoomInstantiate();
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
        PhotonNetwork.Disconnect();
    }
Exemple #25
0
    /// <summary>
    /// Static constructor used for basic setup.
    /// </summary>
    static PhotonNetwork()
    {
        #if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying || !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
        {
            return;
        }

        // This can happen when you recompile a script IN play made
        // This helps to surpress some errors, but will not fix breaking
        bool doubleInstall = false;
        GameObject pGO = GameObject.Find("PhotonMono");
        doubleInstall = pGO != null;
        if (doubleInstall)
        {
            GameObject.Destroy(pGO);
            Debug.LogWarning("The Unity recompile forced a restart of UnityPhoton!");
        }

        #endif
        Application.runInBackground = true;

        // Set up a MonoBheaviour to run Photon, and hide it.
        GameObject photonGO = new GameObject();
        photonMono = (PhotonHandler)photonGO.AddComponent<PhotonHandler>();
        photonGO.name = "PhotonMono";
        photonGO.hideFlags = UnityEngine.HideFlags.HideInHierarchy;

        // Set up the NetworkingPeer
        networkingPeer = new NetworkingPeer(photonMono, string.Empty, ExitGames.Client.Photon.ConnectionProtocol.Udp);
        networkingPeer.LimitOfUnreliableCommands = 20;

        // Local player
        CustomTypes.Register();
    }
        void Update()
        {
            if (Input.GetKeyUp(KeyCode.A))
            {
                _room.LeaveRoom();
            }

            if (Input.GetKeyUp(KeyCode.S))
            {
                _room.ConnectUsingSettings("0");
                PhotonHandler.StopFallbackSendAckThread();
            }

            if (!_room.InRoom)
            {
                return;
            }

            if (_room.Connected && _reconnectParent.gameObject.GetActive())
            {
                _reconnectParent.gameObject.SetActive(false);
            }

            if (!_room.Connected && !_room.Connecting && !_reconnectParent.gameObject.GetActive())
            {
                _reconnectParent.gameObject.SetActive(true);
            }

            if (_room.CurrentRoom.PlayerCount > 1)
            {
                if (_room.TurnIsOver)
                {
                    return;
                }

                if (_turnText != null)
                {
                    _turnText.text = _room.Turn.ToString();
                }

                if (_room.Turn > 0 && _timeText != null && !_isShowingResults)
                {
                    _timeText.text = _room.RemainingSecondsInTurn.ToString("F1") + " SECONDS";

                    _timerFillImage.anchorMax = new Vector2(1f - _room.RemainingSecondsInTurn / _room.TurnDuration, 1f);
                }
            }

            UpdatePlayerTexts();

            Sprite selected = SelectionToSprite(_localSelection);

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

            if (_room.IsCompletedByAll)
            {
                selected = SelectionToSprite(_remoteSelection);
                if (selected != null)
                {
                    _remoteSelectionImage.color  = new Color(1, 1, 1, 1);
                    _remoteSelectionImage.sprite = selected;
                }
            }
            else
            {
                EnableButtons(_room.CurrentRoom.PlayerCount > 1);

                if (_room.CurrentRoom.PlayerCount < 2)
                {
                    _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 (_room.Turn > 0 && !_room.IsCompletedByAll)
                {
                    // alpha of the remote hand is used as indicator if the remote player "is active" and "made a turn"
                    PhotonPlayer remote = _room.LocalPlayer.GetNext();
                    float        alpha  = 0.5f;
                    if (_room.IsPlayerTurnFinished(remote))
                    {
                        alpha = 1;
                    }

                    if (remote != null && remote.IsInactive)
                    {
                        alpha = 0.1f;
                    }

                    _remoteSelectionImage.color  = new Color(1, 1, 1, alpha);
                    _remoteSelectionImage.sprite = SelectionToSprite(_randomHand);
                }
            }
        }
Exemple #27
0
    /// <summary>
    /// Static constructor used for basic setup.
    /// </summary>
    static PhotonNetwork()
    {
        #if UNITY_EDITOR
        if (PhotonServerSettings == null)
        {
            // create PhotonServerSettings
            CreateSettings();
        }

        if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
        {
            //Debug.Log(string.Format("PhotonNetwork.ctor() Not playing {0} {1}", UnityEditor.EditorApplication.isPlaying, UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode));
            return;
        }

        // This can happen when you recompile a script IN play made
        // This helps to surpress some errors, but will not fix breaking
        PhotonHandler[] photonHandlers = GameObject.FindObjectsOfType(typeof(PhotonHandler)) as PhotonHandler[];
        if (photonHandlers != null && photonHandlers.Length > 0)
        {
            Debug.LogWarning("Unity recompiled. Connection gets closed and replaced. You can connect as 'new' client.");
            foreach (PhotonHandler photonHandler in photonHandlers)
            {
                //Debug.Log("Handler: " + photonHandler + " photonHandler.gameObject: " + photonHandler.gameObject);
                photonHandler.gameObject.hideFlags = 0;
                GameObject.DestroyImmediate(photonHandler.gameObject);
                Component.DestroyImmediate(photonHandler);
            }
        }
        #endif

        Application.runInBackground = true;

        // Set up a MonoBehaviour to run Photon, and hide it
        GameObject photonGO = new GameObject();
        photonMono = (PhotonHandler)photonGO.AddComponent<PhotonHandler>();
        photonGO.name = "PhotonMono";
        photonGO.hideFlags = HideFlags.HideInHierarchy;

        // Set up the NetworkingPeer and use protocol of PhotonServerSettings
        ConnectionProtocol protocol = PhotonNetwork.PhotonServerSettings.Protocol;
        networkingPeer = new NetworkingPeer(string.Empty, protocol);
        networkingPeer.QuickResendAttempts = 2;
        networkingPeer.SentCountAllowance = 7;

        #if UNITY_XBOXONE
        Debug.Log("UNITY_XBOXONE is defined: Using AuthMode 'AuthOnceWss' and EncryptionMode 'DatagramEncryption'.");
        if (!PhotonPeer.NativeDatagramEncrypt)
        {
            Debug.LogError("XB1 builds need a Photon3Unity3d.dll which uses the native PhotonEncryptorPlugin. This dll does not!");
        }

        networkingPeer.AuthMode = AuthModeOption.AuthOnceWss;
        networkingPeer.EncryptionMode = EncryptionMode.DatagramEncryption;
        #endif

        if (UsePreciseTimer)
        {
            Debug.Log("Using Stopwatch as precision timer for PUN.");
            startupStopwatch = new Stopwatch();
            startupStopwatch.Start();
            networkingPeer.LocalMsTimestampDelegate = () => (int)startupStopwatch.ElapsedMilliseconds;
        }

        // Local player
        CustomTypes.Register();
    }
    protected void Awake()
    {
//		Debug.Log ("----------------"+pathXML);
        XmlDocument doc = new XmlDocument();

        if (!File.Exists(pathXML))
        {
            XmlElement rootElement = doc.CreateElement("YuanXml");
            doc.AppendChild(rootElement);
            doc.Save(pathXML);
        }
        else
        {
            doc.Load(pathXML);
        }


        XmlNode root = doc.SelectSingleNode("YuanXml");
        //XmlNode xn=root.SelectSingleNode ("SendTimes");
        XmlNode xn;

        GetXMLNode(doc, root, out xn, "SendTimes", "0.1");
        sendTimes = float.Parse(xn.InnerText);
        BtnGameManager.rpcSendTime = sendTimes;
        //xn=root.SelectSingleNode ("StremUp");
        GetXMLNode(doc, root, out xn, "StremUp", "yes");
        if (xn.InnerText == "yes")
        {
            isStremUp = true;
        }
        else if (xn.InnerText == "no")
        {
            isStremUp = false;
        }
        //xn=root.SelectSingleNode ("RPCUp");
        GetXMLNode(doc, root, out xn, "RPCUp", "yes");
        if (xn.InnerText == "yes")
        {
            isRPCUp = true;
        }
        else if (xn.InnerText == "no")
        {
            isRPCUp = false;
        }
        //xn=root.SelectSingleNode ("RomMaxPlayerNum");
        GetXMLNode(doc, root, out xn, "RomMaxPlayerNum", "25");
        BtnGameManager.roomPlayerNum = int.Parse(xn.InnerText);

        GetXMLNode(doc, root, out xn, "PublicSkillCD", "1");
        BtnGameManager.numPubSkillCD = int.Parse(xn.InnerText);

        GetXMLNode(doc, root, out xn, "SeviceMianCity", "0.33");

        BtnGameManager.numSeviceMianCity = float.Parse(xn.InnerText);

        GetXMLNode(doc, root, out xn, "SeviceDuplicate", "0.2");
        BtnGameManager.numSeviceDuplicate = float.Parse(xn.InnerText);

        GetXMLNode(doc, root, out xn, "SevicePVP", "0.1");
        BtnGameManager.numSevicePVP = float.Parse(xn.InnerText);

        GetXMLNode(doc, root, out xn, "johnSendTimes", "333");
        johnSendTimes = int.Parse(xn.InnerText);



        doc.Save(pathXML);

//		Debug.Log ("---------------------isRPCUp:"+isRPCUp);
        if (SP != null && SP != this && SP.gameObject != null)
        {
            GameObject.DestroyImmediate(SP.gameObject);
        }

        SP = this;
        DontDestroyOnLoad(this.gameObject);

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

        PhotonHandler.StartFallbackSendAckThread();
    }
Exemple #29
0
    /// <summary>
    /// Static constructor used for basic setup.
    /// </summary>
    static PhotonNetwork()
    {
        #if UNITY_EDITOR

        if (PhotonServerSettings == null)
        {
            // create pss
            CreateSettings();
        }

        if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
        {
            //Debug.Log(string.Format("PhotonNetwork.ctor() Not playing {0} {1}", UnityEditor.EditorApplication.isPlaying, UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode));
            return;
        }

        // This can happen when you recompile a script IN play made
        // This helps to surpress some errors, but will not fix breaking
        PhotonHandler[] photonHandlers = GameObject.FindObjectsOfType(typeof(PhotonHandler)) as PhotonHandler[];
        if (photonHandlers != null && photonHandlers.Length > 0)
        {
            Debug.LogWarning("Unity recompiled. Connection gets closed and replaced. You can connect as 'new' client.");
            foreach (PhotonHandler photonHandler in photonHandlers)
            {
                //Debug.Log("Handler: " + photonHandler + " photonHandler.gameObject: " + photonHandler.gameObject);
                photonHandler.gameObject.hideFlags = 0;
                GameObject.DestroyImmediate(photonHandler.gameObject);
                Component.DestroyImmediate(photonHandler);
            }
        }
        #endif

        Application.runInBackground = true;

        // Set up a MonoBehaviour to run Photon, and hide it
        GameObject photonGO = new GameObject();
        photonMono = (PhotonHandler)photonGO.AddComponent<PhotonHandler>();
        photonGO.name = "PhotonMono";
        photonGO.hideFlags = HideFlags.HideInHierarchy;

        // Set up the NetworkingPeer and use protocol of PhotonServerSettings
        ConnectionProtocol protocol = PhotonNetwork.PhotonServerSettings.Protocol;
        #if UNITY_WEBGL
        if (protocol != ConnectionProtocol.WebSocket && protocol != ConnectionProtocol.WebSocketSecure) {
            Debug.Log("WebGL only supports WebSocket protocol. Overriding PhotonServerSettings.");
            protocol = ConnectionProtocol.WebSocketSecure;
        }
        #endif
        networkingPeer = new NetworkingPeer(photonMono, string.Empty, protocol);

        // Local player
        CustomTypes.Register();
    }
 // Token: 0x0600B26A RID: 45674 RVA: 0x00415FAC File Offset: 0x004141AC
 protected void PINGNFLJAGB()
 {
     PhotonHandler.StopFallbackSendAckThread();
 }