namespace Photon.Pun { using UnityEngine; using Photon.Realtime; /// Defines the OnPhotonSerializeView method to make it easy to implement correctly for observable scripts. /// \ingroup callbacks public interface IPunObservable { /// /// Called by PUN several times per second, so that your script can write and read synchronization data for the PhotonView. /// /// /// This method will be called in scripts that are assigned as Observed component of a PhotonView.
/// PhotonNetwork.SerializationRate affects how often this method is called.
/// PhotonNetwork.SendRate affects how often packages are sent by this client.
/// /// Implementing this method, you can customize which data a PhotonView regularly synchronizes. /// Your code defines what is being sent (content) and how your data is used by receiving clients. /// /// Unlike other callbacks, OnPhotonSerializeView only gets called when it is assigned /// to a PhotonView as PhotonView.observed script. /// /// To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the /// client that controls a PhotonView (PhotonStream.IsWriting == true) and in "reading mode" on the /// remote clients that just receive that the controlling client sends. /// /// If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can /// conserve bandwidth and messages (which have a limit per room/second). /// /// Note that OnPhotonSerializeView is not called on remote clients when the sender does not send /// any update. This can't be used as "x-times per second Update()". ///
/// \ingroup publicApi void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info); } /// /// Global Callback interface for ownership changes. These callbacks will fire for changes to ANY PhotonView that changes. /// Consider using IOnPhotonViewControllerChange for callbacks from a specific PhotonView. /// public interface IPunOwnershipCallbacks { /// /// Called when another player requests ownership of a PhotonView. /// Called on all clients, so check if (targetView.IsMine) or (targetView.Owner == PhotonNetwork.LocalPlayer) /// to determine if a targetView.TransferOwnership(requestingPlayer) response should be given. /// /// /// The parameter viewAndPlayer contains: /// /// PhotonView view = viewAndPlayer[0] as PhotonView; /// /// Player requestingPlayer = viewAndPlayer[1] as Player; /// /// PhotonView for which ownership gets requested. /// Player who requests ownership. void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer); /// /// Called when ownership of a PhotonView is transfered to another player. /// /// /// The parameter viewAndPlayers contains: /// /// PhotonView view = viewAndPlayers[0] as PhotonView; /// /// Player newOwner = viewAndPlayers[1] as Player; /// /// Player oldOwner = viewAndPlayers[2] as Player; /// /// void OnOwnershipTransfered(object[] viewAndPlayers) {} // /// PhotonView for which ownership changed. /// Player who was the previous owner (or null, if none). void OnOwnershipTransfered(PhotonView targetView, Player previousOwner); /// /// Called when an Ownership Request fails for objects with "takeover" setting. /// /// /// Each request asks to take ownership from a specific controlling player. This can fail if anyone /// else took over ownership briefly before the request arrived. /// /// /// void OnOwnershipTransferFailed(PhotonView targetView, Player senderOfFailedRequest); } /// \ingroup callbacks public interface IPunInstantiateMagicCallback { void OnPhotonInstantiate(PhotonMessageInfo info); } /// /// Defines an interface for object pooling, used in PhotonNetwork.Instantiate and PhotonNetwork.Destroy. /// /// /// To apply your custom IPunPrefabPool, set PhotonNetwork.PrefabPool. /// /// The pool has to return a valid, disabled GameObject when PUN calls Instantiate. /// Also, the position and rotation must be applied. /// /// Note that Awake and Start are only called once by Unity, so scripts on re-used GameObjects /// should make use of OnEnable and or OnDisable. When OnEnable gets called, the PhotonView /// is already updated to the new values. /// /// To be able to enable a GameObject, Instantiate must return an inactive object. /// /// Before PUN "destroys" GameObjects, it will disable them. /// /// If a component implements IPunInstantiateMagicCallback, PUN will call OnPhotonInstantiate /// when the networked object gets instantiated. If no components implement this on a prefab, /// PUN will optimize the instantiation and no longer looks up IPunInstantiateMagicCallback /// via GetComponents. /// public interface IPunPrefabPool { /// /// Called to get an instance of a prefab. Must return valid, disabled GameObject with PhotonView. /// /// The id of this prefab. /// The position for the instance. /// The rotation for the instance. /// A disabled instance to use by PUN or null if the prefabId is unknown. GameObject Instantiate(string prefabId, Vector3 position, Quaternion rotation); /// /// Called to destroy (or just return) the instance of a prefab. It's disabled and the pool may reset and cache it for later use in Instantiate. /// /// /// A pool needs some way to find out which type of GameObject got returned via Destroy(). /// It could be a tag, name, a component or anything similar. /// /// The instance to destroy. void Destroy(GameObject gameObject); } }