Inheritance: LoadbalancingPeer, IPhotonPeerListener
Exemplo n.º 1
0
    /// <summary>
    /// Updates the current room's Custom Properties with new/updated key-values.
    /// </summary>
    /// <remarks>
    /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room.
    /// They can relate to the room or individual players and are useful when only the current value
    /// of something is of interest. For example: The map of a room.
    /// All keys must be strings.
    ///
    /// The Room and the PhotonPlayer class both have SetCustomProperties methods.
    /// Also, both classes offer access to current key-values by: customProperties.
    ///
    /// Always use SetCustomProperties to change values.
    /// To reduce network traffic, set only values that actually changed.
    /// New properties are added, existing values are updated.
    /// Other values will not be changed, so only provide values that changed or are new.
    ///
    /// To delete a named (custom) property of this room, use null as value.
    ///
    /// Locally, SetCustomProperties will update it's cache without delay.
    /// Other clients are updated through Photon (the server) with a fitting operation.
    ///
    /// <b>Check and Swap</b>
    ///
    /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS):
    /// Values only get updated if the expected values are correct.
    /// The expectedValues can be different key/values than the propertiesToSet. So you can
    /// check some key and set another key's value (if the check succeeds).
    ///
    /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS.
    /// This can be useful to keep players from concurrently setting values. For example: If all players
    /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties
    /// gets executed server-side and any other (sent at the same time) fails.
    ///
    /// The server will broadcast successfully changed values and the local "cache" of customProperties
    /// only gets updated after a roundtrip (if anything changed).
    ///
    /// You can do a "webForward": Photon will send the changed properties to a WebHook defined
    /// for your application.
    ///
    /// <b>OfflineMode</b>
    ///
    /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored.
    /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip).
    /// </remarks>
    /// <param name="propertiesToSet">The new properties to be set. </param>
    /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param>
    /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param>
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false)
    {
        if (propertiesToSet == null)
        {
            return;
        }

        Hashtable customProps        = propertiesToSet.StripToStringKeys() as Hashtable;
        Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable;


        // no expected values -> set and callback
        bool noCas = customPropsToCheck == null || customPropsToCheck.Count == 0;

        if (PhotonNetworkManager.offlineMode || noCas)
        {
            this.CustomProperties.Merge(customProps);   // the customProps are already stripped to string-keys-only (custom-props keys)
            this.CustomProperties.StripKeysWithNullValues();
        }

        if (!PhotonNetworkManager.offlineMode)
        {
            PhotonNetworkManager.networkingPeer.OpSetPropertiesOfRoom(customProps, customPropsToCheck, webForward);    // as the customProps are stripped already, this equals OpSetCustomPropertiesOfRoom()
        }

        if (PhotonNetworkManager.offlineMode || noCas)
        {
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, customProps);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Updates the this player's Custom Properties with new/updated key-values.
    /// </summary>
    /// <remarks>
    /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room.
    /// They can relate to the room or individual players and are useful when only the current value
    /// of something is of interest. For example: The map of a room.
    /// All keys must be strings.
    ///
    /// The Room and the PhotonPlayer class both have SetCustomProperties methods.
    /// Also, both classes offer access to current key-values by: customProperties.
    ///
    /// Always use SetCustomProperties to change values.
    /// To reduce network traffic, set only values that actually changed.
    /// New properties are added, existing values are updated.
    /// Other values will not be changed, so only provide values that changed or are new.
    ///
    /// To delete a named (custom) property of this room, use null as value.
    ///
    /// Locally, SetCustomProperties will update it's cache without delay.
    /// Other clients are updated through Photon (the server) with a fitting operation.
    ///
    /// <b>Check and Swap</b>
    ///
    /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS):
    /// Values only get updated if the expected values are correct.
    /// The expectedValues can be different key/values than the propertiesToSet. So you can
    /// check some key and set another key's value (if the check succeeds).
    ///
    /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS.
    /// This can be useful to keep players from concurrently setting values. For example: If all players
    /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties
    /// gets executed server-side and any other (sent at the same time) fails.
    ///
    /// The server will broadcast successfully changed values and the local "cache" of customProperties
    /// only gets updated after a roundtrip (if anything changed).
    ///
    /// You can do a "webForward": Photon will send the changed properties to a WebHook defined
    /// for your application.
    ///
    /// <b>OfflineMode</b>
    ///
    /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored.
    /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip).
    /// </remarks>
    /// <param name="propertiesToSet">The new properties to be set. </param>
    /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param>
    /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param>
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false)
    {
        if (propertiesToSet == null)
        {
            return;
        }

        Hashtable customProps        = propertiesToSet.StripToStringKeys() as Hashtable;
        Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable;


        // no expected values -> set and callback
        bool noCas        = customPropsToCheck == null || customPropsToCheck.Count == 0;
        bool inOnlineRoom = this.actorID > 0 && !PhotonNetwork.offlineMode;


        if (inOnlineRoom)
        {
            PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, customProps, customPropsToCheck, webForward);
        }

        if (!inOnlineRoom || noCas)
        {
            this.InternalCacheProperties(customProps);
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, customProps);
        }
    }
