void OnGameEnd() { Debug.Log("OnGameEnd"); // 一旦切断する MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineScene.SceneNameOffline); }
void Update() { if (this.player == null && MonobitNetwork.inRoom) { if (MonobitNetwork.isHost) { // ボス作成 MonobitNetwork.Instantiate( "Dragon", this.bossEnemyPoint.position, this.bossEnemyPoint.rotation, 0, null, false, false, false ); } var shiftVector = new Vector3(MonobitNetwork.room.playerCount * 1.5f, 0.0f); this.player = MonobitNetwork.Instantiate("Player", this.startPoint.position + shiftVector, this.startPoint.rotation, 0); this.followCamera.SetTarget(this.player.transform); Debug.Log($"Create player: {MonobitNetwork.playerName}, call {nameof(CharacterStatus.SetName)}()"); this.player.BroadcastMessage(nameof(CharacterStatus.SetName), MonobitNetwork.playerName); } if (this.gameClear || this.gameOver) { this.sceneChangeTime -= Time.deltaTime; if (this.sceneChangeTime <= 0.0f) { this.sceneChangeTime = 3.0f; this.player = null; // TODO: 接続維持してリトライしたい MonobitNetwork.DisconnectServer(); SceneManager.LoadScene("TitleScene"); } return; } if (MonobitNetwork.inRoom) { this.timeRemaining -= Time.deltaTime; // 残り時間が無くなったらゲームオーバー if (this.timeRemaining <= 0.0f) { this.GameOver(); } } }
void OnClickExitButton() { if (MonobitNetwork.inLobby) { MonobitNetwork.DisconnectServer(); } #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #elif UNITY_STANDALONE UnityEngine.Application.Quit(); #endif }
// GUI制御 private void OnGUI() { if (!MonobitNetwork.inRoom) { return; } //ルーム内のプレイヤー一覧の表示 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.DisconnectServer(); 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); }
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); } if (bSelectMenu == false) { if (!MonobitNetwork.isConnect) { if (GUILayout.Button("Connect", GUILayout.Width(150))) { bSelectMenu = true; MonobitNetwork.autoJoinLobby = true; MonobitNetwork.ConnectServer("MonobitAutoLoginTemplete_v0.1"); } } else if (MonobitNetwork.inRoom) { if (!bStart) { if (GUILayout.Button("GameStart", GUILayout.Width(150))) { bSelectMenu = true; monobitView.RPC("GameStart", MonobitTargets.All, null); } } else { if (GUILayout.Button("Disconnect", GUILayout.Width(150))) { MonobitNetwork.DisconnectServer(); } } } } }
/// <summary> /// 接続待ち処理 /// </summary> /// <param name="roomname"></param> /// <returns></returns> private IEnumerator WaitConnectedCoroutine(string playerName, 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(playerName, roomname)); } } else { MonobitNetwork.DisconnectServer(); MonobitNetwork.playerName = playerName; MonobitNetwork.autoJoinLobby = true; MonobitNetwork.ConnectServer("SimpleVoiceChat_v1.0"); Debug.Log("VC_WaitConnected..."); yield return(new WaitForSecondsRealtime(1.0f)); StartCoroutine(WaitConnectedCoroutine(playerName, roomname)); } }
// 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"); } }
// タイトル画面へ戻る public void OnClickBack() { MonobitNetwork.DisconnectServer(); }
// 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"); } }
public void OnClickLeave() { MonobitNetwork.DisconnectServer(); }
// 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]); } } } }
private void OnGUI() { // デフォルトのボタンと被らないように、段下げを行なう。 GUILayout.Space(24); // MUNサーバに接続している場合 if (MonobitNetwork.isConnect) { // ボタン入力でサーバから切断&シーンリセット if (GUILayout.Button("Disconnect", GUILayout.Width(150))) { // サーバから切断する MonobitNetwork.DisconnectServer(); // シーンをリロードする #if UNITY_5_3_OR_NEWER || UNITY_5_3 string sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName); #else Application.LoadLevel(Application.loadedLevelName); #endif } // ルームに入室している場合 if (MonobitNetwork.inRoom) { // ボタン入力でルームから退室 if (GUILayout.Button("Leave Room", GUILayout.Width(150))) { MonobitNetwork.LeaveRoom(); } } // ルームに入室していない場合 if (!MonobitNetwork.inRoom) { GUILayout.BeginHorizontal(); // ルーム名の入力 GUILayout.Label("RoomName : "); roomName = GUILayout.TextField(roomName, GUILayout.Width(200)); // ボタン入力でルーム作成 if (GUILayout.Button("Create Room", GUILayout.Width(150))) { MonobitNetwork.CreateRoom(roomName); } GUILayout.EndHorizontal(); // 現在存在するルームからランダムに入室する if (GUILayout.Button("Join Random Room", GUILayout.Width(200))) { MonobitNetwork.JoinRandomRoom(); } // ルーム一覧から選択式で入室する foreach (RoomData room in MonobitNetwork.GetRoomData()) { string strRoomInfo = string.Format("{0}({1}/{2})", room.name, room.playerCount, (room.maxPlayers == 0) ? "-" : room.maxPlayers.ToString()); if (GUILayout.Button("Enter Room : " + strRoomInfo)) { MonobitNetwork.JoinRoom(room.name); } } } } }
// 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))) { // 安全なDisconnect bSafeDiscoonect = true; // 部屋から離脱する MonobitNetwork.DisconnectServer(); // シーンをオフラインシーンへ MonobitNetwork.LoadLevel(OfflineSceneReconnect.SceneNameOffline); return; } // ホストの場合 if (MonobitNetwork.isHost) { // ゲームスタート前にゲームスタートするかどうか 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"); } }
/// <summary>タイトル画面へ戻るボタンを押した際に呼ばれる</summary> void OnClickBack() { // サーバーから切断する MonobitNetwork.DisconnectServer(); }