IPunCallbacks.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 
  2. namespace Photon.Pun
  3. {
  4. using UnityEngine;
  5. using Photon.Realtime;
  6. /// <summary>Defines the OnPhotonSerializeView method to make it easy to implement correctly for observable scripts.</summary>
  7. /// \ingroup callbacks
  8. public interface IPunObservable
  9. {
  10. /// <summary>
  11. /// Called by PUN several times per second, so that your script can write and read synchronization data for the PhotonView.
  12. /// </summary>
  13. /// <remarks>
  14. /// This method will be called in scripts that are assigned as Observed component of a PhotonView.<br/>
  15. /// PhotonNetwork.SerializationRate affects how often this method is called.<br/>
  16. /// PhotonNetwork.SendRate affects how often packages are sent by this client.<br/>
  17. ///
  18. /// Implementing this method, you can customize which data a PhotonView regularly synchronizes.
  19. /// Your code defines what is being sent (content) and how your data is used by receiving clients.
  20. ///
  21. /// Unlike other callbacks, <i>OnPhotonSerializeView only gets called when it is assigned
  22. /// to a PhotonView</i> as PhotonView.observed script.
  23. ///
  24. /// To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the
  25. /// client that controls a PhotonView (PhotonStream.IsWriting == true) and in "reading mode" on the
  26. /// remote clients that just receive that the controlling client sends.
  27. ///
  28. /// If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can
  29. /// conserve bandwidth and messages (which have a limit per room/second).
  30. ///
  31. /// Note that OnPhotonSerializeView is not called on remote clients when the sender does not send
  32. /// any update. This can't be used as "x-times per second Update()".
  33. /// </remarks>
  34. /// \ingroup publicApi
  35. void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info);
  36. }
  37. /// <summary>
  38. /// Global Callback interface for ownership changes. These callbacks will fire for changes to ANY PhotonView that changes.
  39. /// Consider using IOnPhotonViewControllerChange for callbacks from a specific PhotonView.
  40. /// </summary>
  41. public interface IPunOwnershipCallbacks
  42. {
  43. /// <summary>
  44. /// Called when another player requests ownership of a PhotonView.
  45. /// Called on all clients, so check if (targetView.IsMine) or (targetView.Owner == PhotonNetwork.LocalPlayer)
  46. /// to determine if a targetView.TransferOwnership(requestingPlayer) response should be given.
  47. /// </summary>
  48. /// <remarks>
  49. /// The parameter viewAndPlayer contains:
  50. ///
  51. /// PhotonView view = viewAndPlayer[0] as PhotonView;
  52. ///
  53. /// Player requestingPlayer = viewAndPlayer[1] as Player;
  54. /// </remarks>
  55. /// <param name="targetView">PhotonView for which ownership gets requested.</param>
  56. /// <param name="requestingPlayer">Player who requests ownership.</param>
  57. void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer);
  58. /// <summary>
  59. /// Called when ownership of a PhotonView is transfered to another player.
  60. /// </summary>
  61. /// <remarks>
  62. /// The parameter viewAndPlayers contains:
  63. ///
  64. /// PhotonView view = viewAndPlayers[0] as PhotonView;
  65. ///
  66. /// Player newOwner = viewAndPlayers[1] as Player;
  67. ///
  68. /// Player oldOwner = viewAndPlayers[2] as Player;
  69. /// </remarks>
  70. /// <example>void OnOwnershipTransfered(object[] viewAndPlayers) {} //</example>
  71. /// <param name="targetView">PhotonView for which ownership changed.</param>
  72. /// <param name="previousOwner">Player who was the previous owner (or null, if none).</param>
  73. void OnOwnershipTransfered(PhotonView targetView, Player previousOwner);
  74. /// <summary>
  75. /// Called when an Ownership Request fails for objects with "takeover" setting.
  76. /// </summary>
  77. /// <remarks>
  78. /// Each request asks to take ownership from a specific controlling player. This can fail if anyone
  79. /// else took over ownership briefly before the request arrived.
  80. /// </remarks>
  81. /// <param name="targetView"></param>
  82. /// <param name="senderOfFailedRequest"></param>
  83. void OnOwnershipTransferFailed(PhotonView targetView, Player senderOfFailedRequest);
  84. }
  85. /// \ingroup callbacks
  86. public interface IPunInstantiateMagicCallback
  87. {
  88. void OnPhotonInstantiate(PhotonMessageInfo info);
  89. }
  90. /// <summary>
  91. /// Defines an interface for object pooling, used in PhotonNetwork.Instantiate and PhotonNetwork.Destroy.
  92. /// </summary>
  93. /// <remarks>
  94. /// To apply your custom IPunPrefabPool, set PhotonNetwork.PrefabPool.
  95. ///
  96. /// The pool has to return a valid, disabled GameObject when PUN calls Instantiate.
  97. /// Also, the position and rotation must be applied.
  98. ///
  99. /// Note that Awake and Start are only called once by Unity, so scripts on re-used GameObjects
  100. /// should make use of OnEnable and or OnDisable. When OnEnable gets called, the PhotonView
  101. /// is already updated to the new values.
  102. ///
  103. /// To be able to enable a GameObject, Instantiate must return an inactive object.
  104. ///
  105. /// Before PUN "destroys" GameObjects, it will disable them.
  106. ///
  107. /// If a component implements IPunInstantiateMagicCallback, PUN will call OnPhotonInstantiate
  108. /// when the networked object gets instantiated. If no components implement this on a prefab,
  109. /// PUN will optimize the instantiation and no longer looks up IPunInstantiateMagicCallback
  110. /// via GetComponents.
  111. /// </remarks>
  112. public interface IPunPrefabPool
  113. {
  114. /// <summary>
  115. /// Called to get an instance of a prefab. Must return valid, disabled GameObject with PhotonView.
  116. /// </summary>
  117. /// <param name="prefabId">The id of this prefab.</param>
  118. /// <param name="position">The position for the instance.</param>
  119. /// <param name="rotation">The rotation for the instance.</param>
  120. /// <returns>A disabled instance to use by PUN or null if the prefabId is unknown.</returns>
  121. GameObject Instantiate(string prefabId, Vector3 position, Quaternion rotation);
  122. /// <summary>
  123. /// 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.
  124. /// </summary>
  125. /// <remarks>
  126. /// A pool needs some way to find out which type of GameObject got returned via Destroy().
  127. /// It could be a tag, name, a component or anything similar.
  128. /// </remarks>
  129. /// <param name="gameObject">The instance to destroy.</param>
  130. void Destroy(GameObject gameObject);
  131. }
  132. }