Exemplo n.º 3
0
    protected internal void ExecuteComponentOnSerialize(Component component, PhotonStream stream, PhotonMessageInfo info)
    {
        IPunObservable observable = component as IPunObservable;

        if (observable != null)
        {
            observable.OnPhotonSerializeView(stream, info);
        }
        else if (component != null)
        {
            MethodInfo method = null;
            bool       found  = this.m_OnSerializeMethodInfos.TryGetValue(component, out method);
            if (!found)
            {
                bool foundMethod = NetworkingPeer.GetMethod(component as MonoBehaviour, PhotonNetworkingMessage.OnPhotonSerializeView.ToString(), out method);

                if (foundMethod == false)
                {
                    Debug.LogError("The observed monobehaviour (" + component.name + ") of this PhotonView does not implement OnPhotonSerializeView()!");
                    method = null;
                }

                this.m_OnSerializeMethodInfos.Add(component, method);
            }

            if (method != null)
            {
                method.Invoke(component, new object[] { stream, info });
            }
        }
    }
Exemplo n.º 4
0
 public static bool JoinRoom(string roomName)
 {
     if (offlineMode)
     {
         if (offlineModeRoom != null)
         {
             Debug.LogError("JoinRoom failed. In offline mode you still have to leave a room to enter another.");
             return(false);
         }
         offlineModeRoom = new Room(roomName, null);
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, new object[0]);
         return(true);
     }
     if ((networkingPeer.server != ServerConnection.MasterServer) || !connectedAndReady)
     {
         Debug.LogError("JoinRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
         return(false);
     }
     if (string.IsNullOrEmpty(roomName))
     {
         Debug.LogError("JoinRoom failed. A roomname is required. If you don't know one, how will you join?");
         return(false);
     }
     return(networkingPeer.OpJoinRoom(roomName, null, null, false));
 }
Exemplo n.º 5
0
 public static bool JoinRoom(string roomName, bool createIfNotExists)
 {
     if (((connectionStateDetailed == PeerStates.Joining) || (connectionStateDetailed == PeerStates.Joined)) || (connectionStateDetailed == PeerStates.ConnectedToGameserver))
     {
         Debug.LogError("JoinRoom aborted: You can only join a room while not currently connected/connecting to a room.");
     }
     else if (room != null)
     {
         Debug.LogError("JoinRoom aborted: You are already in a room!");
     }
     else if (roomName == string.Empty)
     {
         Debug.LogError("JoinRoom aborted: You must specifiy a room name!");
     }
     else
     {
         if (offlineMode)
         {
             offlineModeRoom = new Room(roomName, null);
             NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, new object[0]);
             return(true);
         }
         return(networkingPeer.OpJoinRoom(roomName, null, null, createIfNotExists));
     }
     return(false);
 }
Exemplo n.º 6
0
        private GameObject InstantiateLocally(string prefabName)
        {
            bool           connected      = PhotonNetwork.connectedAndReady;
            NetworkingPeer networkingPeer = PhotonNetwork.networkingPeer;

            // safeguard
            if (!connected)
            {
                Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Client should be in a room. Current connectionStateDetailed: " + PhotonNetwork.connectionStateDetailed);
                return(null);
            }

            // retrieve PUN object from cache
            GameObject prefabGo;

            if (!RetrieveFromPUNCache(prefabName, out prefabGo))
            {
                Debug.LogError("Failed to Instantiate prefab: " + prefabName + ".");
                return(null);
            }
#if UNITY_EDITOR
            GameObject go = UnityEditor.PrefabUtility.InstantiatePrefab(prefabGo) as GameObject;
#else
            GameObject go = GameObject.Instantiate(prefabGo);
#endif
            go.name = prefabGo.name;

            HandleLocalLogic(go);
            RegisterObjectCreation(go, prefabName);

            return(go);
        }
Exemplo n.º 7
0
    public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
                return(false);
            }
            offlineModeRoom = new Room("offline room", null);
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, new object[0]);
            return(true);
        }
        if ((networkingPeer.server != ServerConnection.MasterServer) || !connectedAndReady)
        {
            Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return(false);
        }
        Hashtable target = new Hashtable();

        target.MergeStringKeys(expectedCustomRoomProperties);
        if (expectedMaxPlayers > 0)
        {
            target[(byte)0xff] = expectedMaxPlayers;
        }
        return(networkingPeer.OpJoinRandomRoom(target, 0, null, matchingType, typedLobby, sqlLobbyFilter));
    }
Exemplo n.º 8
0
    // Token: 0x060004FA RID: 1274 RVA: 0x0001D884 File Offset: 0x0001BA84
    protected internal void ExecuteComponentOnSerialize(Component component, PhotonStream stream, PhotonMessageInfo info)
    {
        IPunObservable punObservable = component as IPunObservable;

        if (punObservable != null)
        {
            punObservable.OnPhotonSerializeView(stream, info);
            return;
        }
        if (component != null)
        {
            MethodInfo methodInfo = null;
            if (!this.m_OnSerializeMethodInfos.TryGetValue(component, out methodInfo))
            {
                if (!NetworkingPeer.GetMethod(component as UnityEngine.MonoBehaviour, PhotonNetworkingMessage.OnPhotonSerializeView.ToString(), out methodInfo))
                {
                    Debug.LogError("The observed monobehaviour (" + component.name + ") of this PhotonView does not implement OnPhotonSerializeView()!");
                    methodInfo = null;
                }
                this.m_OnSerializeMethodInfos.Add(component, methodInfo);
            }
            if (methodInfo != null)
            {
                methodInfo.Invoke(component, new object[]
                {
                    stream,
                    info
                });
            }
        }
    }
Exemplo n.º 9
0
    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.
        // TODO: Add parameter for custom(ers) client version (being v1.0 now)
        networkingPeer = new NetworkingPeer(photonMono, "Guest " + UnityEngine.Random.Range(1, 9999), "v1.0", ExitGames.Client.Photon.ConnectionProtocol.Udp);
        networkingPeer.LimitOfUnreliableCommands = 20;

        // Local player
        CustomTypes.Register();
    }
Exemplo n.º 10
0
    // Token: 0x06003DAC RID: 15788 RVA: 0x00136E5C File Offset: 0x0013525C
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false)
    {
        if (propertiesToSet == null)
        {
            return;
        }
        Hashtable hashtable  = propertiesToSet.StripToStringKeys();
        Hashtable hashtable2 = expectedValues.StripToStringKeys();
        bool      flag       = hashtable2 == null || hashtable2.Count == 0;
        bool      flag2      = this.actorID > 0 && !PhotonNetwork.offlineMode;

        if (flag)
        {
            this.CustomProperties.Merge(hashtable);
            this.CustomProperties.StripKeysWithNullValues();
        }
        if (flag2)
        {
            PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, hashtable, hashtable2, webForward);
        }
        if (!flag2 || flag)
        {
            this.InternalCacheProperties(hashtable);
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, new object[]
            {
                this,
                hashtable
            });
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Updates the current room's Custom Properties with new/updated key-values.
    /// </summary>
    /// <remarks>
    /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room.
    /// They can relate to the room or individual players and are useful when only the current value
    /// of something is of interest. For example: The map of a room.
    /// All keys must be strings.
    ///
    /// The Room and the PhotonPlayer class both have SetCustomProperties methods.
    /// Also, both classes offer access to current key-values by: customProperties.
    ///
    /// Always use SetCustomProperties to change values.
    /// To reduce network traffic, set only values that actually changed.
    /// New properties are added, existing values are updated.
    /// Other values will not be changed, so only provide values that changed or are new.
    ///
    /// To delete a named (custom) property of this room, use null as value.
    ///
    /// Locally, SetCustomProperties will update it's cache without delay.
    /// Other clients are updated through Photon (the server) with a fitting operation.
    ///
    /// <b>Check and Swap</b>
    ///
    /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS):
    /// Values only get updated if the expected values are correct.
    /// The expectedValues can be different key/values than the propertiesToSet. So you can
    /// check some key and set another key's value (if the check succeeds).
    ///
    /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS.
    /// This can be useful to keep players from concurrently setting values. For example: If all players
    /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties
    /// gets executed server-side and any other (sent at the same time) fails.
    ///
    /// The server will broadcast successfully changed values and the local "cache" of customProperties
    /// only gets updated after a roundtrip (if anything changed).
    ///
    /// You can do a "webForward": Photon will send the changed properties to a WebHook defined
    /// for your application.
    ///
    /// <b>OfflineMode</b>
    ///
    /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored.
    /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip).
    /// </remarks>
    /// <param name="propertiesToSet">The new properties to be set. </param>
    /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param>
    /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param>
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false)
    {
        if (propertiesToSet == null)
        {
            return;
        }

        Hashtable customProps        = propertiesToSet.StripToStringKeys() as Hashtable;
        Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable;


        // no expected values -> set and callback
        bool noCas = customPropsToCheck == null || customPropsToCheck.Count == 0;

        if (noCas)
        {
            this.CustomProperties.Merge(customProps);
            this.CustomProperties.StripKeysWithNullValues();
        }

        if (!PhotonNetwork.offlineMode)
        {
            PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, customPropsToCheck, webForward);
        }

        if (PhotonNetwork.offlineMode || noCas)
        {
            this.InternalCacheProperties(customProps);
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, customProps);
        }
    }
