Created
July 4, 2013 15:18
-
-
Save tsubaki/5928568 to your computer and use it in GitHub Desktop.
Photon Cloudのロビーほぼ最小構成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Loby : MonoBehaviour | |
{ | |
void OnEnable () | |
{ | |
// サーバー接続 | |
PhotonNetwork.ConnectUsingSettings ("0.1"); | |
} | |
void OnDisable () | |
{ | |
// サーバー切断 | |
PhotonNetwork.Disconnect (); | |
} | |
void OnGUI () | |
{ | |
if (PhotonNetwork.insideLobby) { | |
InLoby (); | |
} else { | |
InRoom (); | |
} | |
} | |
/// <summary> | |
/// | |
/// 入室後の処理 | |
/// | |
/// </summary> | |
void InRoom () | |
{ | |
Room room = PhotonNetwork.room; | |
if (room == null) { | |
return; | |
} | |
GUILayout.Label ("playercount" + room.playerCount); | |
// ルーム共有プロパティを更新 | |
if (GUILayout.Button ("isGamePlay..." + room.customProperties ["isGamePlay"])) { | |
Hashtable hash = room.customProperties; | |
hash ["isGamePlay"] = !(bool)hash ["isGamePlay"]; | |
room.SetCustomProperties (hash); | |
} | |
// 入室可能か | |
if (GUILayout.Button ("isOpen..." + room.open)) { | |
room.open = !room.open; | |
} | |
// 部屋から抜ける | |
if (GUILayout.Button ("leave room")) { | |
PhotonNetwork.LeaveRoom (); | |
} | |
} | |
/// <summary> | |
/// | |
/// 入室前(ロビー)の処理 | |
/// | |
/// </summary> | |
void InLoby () | |
{ | |
// 部屋を作る | |
if (GUILayout.Button ("create room")) { | |
PhotonNetwork.CreateRoom ( | |
"room name", // ユニークな部屋名 | |
true, // リストに表示可能かどうか | |
true, // 入場可能か | |
4, // 最大人数 | |
new Hashtable (){{"isGamePlay", false} }, // ルーム共有プロパティ | |
new string[] { "isGamePlay"}); // ロビーで取得可能なプロパティ一覧 | |
} | |
// 部屋一覧 | |
foreach (RoomInfo room in PhotonNetwork.GetRoomList()) { | |
// 部屋情報 | |
GUILayout.Label (string.Format ("{0} player({1}/{2}) isGamePlay({3})", | |
room.name, //部屋名 | |
room.playerCount, //部屋の入場人数 | |
room.maxPlayers, //最大人数 | |
room.customProperties ["isGamePlay"])); // 部屋のステータス | |
// 入室 | |
if (room.open && GUILayout.Button ("join")) { | |
PhotonNetwork.JoinRoom (room); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment