void createText(string text, string parentName) { // ホスト以外は処理をしない if (!MonobitEngine.MonobitNetwork.isHost) { return; } GameObject newText = MonobitNetwork.Instantiate( ToSpawn.name, Vector3.zero, Quaternion.identity, 0, null, true, false, true ) as GameObject; newText.GetComponentInChildren <textStatusReceiver>().parentName = parentName; newText.GetComponentInChildren <textStatusReceiver>().text = text; newText.GetComponentInChildren <textStatusReceiver>().color = fcp.color; //入力された言葉を連想配列に追加する wordList.AddWord(text); }
private void UpdateRoomData() { var scrollViewContent = m_scrollViewObj.transform.Find("Viewport/Content"); int roomCount = MonobitNetwork.GetRoomData().Length; for (int i = 0; i < roomCount; i++) { RoomData roomData = MonobitNetwork.GetRoomData()[i]; if (!roomData.customParameters["password"].Equals("empty")) { continue; } GameObject button = (GameObject)Instantiate(m_ButtonPrefab); button.transform.SetParent(scrollViewContent, false); button.GetComponent <RectTransform>().anchoredPosition = new Vector3(0, i * -30 + 120, 0); button.GetComponent <ScrollViewButton>().Set(MonobitNetwork.GetRoomData()[i]); m_ButtonList.Add(button); } }
private IEnumerator WaitConnectedCoroutine(string roomname) { yield return(null); if (MonobitNetwork.isConnecting) { yield return(new WaitForSecondsRealtime(3.0f)); Debug.Log(string.Join(" / ", MonobitNetwork.GetRoomData().Select(x => x.name))); if (!MonobitNetwork.inRoom) { Debug.Log("VC_Connected!"); if (MonobitNetwork.GetRoomData().ToList().FirstOrDefault(room => room.name == roomname) == null) { Debug.Log("VC_CreateRoom: " + roomname); MonobitNetwork.CreateRoom(roomname); } else { Debug.Log("VC_JoinRoom: " + roomname); MonobitNetwork.JoinRoom(roomname); } yield return(new WaitForSecondsRealtime(1.0f)); Debug.Log(string.Join(" / ", MonobitNetwork.GetRoomData().Select(x => x.name))); StartCoroutine(WaitLoginCoroutine()); } } else { Debug.Log("VC_WaitConnected..."); yield return(new WaitForSecondsRealtime(1.0f)); StartCoroutine(WaitConnectedCoroutine(roomname)); } }
// ウィンドウ表示 void OnGUI_UnsafeDisconnect(int WindowID) { GUIStyle style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; GUIStyleState stylestate = new GUIStyleState(); stylestate.textColor = Color.white; style.normal = stylestate; if (isDisconnecting) { GUILayout.Label("MUN is disconnect.\nAre you reconnect?", style); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Yes", GUILayout.Width(50))) { // もう一度接続処理を実行する isDisconnecting = false; isReconnecting = true; isGameStart = false; isGameEnd = false; isSpawnMyChara = false; MonobitNetwork.ConnectServer("RakeupGame_ClientSide_v1.0"); } if (GUILayout.Button("No", GUILayout.Width(50))) { isDisconnecting = false; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { GUILayout.Label("reconnecting...", style); } }
/** * ルーム作成設定. */ private void OnGUI_CreateOrJoinRoom() { // 値の入力 GUILayout.BeginHorizontal(); GUILayout.Label("Your Numeric Value(" + baseValueLow + "-" + baseValueHigh + ") : ", GUILayout.Width(200)); baseValue = Convert.ToInt32(GUILayout.TextField(baseValue.ToString(), GUILayout.Width(50))); GUILayout.EndHorizontal(); // ルーム最大人数の入力 GUILayout.BeginHorizontal(); GUILayout.Label("Room Max Players : ", GUILayout.Width(200)); maxPlayers = Convert.ToByte(GUILayout.TextField(maxPlayers.ToString(), GUILayout.Width(50))); GUILayout.EndHorizontal(); // ルームの作成 if (GUILayout.Button("Create Room", GUILayout.Width(250))) { // 入力した値が範囲外の場合、入力を無視する if (baseValue < baseValueLow || baseValue > baseValueHigh) { Debug.LogWarning("Your value must between" + baseValueLow + " and " + baseValueHigh); } else { // 自身の値をクエリーパラメータとして代入 customRoomParam["Value"] = baseValue; // ロビー抽出バラメータの設定 string[] customRoomParametersForLobby = { "Value" }; // ルームの作成 RoomSettings roomSettings = new RoomSettings() { isVisible = true, isOpen = true, maxPlayers = this.maxPlayers, roomParameters = this.customRoomParam, lobbyParameters = customRoomParametersForLobby }; MonobitNetwork.CreateRoom(null, roomSettings, null); } } // ルームへの入室 if (GUILayout.Button("Join Room", GUILayout.Width(250))) { // 入力した値が範囲外の場合、入力を無視する if (baseValue < baseValueLow || baseValue > baseValueHigh) { Debug.LogWarning("Your value must between" + baseValueLow + " and " + baseValueHigh); } else { // 自身の値に対し、検索範囲の最初の閾値を設定する baseValueMin = (baseValue - baseValueIncrease < baseValueLow) ? baseValueLow : baseValue - baseValueIncrease; baseValueMax = (baseValue + baseValueIncrease > baseValueHigh) ? baseValueHigh : baseValue + baseValueIncrease; // 閾値から、クエリー検索のためのWHERE句を生成する string queryLobbyFilter = "Value>=" + baseValueMin + " AND Value<=" + baseValueMax; // ルームへの入室 MonobitNetwork.JoinRandomRoom(null, this.maxPlayers, Definitions.MatchmakingMode.SerialMatching, new LobbyInfo() { Kind = LobbyKind.Query, Name = "QueryLobby" }, queryLobbyFilter); } } }
private void LeaveRoomAll() { MonobitNetwork.LeaveRoom(); }
// 接続が確立した時の処理 public void OnJoinedLobby() { // 現在残っているルーム情報から再接続を実行する MonobitNetwork.JoinRoom(reconnectRoomName); }
public override void OnJoinedLobby() { Debug.Log("On join lobby."); MonobitNetwork.JoinOrCreateRoom("TCAvrOB", new RoomSettings(), LobbyInfo.Default); }
/** * @brief オンライン&ロビー入室中のGUI表示. * @param isDispInputGUI 入力系GUIを表示するかどうかのフラグ(縁取り文字描画機能を活かした場合の、多重描画を防止するため). * @param state 文字表示色. */ private void OnGUI_InLobby(bool isDispInputGUI, GUIStyleState state) { // ルーム作成GUIレイヤー { // Header GUILayout.Label("Create Room/Join Random", new GUIStyle() { normal = state, fontSize = 18 }); GUILayout.BeginHorizontal(); GUILayout.Space(25); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); { // ルーム名の入力欄、および作成ボタン入力表示 GUILayout.Label("Input room name:", new GUIStyle() { normal = state, fontSize = 16, margin = new RectOffset(6, 6, 6, 6), fixedWidth = 140 }); if (isDispInputGUI) { this.roomName = GUILayout.TextField(this.roomName, GUILayout.Width(200)); if (GUILayout.Button("Create Room", GUILayout.Width(150))) { // 入力があった場合、指定された名前で4人部屋を生成 MonobitNetwork.CreateRoom(roomName, new RoomSettings() { isVisible = true, isOpen = true, maxPlayers = 4 }, null); } } else { GUILayout.Space(25); } } GUILayout.EndHorizontal(); // ルームの作成ボタン入力表示 if (isDispInputGUI) { if (GUILayout.Button("Join Random", GUILayout.Width(150))) { // ランダム入室をする MonobitNetwork.JoinRandomRoom(); } } else { GUILayout.Space(25); } // Footer GUILayout.EndVertical(); GUILayout.EndHorizontal(); } // ルームリストGUIレイヤー { // ルーム一覧の取得 RoomData[] roomList = MonobitNetwork.GetRoomData(); // ルーム一覧が存在する場合、ルームリストを表示 if (roomList != null) { // Header GUILayout.Label("Created Room List", new GUIStyle() { normal = state, fontSize = 24 }); GUILayout.BeginHorizontal(); GUILayout.Space(25); GUILayout.BeginVertical(); // ルームリストについて、1件ずつボタン入力表示 foreach (RoomData room in roomList) { if (isDispInputGUI && room.open && room.visible) { if (GUILayout.Button(room.name + " (" + room.playerCount + "/" + room.maxPlayers + ")", GUILayout.Width(300))) { MonobitNetwork.JoinRoom(room.name); } } } // Footer GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } }
public void StopVoiceChat() { MonobitNetwork.LeaveRoom(); }
// GUI処理 void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // プレイヤーIDの表示 if (MonobitNetwork.player != null) { GUILayout.Label("My Player ID : " + MonobitNetwork.player.ID); } // ルーム情報の取得 Room room = MonobitNetwork.room; if (room != null) { // ルーム名の表示 GUILayout.Label("Room Name : " + room.name); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label("PlayerCount : " + room.playerCount); // ルームがオープンかクローズか GUILayout.Label("Room IsOpen : " + room.open); // 制限時間の表示 if (m_bGameStart) { GUILayout.Label("Rest Frame : " + this.battleEndFrame); } } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(100))) { // 部屋から離脱する MonobitNetwork.LeaveRoom(); // 一旦切断する MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineScene.SceneNameOffline); } // ホストの場合 if (MonobitNetwork.isHost) { // ゲームスタート前にゲームスタートするかどうか if (!m_bGameStart && GUILayout.Button("Start Game", GUILayout.Width(100))) { // ゲームスタートフラグを立てる m_bGameStart = true; // ルームをクローズする //room.open = false; // バトルスタートを通知 monobitView.RPC("OnGameStart", MonobitTargets.All, null); } for (int i = 0; i < MonobitNetwork.otherPlayersList.Length; i++) { if (!m_bGameStart && GUILayout.Button("Switch Host ID:" + MonobitNetwork.otherPlayersList[i].ID, GUILayout.Width(200))) { MonobitNetwork.ChangeHost(MonobitNetwork.otherPlayersList[i]); } } } }
/** * ルーム内でのGUI操作. */ private void OnGUI_InRoom() { // 自身のプレイヤーIDの表示 GUILayout.Label("Your ID : " + MonobitNetwork.player.ID); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label("PlayerCount : " + MonobitNetwork.room.playerCount + " / " + ((MonobitNetwork.room.maxPlayers == 0) ? "-" : MonobitNetwork.room.maxPlayers.ToString())); // ルームの入室制限可否設定の表示 GUILayout.Label("Room isOpen : " + MonobitNetwork.room.open); // ルーム作成者が入力した値 GUILayout.Label("Room Owner Numeric Value : " + MonobitNetwork.room.customParameters["Value"]); // 自身が入力した値 GUILayout.Label("My Skill Level : " + baseValue); // 制限時間の表示 if (isGameStart) { GUILayout.Label("Rest Frame : " + this.battleEndFrame); } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(150))) { MonobitNetwork.LeaveRoom(); } // ホストの場合 if (MonobitNetwork.isHost) { // ゲームスタート if (!isGameStart && GUILayout.Button("Start Game", GUILayout.Width(150))) { this.isGameStart = true; // room.open = false; monobitView.RPC("GameStart", MonobitTargets.All, null); } // バトル終了 if (this.battleEndFrame <= 0) { // room.open = true; // 部屋から離脱する monobitView.RPC("LeaveRoomAll", MonobitTargets.All, null); } } // 他にルームが作成されている場合 if (MonobitNetwork.GetRoomData() != null && MonobitNetwork.GetRoomData().Length >= 1) { // 他の部屋に入室 if (GUILayout.Button("Enter Another Room", GUILayout.Width(150))) { // 一旦部屋から離脱する MonobitNetwork.LeaveRoom(); isEnterAnotherRoom = true; } } }
/** * ルーム内でのGUI操作. */ private void OnGUI_InRoom() { // 自身のプレイヤーIDの表示 GUILayout.Label("Your ID : " + MonobitNetwork.player.ID); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label("PlayerCount : " + MonobitNetwork.room.playerCount + " / " + ((MonobitNetwork.room.maxPlayers == 0) ? "-" : MonobitNetwork.room.maxPlayers.ToString())); // ルームの入室制限可否設定の表示 GUILayout.Label("Room is : " + ((MonobitNetwork.room.open) ? "open," : "close,") + " and " + ((MonobitNetwork.room.visible) ? "visible." : "invisible.")); // カスタムルームパラメータの表示 GUILayout.Label("Custom Room Parameters"); foreach (DictionaryEntry dic in MonobitNetwork.room.customParameters) { GUILayout.Label("\tKeys : " + dic.Key + ", Value : " + dic.Value); } // 制限時間の表示 if (isGameStart) { GUILayout.Label("Rest Frame : " + this.battleEndFrame); } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(100))) { MonobitNetwork.LeaveRoom(); } // ホストの場合 if (MonobitNetwork.isHost) { // ルームのカスタムパラメータの値入力 bool isCustomRoomParamChanged = false; if (this.customRoomParam.Count > 0) { Hashtable tmp = new Hashtable(this.customRoomParam); foreach (string key in this.customRoomParam.Keys) { GUILayout.BeginHorizontal(); GUILayout.Label("Key : " + key + ", Value : "); tmp[key] = GUILayout.TextField(this.customRoomParam[key].ToString(), GUILayout.Width(200)); GUILayout.EndHorizontal(); } foreach (string key in this.customRoomParam.Keys) { if (!tmp.ContainsKey(key) || tmp[key] != this.customRoomParam[key]) { isCustomRoomParamChanged = true; this.customRoomParam = tmp; break; } } } // ルームのカスタムパラメータのキー追加 GUILayout.BeginHorizontal(); GUILayout.Label("New Key : "); customRoomKey = GUILayout.TextField(customRoomKey, GUILayout.Width(200)); if (GUILayout.Button("Add", GUILayout.Width(75))) { if (!string.IsNullOrEmpty(customRoomKey)) { isCustomRoomParamChanged = true; this.customRoomParam[customRoomKey] = "" as object; customRoomKey = ""; } } if (isCustomRoomParamChanged) { MonobitNetwork.room.SetCustomParameters(this.customRoomParam); } GUILayout.EndHorizontal(); // ゲームスタート if (!isGameStart && GUILayout.Button("Start Game", GUILayout.Width(100))) { this.isGameStart = true; // room.open = false; monobitView.RPC("GameStart", MonobitTargets.All, null); } // バトル終了 if (this.battleEndFrame <= 0) { // room.open = true; // 部屋から離脱する monobitView.RPC("LeaveRoomAll", MonobitTargets.All, null); } } }
// GUI処理 void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // マイクデバイスの表示 GUILayout.Label("Microphone: " + MonobitMicrophone.MicrophoneDeviceName); // マイクデバイスの切り替え for (int i = 0; i < Microphone.devices.Length; ++i) { string name = (Microphone.devices[i].Length > 0) ? Microphone.devices[i] : null; if (i == 0) { if (null != MonobitMicrophone.MicrophoneDeviceName) { // i == 0はデフォルト。デフォルトに必ず戻せるようにしておく if (GUILayout.Button("Default" + ((null == name) ? "" : " < " + name + " >"), GUILayout.Width(400))) { MonobitMicrophone.MicrophoneDeviceName = null; } } continue; } else if (name == null) { // Unity2018より前のバージョンだと、日本語を含むデバイス名が空文字列になり、選択できないので、無視 continue; } // 選択済のデバイスは無視 if (name == MonobitMicrophone.MicrophoneDeviceName) { continue; } if (GUILayout.Button(name, GUILayout.Width(400))) { MonobitMicrophone.MicrophoneDeviceName = name; } } // プレイヤーIDの表示 if (MonobitNetwork.player != null) { GUILayout.Label(string.Format("My Player ID : {0}", MonobitNetwork.player.ID)); } // ルーム情報の取得 Room room = MonobitNetwork.room; if (room != null) { // ルーム名の表示 GUILayout.Label("Voice bps : " + m_bps); // ルーム名の表示 GUILayout.Label(string.Format("Room Name : {0}", room.name)); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label(string.Format("PlayerCount : {0}", room.playerCount)); // ルームがオープンかクローズか GUILayout.Label(string.Format("Room IsOpen : {0}", room.open)); // 制限時間の表示 if (m_bGameStart) { GUILayout.Label(string.Format("Rest Frame : {0}", this.battleEndFrame)); } GUILayout.Label(string.Format("IsHost : {0}", MonobitNetwork.isHost)); if (null != MonobitNetwork.host) { GUILayout.Label(string.Format("Host : {0}", MonobitNetwork.host)); } GUILayout.Label(string.Format("IsLeader : {0}", MonobitNetwork.isLeader)); if (!MonobitNetwork.isHost) { if (GUILayout.Button("Change Host", GUILayout.Width(100))) { MonobitNetwork.ChangeHost(MonobitNetwork.player); } } foreach (MonobitPlayer otherPlayer in MonobitNetwork.otherPlayersList) { if (GUILayout.Button("Kick " + otherPlayer, GUILayout.Width(200))) { MonobitNetwork.Kick(otherPlayer); } } if (GUILayout.Button("Buffered RPC", GUILayout.Width(100))) { // RPCのBuffered確認用 monobitView.RPC("BufferedRPC", MonobitTargets.AllBuffered, MonobitNetwork.player.ID, battleEndFrame); } } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(100))) { // 安全なDisconnect bSafeDiscoonect = true; // 部屋から離脱する MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineSceneReconnect.SceneNameOffline); return; } // リーダーの場合 if (MonobitNetwork.isLeader) { // ゲームスタート前にゲームスタートするかどうか if (!m_bGameStart && GUILayout.Button("Start Game", GUILayout.Width(100))) { // ゲームスタートフラグを立てる m_bGameStart = true; // バトルスタートを通知 monobitView.RPC("OnGameStart", MonobitTargets.All, null); } // バトル終了 if (battleEndFrame <= 0) { // 安全なDisconnect bSafeDiscoonect = true; // ルームを抜ける MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineSceneReconnect.SceneNameOffline); return; } } // 意図しないタイミングで切断されたとき if (!MonobitNetwork.isConnect && !bSafeDiscoonect) { GUILayout.Window(0, new Rect(Screen.width / 2 - 100, Screen.height / 2 - 40, 200, 80), WindowGUI, "Disconnect"); } }
// GUI制御 private void OnGUI() { // MUNサーバに接続している場合 if (MonobitNetwork.isConnect) { // ルームに入室している場合 if (MonobitNetwork.inRoom) { //ルーム内のプレイヤー一覧の表示 GUILayout.BeginHorizontal(); GUILayout.Label("PlayerList : "); foreach (MonobitPlayer player in MonobitNetwork.playerList) { GUILayout.Label(player.name + " "); } GUILayout.EndHorizontal(); // ルームからの退室 if (GUILayout.Button("Leave Room", GUILayout.Width(150))) { MonobitNetwork.LeaveRoom(); chatLog.Clear(); } // チャット発言文の入力 GUILayout.BeginHorizontal(); GUILayout.Label("Message : "); chatWord = GUILayout.TextField(chatWord, GUILayout.Width(400)); GUILayout.EndHorizontal(); // チャット発言文を送信する if (GUILayout.Button("Send", GUILayout.Width(100))) { monobitView.RPC("RecvChat", MonobitTargets.All, MonobitNetwork.playerName, chatWord); chatWord = ""; } // チャットログを表示する string msg = ""; for (int i = 0; i < 10; ++i) { msg += ((i < chatLog.Count) ? chatLog[i] : "") + "\r\n"; } GUILayout.TextArea(msg); } // ルームに入室していない場合 else { // ルーム名入力 GUILayout.BeginHorizontal(); GUILayout.Label("RoomName : "); roomName = GUILayout.TextField(roomName, GUILayout.Width(200)); GUILayout.EndHorizontal(); // ルームを作成して入室する if (GUILayout.Button("CreateRoom", GUILayout.Width(150))) { MonobitNetwork.CreateRoom(roomName); } // ルーム一覧を検索 foreach (RoomData room in MonobitNetwork.GetRoomData()) { System.String roomParam = System.String.Format("{0}({1}/{2})", room.name, room.playerCount, ((room.maxPlayers == 0) ? "-" : room.maxPlayers.ToString()) ); // ルームを選択して入室する if (GUILayout.Button("Enter Room : " + roomParam)) { MonobitNetwork.JoinRoom(room.name); } } } } // MUNサーバに接続していない場合 else { // プレイヤー名の入力 GUILayout.BeginHorizontal(); GUILayout.Label("PlayerName : "); MonobitNetwork.playerName = GUILayout.TextField( (MonobitNetwork.playerName == null) ? "" : MonobitNetwork.playerName, GUILayout.Width(200)); GUILayout.EndHorizontal(); // デフォルトロビーへの自動入室を許可する MonobitNetwork.autoJoinLobby = true; // MUNサーバに接続する if (GUILayout.Button("ConnectServer", GUILayout.Width(150))) { MonobitNetwork.ConnectServer("SinpleChat_v1.0"); } } }
public void OnClickLeave() { MonobitNetwork.DisconnectServer(); }
private void OnGUI() { //MUNサーバに接続している場合 if (MonobitNetwork.isConnect) { //Debug.Log("サーバに接続しました"); // ルームに入室している場合 if (MonobitNetwork.inRoom) { } // ルームに入室していない場合 else { int x = Screen.width; int y = Screen.height; // ルーム名の入力 //UIの位置を中心に GUILayout.Space(y / 3.2f); GUILayout.BeginHorizontal(); { GUILayout.Space(x / 4.5f); GUI.skin.label.fontSize = x / 30; GUILayout.Label("部屋名・パスワードは4文字まで", GUILayout.Height(x / 20), GUILayout.Width(x / 2)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Space(x / 4); GUI.skin.label.fontSize = x / 50; GUILayout.Label("部屋名: ", GUILayout.Width(x / 8)); GUI.skin.textField.fontSize = x / 50; GUI.skin.button.fontSize = x / 50; roomName = GUILayout.TextField(roomName, GUILayout.Height(x / 40), GUILayout.Width(x / 3)); } GUILayout.EndHorizontal(); //パスワード欄 GUILayout.BeginHorizontal(); { GUILayout.Space(x / 5); GUILayout.Label("パスワード作成: ", GUILayout.Height(x / 40), GUILayout.Width(x * 7 / 40)); roomPasword = GUILayout.TextField(roomPasword, GUILayout.Height(x / 40), GUILayout.Width(x / 3)); } GUILayout.EndHorizontal(); // ルームを作成して入室する GUILayout.BeginHorizontal(); GUILayout.Space(x * 3 / 8); if (GUILayout.Button("部屋を作成", GUILayout.Height(x / 35), GUILayout.Width(x / 3))) { int a = roomName.Length; int b = roomPasword.Length; MonobitNetwork.CreateRoom(roomName + roomPasword + a + b); Debug.Log("ルームを作成しました"); /******** * ここでメインのシーンに遷移する *********/ SceneManager.LoadScene("newUI"); } GUILayout.EndHorizontal(); // ルーム一覧を検索 foreach (RoomData room in MonobitNetwork.GetRoomData()) { // ルームパラメータの可視化 System.String roomParam = System.String.Format( "{0}({1}/{2})", room.name, room.playerCount, ((room.maxPlayers == 0) ? "-" : room.maxPlayers.ToString()) ); string rn = room.name; string s1 = rn.Substring(rn.Length - 1); string s2 = rn.Substring(rn.Length - 2, 1); int i1 = int.Parse(s1); int i2 = int.Parse(s2); string s3 = rn.Substring(0, i2); string s4 = rn.Substring(i2, i1); //ルームパスワードと結びつけ GUILayout.BeginHorizontal(); { GUILayout.Space(x / 8); GUILayout.Label(s3 + "のパスワード解除: ", GUILayout.Height(x / 40), GUILayout.Width(x / 4)); roomUnrock = GUILayout.TextField(roomUnrock, GUILayout.Height(x / 40), GUILayout.Width(x / 3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(x * 3 / 8); // ルームを選択して入室する if (GUILayout.Button("部屋に入室 : " + s3, GUILayout.Height(x / 35), GUILayout.Width(x / 3))) { if (roomUnrock == s4) { MonobitNetwork.JoinRoom(room.name); /******** * ここでメインのシーンに遷移する *********/ SceneManager.LoadScene("newUI"); } else { Debug.Log("パスワードが違います"); } } GUILayout.EndHorizontal(); } } } //していない場合 else { int x = Screen.width; int y = Screen.height; // プレイヤー名の入力 GUILayout.Space(y / 2.3f); GUILayout.BeginHorizontal(); { GUILayout.Space(x / 4); GUILayout.Label("名前入力 : ", GUILayout.Width(x / 8)); GUI.skin.label.fontSize = x / 50; GUI.skin.textField.fontSize = x / 50; GUI.skin.button.fontSize = x / 50; MonobitNetwork.playerName = GUILayout.TextField( (MonobitNetwork.playerName == null) ? "" : MonobitNetwork.playerName, GUILayout.Height(x / 40), GUILayout.Width(x / 3)); } GUILayout.EndHorizontal(); // デフォルトロビーへの自動入室を許可する MonobitNetwork.autoJoinLobby = true; // MUNサーバに接続する GUILayout.BeginHorizontal(); GUILayout.Space(x * 3 / 8); if (GUILayout.Button("サーバに接続", GUILayout.Height(x / 35), GUILayout.Width(x / 3))) { MonobitNetwork.ConnectServer("SimpleChat_v1.0"); Debug.Log("サーバに接続しました"); } GUILayout.EndHorizontal(); } }
// タイトル画面へ戻る public void OnClickBack() { MonobitNetwork.DisconnectServer(); }
/** * @brief 更新関数. */ void Update() { // ゲーム中の処理 if (isGameStart && !isGameEnd) { // まだ自分のキャラクタのspawnが終わっていない状態であれば、自身のキャラクタをspawnする if (!isSpawnMyChara) { OnGameStart(); } // 自身のキャラクタ位置の退避 if (myObject != null) { myPosition = myObject.transform.position; myRotation = myObject.transform.rotation; } // ルーム名の退避 if (MonobitNetwork.room != null) { reconnectRoomName = MonobitNetwork.room.name; } // ホストの場合の処理 if (MonobitNetwork.isHost) { // アイテムに接近したら、アイテム取得処理を実行する if (gameItemRakeupCount < gameItemLimit) { for (int index = itemObject.Count - 1; index >= 0; --index) { foreach (SD_Unitychan_PC playerObject in s_PlayerObject) { if ((playerObject.transform.position - itemObject[index].transform.position).magnitude < 1.0f) { // そのオブジェクトを削除する MonobitNetwork.Destroy(itemObject[index]); itemObject.Remove(itemObject[index]); // 自身のスコア情報を加算するRPC処理を実行する monobitView.RPC("OnUpdateScore", MonobitTargets.All, playerObject.GetPlayerID(), playerObject.MyScore + 100); gameItemRakeupCount++; } } } } else { // ゲーム終了メッセージを送信 monobitView.RPC("OnGameEnd", MonobitTargets.All, null); } // 制限時間の減少 if (gameTimeLimit > 0) { gameTimeLimit--; } else { // ゲーム終了メッセージを送信 monobitView.RPC("OnGameEnd", MonobitTargets.All, null); } // 個数制限&時間制限のタイミングで、ゲームシーン上にオブジェクトを配置 if ((gameItemIsPut < gameItemLimit) && (gameTimeLimit % 10 == 0)) { // ある程度ランダムな位置・姿勢でプレイヤーを配置する Vector3 position = Vector3.zero; position.x = UnityEngine.Random.Range(-10.0f, 10.0f); position.z = UnityEngine.Random.Range(-10.0f, 10.0f); Quaternion rotation = Quaternion.AngleAxis(UnityEngine.Random.Range(-180.0f, 180.0f), Vector3.up); // オブジェクトの配置(他クライアントにも同時にInstantiateする) MonobitNetwork.InstantiateSceneObject("item", position, rotation, 0, null); // ゲームオブジェクト出現個数を加算 gameItemIsPut++; } // 制限時間をRPCで送信 monobitView.RPC("TickCount", MonobitTargets.Others, gameTimeLimit); } } }
// MUNサーバーとの接続に成功した際に呼ばれる接続コールバック public void OnConnectedToMonobit() { Debug.Log("接続しました"); MonobitNetwork.JoinLobby(); }
private void OnDestroy() { MonobitNetwork.LeaveRoom(); }
void OnJoinedLobby() { Debug.Log("OnJoinedLobby"); MonobitNetwork.JoinOrCreateRoom(roomName, new RoomSettings(), LobbyInfo.Default); }
// Update is called once per frame public void Update() { if (monobitView.isMine) { if (monobitView.isMine) { // キャラクタの移動&アニメーション切り替え if (currentAnimId == 3) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") || animator.GetCurrentAnimatorStateInfo(0).normalizedTime <= 0.55) { gameObject.transform.position += jumpFixedSpeed; } else { jumpFixedSpeed = Vector3.zero * Time.deltaTime; gameObject.transform.position += jumpFixedSpeed; currentAnimId = 0; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); } } else if (currentAnimId == 4) { if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion") && animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.90) { jumpFixedSpeed = Vector3.zero * Time.deltaTime; gameObject.transform.position += jumpFixedSpeed; currentAnimId = 0; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); } } else if (Input.GetButtonDown("Jump")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { gameObject.transform.position += jumpFixedSpeed; currentAnimId = 3; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); } } else if (Input.GetKeyDown("z")) { if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Stand")) { jumpFixedSpeed = Vector3.zero * Time.deltaTime; gameObject.transform.position += jumpFixedSpeed; currentAnimId = 4; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); } } else if (Input.GetKey("up")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Stand") || animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Walk")) { jumpFixedSpeed = gameObject.transform.forward * 1.5f * Time.deltaTime; } else { jumpFixedSpeed = gameObject.transform.forward * 3.0f * Time.deltaTime; } gameObject.transform.position += jumpFixedSpeed; currentAnimId = 1; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); } } else if (Input.GetKey("down")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { jumpFixedSpeed = gameObject.transform.forward * -0.1f * Time.deltaTime; gameObject.transform.position += jumpFixedSpeed; currentAnimId = 2; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime <= 0.0f) { animator.Play(Animator.StringToHash("Walking@loop"), 0, 1.0f); } } } else { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { jumpFixedSpeed = Vector3.zero * Time.deltaTime; gameObject.transform.position += jumpFixedSpeed; currentAnimId = 0; animator.SetInteger(animId, currentAnimId); animator.SetFloat(moveSpeed, jumpFixedSpeed.magnitude); ChangeFace("default@sd_generic"); } } if (Input.GetKey("right")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { gameObject.transform.Rotate(0, 30.0f * Time.deltaTime, 0); } } if (Input.GetKey("left")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { gameObject.transform.Rotate(0, -30.0f * Time.deltaTime, 0); } } if (Input.GetKeyDown("x")) { if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump") && !animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Emotion")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0); } } animator.SetLayerWeight(1, currentFace); monobitView.RPC("SetFaceID", MonobitTargets.OthersBuffered, currentAnimId, currentFace, currentFaceName); } else { animator.SetInteger(animId, currentAnimId); animator.SetLayerWeight(1, currentFace); foreach (var animation in animations) { if (currentFaceName == animation.name) { ChangeFace(currentFaceName); } } } } }
static void CleanupMunHideInHierarchyObject() { MonobitNetwork.CleanupMunHideInHierarchyObject(); }
/** * @brief オフライン中のGUI表示. * @param isDispInputGUI 入力系GUIを表示するかどうかのフラグ(縁取り文字描画機能を活かした場合の、多重描画を防止するため). * @param state 文字表示色. */ private void OnGUI_Offline(bool isDispInputGUI, GUIStyleState state) { // プレイヤー名入力GUIレイヤー { // Header GUILayout.Label("Player Name Entry", new GUIStyle() { normal = state, fontSize = 24 }); GUILayout.BeginHorizontal(); GUILayout.Space(25); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); { // プレイヤー名の入力欄の表示 GUILayout.Label("Input player name:", new GUIStyle() { normal = state, fontSize = 16, margin = new RectOffset(6, 6, 6, 6), fixedWidth = 140 }); if (isDispInputGUI) { MonobitNetwork.playerName = GUILayout.TextField((MonobitNetwork.playerName == null) ? "" : MonobitNetwork.playerName, GUILayout.Width(150)); } // サーバ接続ボタン入力表示 if (isDispInputGUI) { if (GUILayout.Button("Connect Server", GUILayout.Width(150))) { // 名前欄が空欄であれば、GUIDで生成したプレイヤー名でサーバに接続 if (MonobitNetwork.playerName == null || MonobitNetwork.playerName.Length <= 0) { MonobitNetwork.playerName = Guid.NewGuid().ToString(); } // デフォルトロビーへの強制入室をONにする。 MonobitNetwork.autoJoinLobby = true; // デバッグログ出力を無効にする MonobitNetwork.LogLevel = MonobitLogLevel.Informational; // まだ未接続の場合、MonobitNetworkに接続する。 if (!MonobitNetwork.isConnect) { isDisconnecting = false; isReconnecting = false; isGameStart = false; isGameEnd = false; MonobitNetwork.ConnectServer("RakeupGame_ServerSide_v1.0"); } } } } GUILayout.EndHorizontal(); // Footer GUILayout.EndVertical(); GUILayout.EndHorizontal(); } }
void DoAction(MonobitKeySettings settings, float keyActiveValue) { switch (settings.actionType) { case ActionType.Move: gameObject.transform.position += gameObject.transform.right * settings.Position.x * keyActiveValue; gameObject.transform.position += gameObject.transform.up * settings.Position.y * keyActiveValue; gameObject.transform.position += gameObject.transform.forward * settings.Position.z * keyActiveValue; break; case ActionType.Rotate: gameObject.transform.Rotate(settings.Rotation * keyActiveValue); break; case ActionType.ChangeAnimLayerWeight: if (animView != null && animView.m_Animator != null) { AnimLayerInfo info = settings.layerInfo[settings.SelectLayer]; animView.m_Animator.SetLayerWeight(info.m_Index, info.m_animWeight * keyActiveValue); } break; case ActionType.ChangeAnimParam: if (keyActiveValue > 0.0f) { if (animView != null && animView.m_Animator != null) { AnimParamInfo info = settings.paramInfo[settings.SelectParam]; switch (info.m_Type) { case MonobitAnimatorView.AnimatorControllerParameterType.Bool: animView.m_Animator.SetBool(info.m_Name, info.m_boolValue); break; case MonobitAnimatorView.AnimatorControllerParameterType.Float: animView.m_Animator.SetFloat(info.m_Name, info.m_floatValue * keyActiveValue); break; case MonobitAnimatorView.AnimatorControllerParameterType.Int: animView.m_Animator.SetInteger(info.m_Name, (int)(info.m_intValue * keyActiveValue)); break; case MonobitAnimatorView.AnimatorControllerParameterType.Trigger: break; } } } break; case ActionType.Instantiate: if (keyActiveValue >= 1.0f) { switch (settings.instantiateType) { case InstantiateType.Absolute: { Quaternion rotation = Quaternion.Euler(settings.Rotation); MonobitNetwork.Instantiate(settings.instantiatePrefab.name, settings.Position, rotation, 0); } break; case InstantiateType.Relative: { Vector3 position = gameObject.transform.position; position += gameObject.transform.right * settings.Position.x; position += gameObject.transform.up * settings.Position.y; position += gameObject.transform.forward * settings.Position.z; Quaternion rotation = gameObject.transform.rotation * Quaternion.Euler(settings.Rotation); MonobitNetwork.Instantiate(settings.instantiatePrefab.name, position, rotation, 0); } break; case InstantiateType.RandomAbsolute: { Vector3 position = new Vector3(UnityEngine.Random.Range(settings.PositionMin.x, settings.PositionMax.x), UnityEngine.Random.Range(settings.PositionMin.y, settings.PositionMax.y), UnityEngine.Random.Range(settings.PositionMin.z, settings.PositionMax.z)); Quaternion rotation = Quaternion.Euler(UnityEngine.Random.Range(settings.RotationMin.x, settings.RotationMax.x), UnityEngine.Random.Range(settings.RotationMin.y, settings.RotationMax.y), UnityEngine.Random.Range(settings.RotationMin.z, settings.RotationMax.z)); MonobitNetwork.Instantiate(settings.instantiatePrefab.name, position, rotation, 0); } break; } } break; } }
/** * GUI制御. */ void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // MUNサーバに接続している場合 if (MonobitNetwork.isConnect) { // ルームに入室している場合 if (MonobitNetwork.inRoom) { // ルーム内のプレイヤー一覧の表示 GUILayout.BeginHorizontal(); GUILayout.Label("PlayerList : "); foreach (MonobitPlayer player in MonobitNetwork.playerList) { GUILayout.Label(player.name + " "); } GUILayout.EndHorizontal(); // ルームからの退室 if (GUILayout.Button("Leave Room", GUILayout.Width(150))) { MonobitNetwork.LeaveRoom(); } if (myVoice != null) { // 送信タイプの設定 GUILayout.BeginHorizontal(); GUILayout.Label("VoiceChat Send Type : "); Int32 streamType = myVoice.SendStreamType == StreamType.BROADCAST ? 0 : 1; myVoice.SendStreamType = (StreamType)GUILayout.Toolbar(streamType, new string[] { "broadcast", "multicast" }); GUILayout.EndHorizontal(); // マルチキャスト送信の場合の、ボイスチャットの送信可否設定 if (myVoice.SendStreamType == StreamType.MULTICAST) { List <MonobitPlayer> playerList = new List <MonobitPlayer>(vcPlayerInfo.Keys); List <MonobitPlayer> vcTargets = new List <MonobitPlayer>(); foreach (MonobitPlayer player in playerList) { // GUI による送信可否の切替 GUILayout.BeginHorizontal(); GUILayout.Label("PlayerName : " + player.name + " "); GUILayout.Label("Send Permission: "); vcPlayerInfo[player] = GUILayout.Toolbar(vcPlayerInfo[player], new string[] { "Allow", "Deny" }); GUILayout.EndHorizontal(); // ボイスチャットの送信可のプレイヤー情報を登録する if (vcPlayerInfo[player] == (Int32)EnableVC.ENABLE) { vcTargets.Add(player); } } // ボイスチャットの送信可否設定を反映させる myVoice.SetMulticastTarget(vcTargets.ToArray()); } } } // ルームに入室していない場合 else { // ルーム名の入力 GUILayout.BeginHorizontal(); GUILayout.Label("RoomName : "); roomName = GUILayout.TextField(roomName, GUILayout.Width(200)); GUILayout.EndHorizontal(); // ルームを作成して入室する if (GUILayout.Button("Create Room", GUILayout.Width(150))) { MonobitNetwork.CreateRoom(roomName); } // ルーム一覧を検索 foreach (RoomData room in MonobitNetwork.GetRoomData()) { // ルームを選択して入室する if (GUILayout.Button("Enter Room : " + room.name + "(" + room.playerCount + "/" + ((room.maxPlayers == 0) ? "-" : room.maxPlayers.ToString()) + ")")) { MonobitNetwork.JoinRoom(room.name); } } } } // MUNサーバに接続していない場合 else { // プレイヤー名の入力 GUILayout.BeginHorizontal(); GUILayout.Label("PlayerName : "); MonobitNetwork.playerName = GUILayout.TextField((MonobitNetwork.playerName == null) ? "" : MonobitNetwork.playerName, GUILayout.Width(200)); GUILayout.EndHorizontal(); // デフォルトロビーへの自動入室を許可する MonobitNetwork.autoJoinLobby = true; // MUNサーバに接続する if (GUILayout.Button("Connect Server", GUILayout.Width(150))) { MonobitNetwork.ConnectServer("SimpleVoiceChat_v1.0"); } } }
// Update is called once per frame public void Update() { if (monobitView.isOwner) { // キャラクタの移動&アニメーション切り替え if (Input.GetKey("up")) { gameObject.transform.position += gameObject.transform.forward * 0.1f; animator.SetInteger(animId, 1); } else { animator.SetInteger(animId, 0); } if (Input.GetKey("right")) { gameObject.transform.Rotate(0, 2.0f, 0); } if (Input.GetKey("left")) { gameObject.transform.Rotate(0, -2.0f, 0); } if (Input.GetKeyDown("z")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0); } if (Input.GetKeyDown("s")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0, null, true, false, true); } if (Input.GetKeyDown("e")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0, null, true, false, false); } if (Input.GetKeyDown("d")) { UnityEngine.Debug.Log("Destroy Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } MonobitNetwork.Destroy(go); if (!view.enabled) { UnityEngine.Debug.Log("Destroy Cube: " + view); } } UnityEngine.Debug.Log("Destroy Cube End"); } if (Input.GetKeyDown("r")) { UnityEngine.Debug.Log("RequestOwnership Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } view.RequestOwnership(); UnityEngine.Debug.Log("RequestOwnership Cube: " + view); } UnityEngine.Debug.Log("RequestOwnership Cube End"); } if (Input.GetKeyDown("t")) { UnityEngine.Debug.Log("TransferOwnership Cube Start"); int playerId = MonobitNetwork.player.ID; foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } view.TransferOwnership(playerId); UnityEngine.Debug.Log("TransferOwnership Cube: " + view); } UnityEngine.Debug.Log("TransferOwnership Cube End"); } if (Input.GetKeyDown("i")) { UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } bool isDontDestroyOnRoom = view.isDontDestroyOnRoom; view.isDontDestroyOnRoom = !isDontDestroyOnRoom; if (isDontDestroyOnRoom != view.isDontDestroyOnRoom) { UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube: " + view + " " + isDontDestroyOnRoom + " -> " + view.isDontDestroyOnRoom); } } UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube End"); } if (Input.GetKeyDown("0")) { serializeBytes[0] = 0; } if (Input.GetKeyDown("1")) { serializeBytes[0] = 1; } } }
// GUI処理 void OnGUI() { // GUI用の解像度を調整する Vector2 guiScreenSize = new Vector2(800, 480); if (Screen.width > Screen.height) { // landscape GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.x, Screen.height / guiScreenSize.y), Vector2.zero); } else { // portrait GUIUtility.ScaleAroundPivot(new Vector2(Screen.width / guiScreenSize.y, Screen.height / guiScreenSize.x), Vector2.zero); } // プレイヤーIDの表示 if (MonobitNetwork.player != null) { GUILayout.Label(string.Format("My Player ID : {0}", MonobitNetwork.player.ID)); } // ルーム情報の取得 Room room = MonobitNetwork.room; if (room != null) { // ルーム名の表示 GUILayout.Label(string.Format("Room Name : {0}", room.name)); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label(string.Format("PlayerCount : {0}", room.playerCount)); // ルームがオープンかクローズか GUILayout.Label(string.Format("Room IsOpen : {0}", room.open)); // 制限時間の表示 if (m_bGameStart) { GUILayout.Label(string.Format("Rest Frame : {0}", this.battleEndFrame)); } GUILayout.Label(string.Format("IsHost : {0}", MonobitNetwork.isHost)); if (null != MonobitNetwork.host) { GUILayout.Label(string.Format("Host : {0}", MonobitNetwork.host)); } GUILayout.Label(string.Format("IsLeader : {0}", MonobitNetwork.isLeader)); if (!MonobitNetwork.isHost) { if (GUILayout.Button("Change Host", GUILayout.Width(100))) { MonobitNetwork.ChangeHost(MonobitNetwork.player); } } foreach (MonobitPlayer otherPlayer in MonobitNetwork.otherPlayersList) { if (GUILayout.Button("Kick " + otherPlayer, GUILayout.Width(200))) { MonobitNetwork.Kick(otherPlayer); } } if (GUILayout.Button("Buffered RPC", GUILayout.Width(100))) { // RPCのBuffered確認用 monobitView.RPC("BufferedRPC", MonobitTargets.AllBuffered, MonobitNetwork.player.ID, battleEndFrame); } } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(100))) { // 安全なDisconnect bSafeDiscoonect = true; // 部屋から離脱する MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineSceneReconnect.SceneNameOffline); return; } // リーダーの場合 if (MonobitNetwork.isLeader) { // ゲームスタート前にゲームスタートするかどうか if (!m_bGameStart && GUILayout.Button("Start Game", GUILayout.Width(100))) { // ゲームスタートフラグを立てる m_bGameStart = true; // バトルスタートを通知 monobitView.RPC("OnGameStart", MonobitTargets.All, null); } // バトル終了 if (battleEndFrame <= 0) { // 安全なDisconnect bSafeDiscoonect = true; // ルームを抜ける MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineSceneReconnect.SceneNameOffline); return; } } // 意図しないタイミングで切断されたとき if (!MonobitNetwork.isConnect && !bSafeDiscoonect) { GUILayout.Window(0, new Rect(Screen.width / 2 - 100, Screen.height / 2 - 40, 200, 80), WindowGUI, "Disconnect"); } }
/** * ルーム内でのGUI操作. */ private void OnGUI_InRoom() { // 自身のプレイヤーIDの表示 GUILayout.Label("Your ID : " + MonobitNetwork.player.ID); // ルーム内に存在するプレイヤー数の表示 GUILayout.Label("PlayerCount : " + MonobitNetwork.room.playerCount + " / " + ((MonobitNetwork.room.maxPlayers == 0) ? "-" : MonobitNetwork.room.maxPlayers.ToString())); // ルームの入室制限可否設定の表示 GUILayout.Label("Room isOpen : " + MonobitNetwork.room.open); // ルーム作成者が入力した値 GUILayout.Label("Room Owner Numeric Value : " + MonobitNetwork.room.customParameters["Value"]); // 自身が入力した値 GUILayout.Label("My Skill Level : " + baseValue); // 制限時間の表示 if (isGameStart) { GUILayout.Label("Rest Frame : " + this.battleEndFrame); } // 部屋からの離脱 if (GUILayout.Button("Leave Room", GUILayout.Width(150))) { MonobitNetwork.LeaveRoom(); } // ホストの場合 if (MonobitNetwork.isHost) { // ゲームスタート if (!isGameStart && GUILayout.Button("Start Game", GUILayout.Width(150))) { this.isGameStart = true; // room.open = false; monobitView.RPC("GameStart", MonobitTargets.All, null); } // バトル終了 if (this.battleEndFrame <= 0) { // room.open = true; // 部屋から離脱する monobitView.RPC("LeaveRoomAll", MonobitTargets.All, null); } } // 他にルームが作成されている場合 if (MonobitNetwork.GetRoomData() != null && MonobitNetwork.GetRoomData().Length >= 1) { // 他の部屋に入室 if (GUILayout.Button("Enter Another Room", GUILayout.Width(150))) { // 一旦部屋から離脱する MonobitNetwork.LeaveRoom(); // 自身の値に対し、検索範囲の最初の閾値を設定する baseValueMin = (baseValue - baseValueIncrease < baseValueLow) ? baseValueLow : baseValue - baseValueIncrease; baseValueMax = (baseValue + baseValueIncrease > baseValueHigh) ? baseValueHigh : baseValue + baseValueIncrease; // 閾値から、クエリー検索のためのWHERE句を生成する string queryLobbyFilter = "Value>=" + baseValueMin + " AND Value<=" + baseValueMax; // ルームへの入室 MonobitNetwork.JoinRandomRoom(null, this.maxPlayers, Definitions.MatchmakingMode.SerialMatching, new LobbyInfo() { Kind = LobbyKind.Query, Name = "QueryLobby" }, queryLobbyFilter); } } }