Exemplo n.º 12
0
    // Token: 0x06000524 RID: 1316 RVA: 0x0001E024 File Offset: 0x0001C224
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false)
    {
        if (propertiesToSet == null)
        {
            return;
        }
        Hashtable hashtable  = propertiesToSet.StripToStringKeys();
        Hashtable hashtable2 = expectedValues.StripToStringKeys();
        bool      flag       = hashtable2 == null || hashtable2.Count == 0;

        if (PhotonNetwork.offlineMode || flag)
        {
            base.CustomProperties.Merge(hashtable);
            base.CustomProperties.StripKeysWithNullValues();
        }
        if (!PhotonNetwork.offlineMode)
        {
            PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(hashtable, hashtable2, webForward);
        }
        if (PhotonNetwork.offlineMode || flag)
        {
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, new object[]
            {
                hashtable
            });
        }
    }
Exemplo n.º 13
0
        private void RaiseSyncSceneEventHandler(int otherPlayerID, bool forceSync)
        {
            if (PhotonNetwork.isMasterClient || forceSync)
            {
                List <GameObject> ASLObjectList = GrabAllASLObjects();

                NetworkingPeer peer = PhotonNetwork.networkingPeer;
                foreach (GameObject go in ASLObjectList)
                {
                    if (nonSyncItems.Contains(go))
                    {
                        continue;
                    }

                    ExitGames.Client.Photon.Hashtable syncSceneData = new ExitGames.Client.Photon.Hashtable();

                    syncSceneData[(byte)0] = otherPlayerID;

#if UNITY_EDITOR
                    string prefabName = UnityEditor.PrefabUtility.GetPrefabParent(go).name;
#else
                    //string prefabName = go.name;
                    string prefabName = ObjectInstantiationDatabase.GetPrefabName(go);
#endif
                    UnityEngine.Debug.Log("Prefab name = " + prefabName);
                    syncSceneData[(byte)1] = prefabName;

                    if (go.transform.position != Vector3.zero)
                    {
                        syncSceneData[(byte)2] = go.transform.position;
                    }

                    if (go.transform.rotation != Quaternion.identity)
                    {
                        syncSceneData[(byte)3] = go.transform.rotation;
                    }

                    int[] viewIDs = ExtractPhotonViewIDs(go);
                    syncSceneData[(byte)4] = viewIDs;

                    if (peer.currentLevelPrefix > 0)
                    {
                        syncSceneData[(byte)5] = peer.currentLevelPrefix;
                    }

                    syncSceneData[(byte)6] = PhotonNetwork.ServerTimestamp;
                    syncSceneData[(byte)7] = go.GetPhotonView().instantiationId;

                    //RaiseEventOptions options = new RaiseEventOptions();
                    //options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache;

                    //Debug.Log("All items packed. Attempting to literally raise event now.");

                    RaiseEventOptions options = new RaiseEventOptions();
                    options.Receivers = ReceiverGroup.Others;
                    PhotonNetwork.RaiseEvent(ASLEventCode.EV_SYNCSCENE, syncSceneData, true, options);
                }
            }
        }
Exemplo n.º 14
0
 public LoadingMapScreen() : base(nameof(LoadingMapScreen))
 {
     if (instance != null)
     {
         instance.DisableImmediate();
     }
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnLeftRoom, OnLeftRoom);
     instance = this;
 }
