Пример #1
0
    public override void OnJoinedRoom()
    {
        Body = Network.Instantiate("GamePlayer", Vector3.zero, Quaternion.identity);
        SetClientTransform(IsHost ? masterTransform : subTransform);

        StartCoroutine(GyroRotate());
    }
Пример #2
0
    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        status = Status.Creating;
        var options = new RoomOptions();

        options.IsVisible  = true;
        options.IsOpen     = true;
        options.MaxPlayers = 20;
        Net.CreateRoom(room, roomOptions: options);
    }
Пример #3
0
 GameObject CreateNPC()
 {
     if (Net.IsMasterClient)
     {
         print("We're master client so let's wait for another client\n"
               + "to instantiate the test NPC");
         return(null);
     }
     print("Not master client so let's create a NPC");
     return(Net.Instantiate(avatar, @fixed, Quaternion.identity, 0));
 }
Пример #4
0
    void Generate()
    {
        string  suffix = null;
        Vector3 P      = transform.position + Random.insideUnitSphere * radius;

        P.y = transform.position.y;
        var x = Net.Instantiate(prefab, P,
                                Quaternion.AngleAxis(Random.Range(0, 360), Vector3.up), 0);

        x.name = prefab + (suffix != null ? suffix : "");
        PhotonView.Get(x).OwnershipTransfer = OwnershipOption.Takeover;
    }
Пример #5
0
 /// <summary>
 /// Transfers the ownership of this PhotonView (and GameObject) to another player.
 /// </summary>
 /// <remarks>
 /// The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.
 /// </remarks>
 public void TransferOwnership(int newOwnerId)
 {
     PhotonNetwork.TransferOwnership(this.ViewID, newOwnerId);
     this.ownerId = newOwnerId;  // immediately switch ownership locally, to avoid more updates sent from this client.
 }
Пример #6
0
 GameObject CreatePlayer()
 {
     print("Create a player object");
     return(Net.Instantiate(
                avatar, random ? spawn : @fixed, Quaternion.identity, 0));
 }
 public void OnJoinedRoom()
 {
     PhotonNetwork.LoadLevelIfSynced(); //TODO: do we really need this since we do this inside OnRoomPropertiesUpdate()
 }
Пример #8
0
 /// <summary>
 /// Call a RPC method of this GameObject on remote clients of this room (or on all, including this client).
 /// </summary>
 /// <remarks>
 /// [Remote Procedure Calls](@ref rpcManual) are an essential tool in making multiplayer games with PUN.
 /// It enables you to make every client in a room call a specific method.
 ///
 /// This method allows you to make an RPC calls on a specific player's client.
 /// Of course, calls are affected by this client's lag and that of remote clients.
 ///
 /// Each call automatically is routed to the same PhotonView (and GameObject) that was used on the
 /// originating client.
 ///
 /// See: [Remote Procedure Calls](@ref rpcManual).
 /// </remarks>
 /// <param name="methodName">The name of a fitting method that was has the RPC attribute.</param>
 /// <param name="targetPlayer">The group of targets and the way the RPC gets sent.</param>
 /// <param name="parameters">The parameters that the RPC method has (must fit this call!).</param>
 public void RPC(string methodName, Player targetPlayer, params object[] parameters)
 {
     PhotonNetwork.RPC(this, methodName, targetPlayer, false, parameters);
 }
 void Start()
 {
     PhotonNetwork.ConnectUsingSettings();
 }
Пример #10
0
 public override void OnConnectedToMaster()
 {
     Network.JoinOrCreateRoom("room", new RoomOptions(), TypedLobby.Default);
 }
 public void Restart()
 {
     PhotonNetwork.Disconnect();
 }
Пример #12
0
 void Start()
 {
     PlayerPrefs.SetString("Username", "Sup");
     status = Status.Connecting;
     Net.ConnectUsingSettings();
 }
 public void OnCreatedRoom()
 {
     PhotonNetwork.SetLevelInPropsIfSynced(SceneManagerHelper.ActiveSceneName);
 }
Пример #14
0
 /// <summary>
 /// Depending on the PhotonView's OwnershipTransfer setting, any client can request to become owner of the PhotonView.
 /// </summary>
 /// <remarks>
 /// Requesting ownership can give you control over a PhotonView, if the OwnershipTransfer setting allows that.
 /// The current owner might have to implement IPunCallbacks.OnOwnershipRequest to react to the ownership request.
 ///
 /// The owner/controller of a PhotonView is also the client which sends position updates of the GameObject.
 /// </remarks>
 public void RequestOwnership()
 {
     PhotonNetwork.RequestOwnership(this.ViewID, this.ownerId);
 }
