facebook twitter hatena line email

Unity/photon/pun2/rpc

提供: 初心者エンジニアの簡易メモ
2021年8月11日 (水) 18:09時点におけるAdmin (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

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);
		}
	}
}