Exemplo n.º 15
0
 protected override void OnPanelEnable()
 {
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnJoinedLobby, OnJoinedLobby);
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnDisconnectedFromPhoton, OnDisconnectedFromPhoton);
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnReceivedRoomListUpdate, OnReceivedRoomListUpdate);
     connectNext = false;
     regions     = locale.GetArray("regions");
     TryConnect(NetworkSettings.PreferedRegion.Value);
     AnarchyManager.MainMenu.DisableImmediate();
 }
Exemplo n.º 16
0
    static PhotonNetwork()
    {
        Application.runInBackground = true;
        var obj2 = new GameObject();

        photonMono     = obj2.AddComponent <PhotonHandler>();
        obj2.name      = "PhotonMono";
        obj2.hideFlags = HideFlags.HideInHierarchy;
        networkingPeer = new NetworkingPeer(photonMono, String.Empty, Settings.ConnectionProtocolSettings == 0 ? ConnectionProtocol.Udp : Settings.ConnectionProtocolSettings == 1 ? ConnectionProtocol.Tcp : ConnectionProtocol.WebSocket);
        CustomTypes.Register();
    }
Exemplo n.º 17
0
    static PhotonNetwork()
    {
        Application.runInBackground = true;
        GameObject gameObject = new GameObject();

        photonMono           = gameObject.AddComponent <PhotonHandler>();
        gameObject.name      = "PhotonMono";
        gameObject.hideFlags = HideFlags.HideInHierarchy;
        networkingPeer       = new NetworkingPeer(photonMono, string.Empty, Anarchy.Network.NetworkSettings.ConnectProtocol);
        CustomTypes.Register();
    }
Exemplo n.º 18
0
    static PhotonNetwork()
    {
        Application.runInBackground = true;
        GameObject obj2 = new GameObject();

        photonMono     = obj2.AddComponent <PhotonHandler>();
        obj2.name      = "PhotonMono";
        obj2.hideFlags = HideFlags.HideInHierarchy;
        networkingPeer = new NetworkingPeer(photonMono, string.Empty, ConnectionProtocol.Udp);
        CustomTypes.Register();
    }
Exemplo n.º 19
0
 public static void SwitchToProtocol(ConnectionProtocol cp)
 {
     if (networkingPeer.UsedProtocol != cp)
     {
         try {
             networkingPeer.Disconnect();
             networkingPeer.StopThread();
         } catch {
         }
         networkingPeer = new NetworkingPeer(photonMono, string.Empty, cp);
         Debug.Log("Protocol switched to: " + cp);
     }
 }
Exemplo n.º 20
0
 public void SetCustomProperties(Hashtable propertiesToSet, bool broadcast = true)
 {
     if (propertiesToSet != null)
     {
         base.customProperties.MergeStringKeys(propertiesToSet);
         base.customProperties.StripKeysWithNullValues();
         Hashtable gameProperties = propertiesToSet.StripToStringKeys();
         if (!PhotonNetwork.offlineMode)
         {
             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(gameProperties, broadcast, 0);
         }
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet);
     }
 }
Exemplo n.º 21
0
        public static void CheckPlayersProperties(Hashtable hash, int targetActorNr, PhotonPlayer sender)
        {
            NetworkingPeer peer = PhotonNetwork.networkingPeer;

            if (peer == null || hash == null || hash.Count <= 0)
            {
                return;
            }
            if (targetActorNr > 0)
            {
                PhotonPlayer target = PhotonPlayer.Find(targetActorNr);
                if (target != null)
                {
                    Hashtable props = peer.GetActorPropertiesForActorNr(hash, targetActorNr);
                    if (target.IsLocal)
                    {
                        bool needSend = false;
                        if (sender == null || !sender.IsMasterClient)
                        {
                            if (props.ContainsKey(PhotonPlayerProperty.name))
                            {
                                string checkName = props[PhotonPlayerProperty.name] as string;
                                if (checkName == null || checkName != User.Name.Value)
                                {
                                    //TODO: Localize
                                    UI.Log.AddLineRaw($"{(sender == null ? "Someone" : $"[{sender.ID}]" + sender.UIName.ToHTMLFormat())} tried to change your name.");
                                    props[PhotonPlayerProperty.name] = User.Name.Value;
                                    needSend = true;
                                }
                            }
                            if (props.ContainsKey(PhotonPlayerProperty.guildName))
                            {
                                string checkName = props[PhotonPlayerProperty.guildName] as string;
                                if (checkName == null || checkName != User.AllGuildNames)
                                {
                                    //TODO: Localize
                                    UI.Log.AddLineRaw($"{(sender == null ? "Someone" : $"[{sender.ID}]" + sender.UIName.ToHTMLFormat())} tried to change your guildname.");
                                    props[PhotonPlayerProperty.guildName] = User.AllGuildNames;
                                    needSend = true;
                                }
                            }
                        }
                        if (needSend)
                        {
                            target.SetCustomProperties(props);
                        }
                    }
                    target.InternalCacheProperties(props);
                    NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, new object[] { target, props });
                }
Exemplo n.º 22
0
 public static bool LeaveRoom()
 {
     if (offlineMode)
     {
         offlineModeRoom = null;
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom, new object[0]);
         return(true);
     }
     if (room == null)
     {
         Debug.LogWarning("PhotonNetwork.room is null. You don't have to call LeaveRoom() when you're not in one. State: " + connectionStatesDetailed);
     }
     return(networkingPeer.OpLeave());
 }