Пример #15
0
 public virtual void OnDisable()
 {
     PhotonNetwork.RemoveCallbackTarget(this);
 }
Пример #16
0
 public virtual void OnEnable()
 {
     PhotonNetwork.AddCallbackTarget(this);
 }
 /// <summary>Called by Unity after a new level was loaded.</summary>
 protected void OnLevelWasLoaded(int level)
 {
     PhotonNetwork.NewSceneLoaded();
     PhotonNetwork.SetLevelInPropsIfSynced(SceneManagerHelper.ActiveSceneName);
 }
 public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
 {
     PhotonNetwork.LoadLevelIfSynced();
 }
Пример #19
0
 public override void OnConnectedToMaster()
 {
     status = Status.Joining;
     Net.JoinRandomRoom();
 }
 /// <summary>
 /// Finds the PhotonView Component with a viewID in the scene
 /// </summary>
 /// <param name="viewID"></param>
 /// <returns>The PhotonView with ViewID. Returns null if none found</returns>
 public static PhotonView Find(int viewID)
 {
     return(PhotonNetwork.GetPhotonView(viewID));
 }
Пример #21
0
 public void Connect()
 {
     Network.ConnectUsingSettings();
 }
Пример #22
0
 /// <summary>
 /// Call a RPC method of this GameObject on remote clients of this room (or on all, including this client).
 /// </summary>
 /// <remarks>
 /// [Remote Procedure Calls](@ref rpcManual) are an essential tool in making multiplayer games with PUN.
 /// It enables you to make every client in a room call a specific method.
 ///
 /// RPC calls can target "All" or the "Others".
 /// Usually, the target "All" gets executed locally immediately after sending the RPC.
 /// The "*ViaServer" options send the RPC to the server and execute it on this client when it's sent back.
 /// Of course, calls are affected by this client's lag and that of remote clients.
 ///
 /// Each call automatically is routed to the same PhotonView (and GameObject) that was used on the
 /// originating client.
 ///
 /// See: [Remote Procedure Calls](@ref rpcManual).
 /// </remarks>
 /// <param name="methodName">The name of a fitting method that was has the RPC attribute.</param>
 /// <param name="target">The group of targets and the way the RPC gets sent.</param>
 /// <param name="parameters">The parameters that the RPC method has (must fit this call!).</param>
 public void RPC(string methodName, RpcTarget target, params object[] parameters)
 {
     PhotonNetwork.RPC(this, methodName, target, false, parameters);
 }
Пример #23
0
 /// <summary>
 /// Call a RPC method of this GameObject on remote clients of this room (or on all, inclunding this client).
 /// </summary>
 /// <remarks>
 /// [Remote Procedure Calls](@ref rpcManual) are an essential tool in making multiplayer games with PUN.
 /// It enables you to make every client in a room call a specific method.
 ///
 /// RPC calls can target "All" or the "Others".
 /// Usually, the target "All" gets executed locally immediately after sending the RPC.
 /// The "*ViaServer" options send the RPC to the server and execute it on this client when it's sent back.
 /// Of course, calls are affected by this client's lag and that of remote clients.
 ///
 /// Each call automatically is routed to the same PhotonView (and GameObject) that was used on the
 /// originating client.
 ///
 /// See: [Remote Procedure Calls](@ref rpcManual).
 /// </remarks>
 ///<param name="methodName">The name of a fitting method that was has the RPC attribute.</param>
 ///<param name="target">The group of targets and the way the RPC gets sent.</param>
 ///<param name="encrypt"> </param>
 ///<param name="parameters">The parameters that the RPC method has (must fit this call!).</param>
 public void RpcSecure(string methodName, RpcTarget target, bool encrypt, params object[] parameters)
 {
     PhotonNetwork.RPC(this, methodName, target, encrypt, parameters);
 }
