facebook twitter hatena line email

Unity/photon/pun2/rpc

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

RpcViewScene.cs

using UnityEngine;
using Photon.Pun;

public class RpcViewScene : MonoBehaviour
{
	PhotonView  photonView    = null;
	void Awake() {
		photonView    = GetComponent<PhotonView>();
	}
	void Start() {
	}
	void Update() {
		if (Input.GetKeyDown (KeyCode.Space)) {
			SpaceKey ();
		}
		if (Input.GetKeyDown (KeyCode.LeftArrow)) {
			LeftArrowKey ();
		}
	}
	void SpaceKey()
	{
		photonView.RPC("CustomMethod", RpcTarget.All);
	}
	[PunRPC]
	private void CustomMethod() {
		Debug.Log ("CustomMethod");
	}
	void LeftArrowKey() {
		object[] args = new object[]{
			"hoge",
			new string[] {"taro", "jiro", "saburo"}
		};
		photonView.RPC("Custom2Method", RpcTarget.All, args);
	}
	[PunRPC]
	private void Custom2Method(string str, string[] names) {
		Debug.Log ("CustomMethod " + str);
		foreach (string name in names) {
			Debug.Log ("CustomMethod name=" + name);
		}
	}
}