Exemplo n.º 23
0
 protected void Awake()
 {
     if (PhotonHandler.SP != null && PhotonHandler.SP != this && PhotonHandler.SP.gameObject != null)
     {
         UnityEngine.Object.DestroyImmediate(PhotonHandler.SP.gameObject);
     }
     PhotonHandler.SP = this;
     UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
     this.updateInterval            = 1000 / PhotonNetwork.sendRate;
     this.updateIntervalOnSerialize = 1000 / PhotonNetwork.sendRateOnSerialize;
     PhotonHandler.StartFallbackSendAckThread();
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnCreatedRoom, OnCreatedRoom);
     NetworkingPeer.RegisterEvent(PhotonNetworkingMessage.OnJoinedRoom, OnJoinedRoom);
 }
Exemplo n.º 24
0
        private void RaiseInstantiateEventHandler(GameObject go)
        {
            //Debug.Log("Attempting to raise event for instantiation");

            NetworkingPeer peer = PhotonNetwork.networkingPeer;

            byte[] content = new byte[2];
            ExitGames.Client.Photon.Hashtable instantiateEvent = new ExitGames.Client.Photon.Hashtable();
#if UNITY_EDITOR
            string prefabName = UnityEditor.PrefabUtility.GetPrefabParent(go).name;
#else
            //string prefabName = go.name;
            string prefabName = ObjectInstantiationDatabase.GetPrefabName(go);
#endif
            instantiateEvent[(byte)0] = prefabName;

            if (go.transform.position != Vector3.zero)
            {
                instantiateEvent[(byte)1] = go.transform.position;
            }

            if (go.transform.rotation != Quaternion.identity)
            {
                instantiateEvent[(byte)2] = go.transform.rotation;
            }

            instantiateEvent[(byte)3] = go.transform.localScale;

            int[] viewIDs = ExtractPhotonViewIDs(go);
            instantiateEvent[(byte)4] = viewIDs;

            if (peer.currentLevelPrefix > 0)
            {
                instantiateEvent[(byte)5] = peer.currentLevelPrefix;
            }

            instantiateEvent[(byte)6] = PhotonNetwork.ServerTimestamp;
            instantiateEvent[(byte)7] = go.GetPhotonView().instantiationId;

            //RaiseEventOptions options = new RaiseEventOptions();
            //options.CachingOption = (isGlobalObject) ? EventCaching.AddToRoomCacheGlobal : EventCaching.AddToRoomCache;

            //Debug.Log("All items packed. Attempting to literally raise event now.");

            RaiseEventOptions options = new RaiseEventOptions();
            options.Receivers = ReceiverGroup.Others;
            PhotonNetwork.RaiseEvent(ASLEventCode.EV_INSTANTIATE, instantiateEvent, true, options);

            //peer.OpRaiseEvent(EV_INSTANTIATE, instantiateEvent, true, null);
        }
Exemplo n.º 25
0
 public void SetCustomProperties(Hashtable propertiesToSet, bool broadcast = true)
 {
     if (propertiesToSet != null)
     {
         customProperties.MergeStringKeys(propertiesToSet);
         customProperties.StripKeysWithNullValues();
         Hashtable actorProperties = propertiesToSet.StripToStringKeys();
         if (Id > 0 && !PhotonNetwork.offlineMode)
         {
             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(Id, actorProperties, broadcast, 0);
         }
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet);
     }
 }
Exemplo n.º 26
0
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues)
    {
        if (propertiesToSet == null)
        {
            return;
        }

        if (!PhotonNetwork.offlineMode)
        {
            Hashtable customProps        = propertiesToSet.StripToStringKeys() as Hashtable;
            Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable;
            PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, false, 0, customPropsToCheck);  // broadcast is always on for CAS
        }
        NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet);
    }