Пример #24
0
        // this method corrects the IDs for photonviews in the scene and in prefabs
        // make sure prefabs always use viewID 0
        // make sure instances never use a owner
        // this is a editor class that should only run if not playing
        internal static void HierarchyChange()
        {
            if (Application.isPlaying)
            {
                //Debug.Log("HierarchyChange ignored, while running.");
                CheckSceneForStuckHandlers = true;                  // done once AFTER play mode.
                return;
            }

            if (CheckSceneForStuckHandlers)
            {
                CheckSceneForStuckHandlers = false;
                PhotonNetwork.InternalCleanPhotonMonoFromSceneIfStuck();
            }

            HashSet <PhotonView> pvInstances             = new HashSet <PhotonView>();
            HashSet <int>        usedInstanceViewNumbers = new HashSet <int>();
            bool fixedSomeId = false;

            //// the following code would be an option if we only checked scene objects (but we can check all PVs)
            //PhotonView[] pvObjects = GameObject.FindSceneObjectsOfType(typeof(PhotonView)) as PhotonView[];
            //Debug.Log("HierarchyChange. PV Count: " + pvObjects.Length);

            string levelName = SceneManagerHelper.ActiveSceneName;

                        #if UNITY_EDITOR
            levelName = SceneManagerHelper.EditorActiveSceneName;
                        #endif
            int minViewIdInThisScene = PunSceneSettings.MinViewIdForScene(levelName);
            //Debug.Log("Level '" + Application.loadedLevelName + "' has a minimum ViewId of: " + minViewIdInThisScene);

            PhotonView[] pvObjects = Resources.FindObjectsOfTypeAll(typeof(PhotonView)) as PhotonView[];

            foreach (PhotonView view in pvObjects)
            {
                // first pass: fix prefabs to viewID 0 if they got a view number assigned (cause they should not have one!)
                if (EditorUtility.IsPersistent(view.gameObject))
                {
                    if (view.ViewID != 0 || view.prefixField != -1)
                    {
                        Debug.LogWarning("PhotonView on persistent object being fixed (id and prefix must be 0). Was: " + view);
                        view.ViewID      = 0;
                        view.prefixField = -1;
                        EditorUtility.SetDirty(view);                           // even in Unity 5.3+ it's OK to SetDirty() for non-scene objects.
                        fixedSomeId = true;
                    }
                }
                else
                {
                    // keep all scene-instanced PVs for later re-check
                    pvInstances.Add(view);
                }
            }

            Dictionary <GameObject, int> idPerObject = new Dictionary <GameObject, int>();

            // second pass: check all used-in-scene viewIDs for duplicate viewIDs (only checking anything non-prefab)
            // scene-PVs must have user == 0 (scene/room) and a subId != 0
            foreach (PhotonView view in pvInstances)
            {
                if (view.OwnerActorNr > 0)
                {
                    Debug.Log("Re-Setting Owner ID of: " + view);
                }

                view.Prefix = -1;                   // TODO: prefix could be settable via inspector per scene?!

                if (view.ViewID != 0)
                {
                    if (view.ViewID < minViewIdInThisScene || usedInstanceViewNumbers.Contains(view.ViewID))
                    {
                        view.ViewID = 0;                         // avoid duplicates and negative values by assigning 0 as (temporary) number to be fixed in next pass
                    }
                    else
                    {
                        usedInstanceViewNumbers.Add(view.ViewID);                         // builds a list of currently used viewIDs

                        int instId = 0;
                        if (idPerObject.TryGetValue(view.gameObject, out instId))
                        {
                            view.InstantiationId = instId;
                        }
                        else
                        {
                            view.InstantiationId         = view.ViewID;
                            idPerObject[view.gameObject] = view.InstantiationId;
                        }
                    }
                }
            }

            // third pass: anything that's now 0 must get a new (not yet used) ID (starting at 0)
            int lastUsedId = (minViewIdInThisScene > 0) ? minViewIdInThisScene - 1 : 0;

            foreach (PhotonView view in pvInstances)
            {
                if (view.ViewID == 0)
                {
                    Undo.RecordObject(view, "Automatic viewID change for: " + view.gameObject.name);

                    // Debug.LogWarning("setting scene ID: " + view.gameObject.name + " ID: " + view.subId.ID + " scene ID: " + view.GetSceneID() + " IsPersistent: " + EditorUtility.IsPersistent(view.gameObject) + " IsSceneViewIDFree: " + IsSceneViewIDFree(view.subId.ID, view));
                    int nextViewId = PhotonViewHandler.GetID(lastUsedId, usedInstanceViewNumbers);

                    view.ViewID = nextViewId;

                    int instId = 0;
                    if (idPerObject.TryGetValue(view.gameObject, out instId))
                    {
                        view.InstantiationId = instId;
                    }
                    else
                    {
                        view.InstantiationId         = view.ViewID;
                        idPerObject[view.gameObject] = nextViewId;
                    }

                    lastUsedId  = nextViewId;
                    fixedSomeId = true;
                }
            }


            if (fixedSomeId)
            {
                //Debug.LogWarning("Some subId was adjusted."); // this log is only interesting for Exit Games
            }
        }