void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // ローカルプレイヤー(他のプレイヤーへ情報を送信するので、ストリームに書き込む) stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { // ネットワーク上のプレイヤー(自分以外のプレイヤーの情報。ネットワーク経由で情報を受け取る) this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); } }
public class TestRPC : Photon.MonoBehaviour { [PunRPC] public void RPCFunc(string msg, byte[] data, PhotonMessageInfo info) { Debug.Log("Message : " + msg); string dataStr = ""; foreach(byte b in data) dataStr += b + " "; Debug.Log("Data : " + dataStr); } }
v1.56 (16. June 2015) Changed: The RPC attribute got replaced by PunRPC. Search and replace your code for [RPC] and replace it with [PunRPC] (in JS: @RPC and @PunRPC). The change is necessary, because the RPC attribute is obsolete in Unity 5.1 and that causes a large amount of warnings at compile time. The new PunRPC must be used in all versions of Unity, starting with this PUN version.
// RPCを呼び出す { PhotonView view; // TestRPC + PhotonViewを持つGameObjectから取得する // RPCメソッドの引数 object[] の配列にする object[] args = new object[]{ "RPC message", // 第1引数 : string msg new byte[] {1, 2, 3} // 第2引数 : byte[] data }; // RPCメソッドの名前、引数を合わせる view.RPC( "RPCFunc", // メソッド名 Photontargets.All, // ネットワークプレイヤー全員に対して呼び出す args); // 引数 }