Exemplo n.º 27
0
 public void SetCustomProperties(Hashtable propertiesToSet)
 {
     if (propertiesToSet != null)
     {
         base.customProperties.MergeStringKeys(propertiesToSet);
         base.customProperties.StripKeysWithNullValues();
         Hashtable gameProperties = propertiesToSet.StripToStringKeys();
         if (!PhotonNetwork.offlineMode)
         {
             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(gameProperties, true, 0);
         }
         object[] parameters = new object[] { propertiesToSet };
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, parameters);
     }
 }
Exemplo n.º 28
0
 public void SetCustomProperties(Hashtable propertiesToSet)
 {
     if (propertiesToSet != null)
     {
         customProperties.MergeStringKeys(propertiesToSet);
         customProperties.StripKeysWithNullValues();
         Hashtable actorProperties = propertiesToSet.StripToStringKeys();
         if (actorID > 0)
         {
             PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(actorID, actorProperties, true, 0);
         }
         object[] parameters = new object[] { this, propertiesToSet };
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, parameters);
     }
 }
Exemplo n.º 29
0
    public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues)
    {
        if (propertiesToSet == null)
        {
            return;
        }

        if (this.actorID > 0 && !PhotonNetwork.offlineMode)
        {
            Hashtable customProps        = propertiesToSet.StripToStringKeys() as Hashtable;
            Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable;
            PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, customProps, false, 0, customPropsToCheck);
        }
        NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet);
    }
Exemplo n.º 30
0
 protected internal void ExecuteOnSerialize(PhotonStream pStream, PhotonMessageInfo info)
 {
     if (!this.failedToFindOnSerialize)
     {
         if ((this.OnSerializeMethodInfo == null) && !NetworkingPeer.GetMethod(this.observed as UnityEngine.MonoBehaviour, PhotonNetworkingMessage.OnPhotonSerializeView.ToString(), out this.OnSerializeMethodInfo))
         {
             Debug.LogError("The observed monobehaviour (" + this.observed.name + ") of this PhotonView does not implement OnPhotonSerializeView()!");
             this.failedToFindOnSerialize = true;
         }
         else
         {
             object[] parameters = new object[] { pStream, info };
             this.OnSerializeMethodInfo.Invoke(this.observed, parameters);
         }
     }
 }
Exemplo n.º 31
0
    /// <summary>
    /// While offline, the network protocol can be switched (which affects the ports you can use to connect).
    /// </summary>
    /// <remarks>
    /// When you switch the protocol, make sure to also switch the port for the master server. Default ports are:
    /// TCP: 4530
    /// UDP: 5055
    ///
    /// This could look like this:<br/>
    /// Connect(serverAddress, <udpport|tcpport>, appID, gameVersion)
    ///
    /// Or when you use ConnectUsingSettings(), the PORT in the settings can be switched like so:<br/>
    /// PhotonNetwork.PhotonServerSettings.ServerPort = 4530;
    ///
    /// The current protocol can be read this way:<br/>
    /// PhotonNetwork.networkingPeer.UsedProtocol
    ///
    /// This does not work with the native socket plugin of PUN+ on mobile!
    /// </remarks>
    /// <param name="cp">Network protocol to use as low level connection. UDP is default. TCP is not available on all platforms (see remarks).</param>
    public static void SwitchToProtocol(ConnectionProtocol cp)
    {
        #if UNITY_WEBGL
        if (cp != ConnectionProtocol.WebSocket && cp != ConnectionProtocol.WebSocketSecure) {
            Debug.Log("WebGL only supports WebSocket protocol. Overriding PhotonServerSettings.");
            cp = ConnectionProtocol.WebSocketSecure;
        }
        #endif

        if (networkingPeer.UsedProtocol == cp)
        {
            return;
        }
        try
        {
            networkingPeer.Disconnect();
            networkingPeer.StopThread();
        }
        catch
        {

        }

        // set up a new NetworkingPeer
        NetworkingPeer newPeer = new NetworkingPeer(photonMono, String.Empty, cp);
        newPeer.mAppVersion = networkingPeer.mAppVersion;
        newPeer.CustomAuthenticationValues = networkingPeer.CustomAuthenticationValues;
        newPeer.PlayerName= networkingPeer.PlayerName;
        newPeer.mLocalActor = networkingPeer.mLocalActor;
        newPeer.DebugOut = networkingPeer.DebugOut;
        newPeer.CrcEnabled = networkingPeer.CrcEnabled;
        newPeer.QuickResendAttempts = networkingPeer.QuickResendAttempts;
        newPeer.lobby = networkingPeer.lobby;
        newPeer.LimitOfUnreliableCommands = networkingPeer.LimitOfUnreliableCommands;
        newPeer.SentCountAllowance = networkingPeer.SentCountAllowance;
        newPeer.TrafficStatsEnabled = networkingPeer.TrafficStatsEnabled;

        networkingPeer = newPeer;
        Debug.LogWarning("Protocol switched to: " + cp + ".");
    }
Exemplo n.º 32
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();
    }
    /// <summary>
    /// While offline, the network protocol can be switched from UDP to TCP at will but make sure to use the fitting port, too.
    /// </summary>
    /// <remarks>
    /// When you switch the protocol, make sure to also switch the port for the master server. Default ports are:
    /// TCP: 4530
    /// UDP: 5055
    ///
    /// This could look like this:
    /// Connect(serverAddress, <udpport|tcpport>, appID, gameVersion)
    ///
    /// Or when you use ConnectUsingSettings(), the PORT in the settings can be switched like so:
    /// PhotonNetwork.PhotonServerSettings.ServerPort = 4530;
    ///
    /// The current protocol can be read this way:
    /// PhotonNetwork.networkingPeer.UsedProtocol
    ///
    /// This does not work with the native socket plugin of PUN+ on mobile!
    /// </remarks>
    /// <param name="cp">Network protocol to use as low level connection. UDP is default. TCP is not available on all platforms (see remarks).</param>
    public static void SwitchToProtocol(ConnectionProtocol cp)
    {
        if (networkingPeer.UsedProtocol == cp)
        {
            return;
        }
        try
        {
            networkingPeer.Disconnect();
            networkingPeer.StopThread();
        }
        catch
        {

        }

        // Set up the NetworkingPeer
        networkingPeer = new NetworkingPeer(photonMono, String.Empty, cp);

        Debug.Log("Protocol switched to: " + cp);
    }
Exemplo n.º 34
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();
    }
Exemplo n.º 35
0
    /// <summary>
    /// While offline, the network protocol can be switched (which affects the ports you can use to connect).
    /// </summary>
    /// <remarks>
    /// When you switch the protocol, make sure to also switch the port for the master server. Default ports are:
    /// TCP: 4530
    /// UDP: 5055
    ///
    /// This could look like this:<br/>
    /// Connect(serverAddress, <udpport|tcpport>, appID, gameVersion)
    ///
    /// Or when you use ConnectUsingSettings(), the PORT in the settings can be switched like so:<br/>
    /// PhotonNetwork.PhotonServerSettings.ServerPort = 4530;
    ///
    /// The current protocol can be read this way:<br/>
    /// PhotonNetwork.networkingPeer.UsedProtocol
    ///
    /// This does not work with the native socket plugin of PUN+ on mobile!
    /// </remarks>
    /// <param name="cp">Network protocol to use as low level connection. UDP is default. TCP is not available on all platforms (see remarks).</param>
    public static void SwitchToProtocol(ConnectionProtocol cp)
    {
        if (networkingPeer.UsedProtocol == cp)
        {
            return;
        }
        try
        {
            networkingPeer.Disconnect();
            networkingPeer.StopThread();
        }
        catch
        {

        }

        // set up a new NetworkingPeer
        NetworkingPeer newPeer = new NetworkingPeer(photonMono, String.Empty, cp);
        newPeer.mAppVersion = networkingPeer.mAppVersion;
        newPeer.CustomAuthenticationValues = networkingPeer.CustomAuthenticationValues;
        newPeer.PlayerName= networkingPeer.PlayerName;
        newPeer.mLocalActor = networkingPeer.mLocalActor;
        newPeer.DebugOut = networkingPeer.DebugOut;
        newPeer.CrcEnabled = networkingPeer.CrcEnabled;
        newPeer.lobby = networkingPeer.lobby;
        newPeer.LimitOfUnreliableCommands = networkingPeer.LimitOfUnreliableCommands;
        newPeer.SentCountAllowance = networkingPeer.SentCountAllowance;
        newPeer.TrafficStatsEnabled = networkingPeer.TrafficStatsEnabled;

        networkingPeer = newPeer;
        Debug.LogWarning("Protocol switched to: " + cp + ".");
    }
Exemplo n.º 36
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();
    }
Exemplo n.º 37
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();
    }