ãUnity9ã表示ããGUI(Network Manager)ãæ©è½ãããï¼ãUNET20-2ã
Unity5.1.1p3 Personal(2015å¹´7æ)
前回の続きã§ãã
æ°ããGUIã®ä½æãå®äºããã®ã§ããã¿ã³ãæ¼ãçããæã«å¦çãçºçããããã«ãã¦ããã¾ãã
UNET Part 20 - UI & Custom Net Manager - YouTube
ãç®æ¨ã表示ããGUIã«å¦çãä¸ããï¼
â OnClickã®è¨å®
ããã§ã¯ãã¿ã³ã®è¨å®ããã¦ããã¾ãã
ã¾ãã¯Menuã·ã¼ã³ãéããButtonStartHostã®Inspectorãã¥ã¼ãè¦ã¦ä¸ããã
Buttonã³ã³ãã¼ãã³ãã®ä¸çªä¸ã«OnClickã¨ããç®æãããã®ã§ããã©ã¹ãã¿ã³ãæ¼ããNetworkManagerãªãã¸ã§ã¯ããæå®ããã¤ãã³ãã¨ãã¦NetworkManager_Custom > StartupHostãé¸æãã¾ãã
ButtonJoinGameãåãããã«è¨å®ãã¾ãã
ã¤ãã³ãã ãNetworkManager_Custom > ãJoinGameã«å¤æ´ãã¾ãã
ããã§ãã¿ã³ãæ¼ããæã«ãã¹ãã¨ã¯ã©ã¤ã¢ã³ãã¨ãã¦æ¥ç¶ã§ããããã«ãªãã¾ããã
â¡Sceneãã¼ãæã®ãã¿ã³è¨å®
ç¶ãã¦Sceneããã¼ãããæã®è¨å®ããååä½æããNetworkManager_Customã¹ã¯ãªããã«è¿½è¨ãã¦ããã¾ãã以ä¸ã½ã¼ã¹ã§ãã
using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; using System.Collections; public class NetworkManager_Custom : NetworkManager { public void StartupHost() { SetPort(); NetworkManager.singleton.StartHost(); } public void JoinGame() { SetIPAddress(); SetPort(); NetworkManager.singleton.StartClient(); } void SetIPAddress() { string ipAddress = GameObject.Find("InputFieldIPAddress").transform.FindChild("Text").GetComponent<Text>().text; NetworkManager.singleton.networkAddress = ipAddress; } void SetPort () { NetworkManager.singleton.networkPort = 7777; } //********** éå§ **********// //Unityããã©ã«ãã®API ã·ã¼ã³ããã¼ãããæã«levelãå¼æ°ã«å®è¡ //åã·ã¼ã³ã®levelã¯Build Settingsã«ã¦è¨å® void OnLevelWasLoaded (int level) { if (level == 0) { //Menuã·ã¼ã³ã¸ç§»åããå ´å SetupMenuSceneButtons(); } else { //ä»ã®ã·ã¼ã³(Mainã·ã¼ã³)ã¸ç§»åããå ´å SetupOtherSceneButtons(); } } void SetupMenuSceneButtons() { //RemoveListener: Buttonã®ã¤ãã³ããåé¤ãã //AddListener: ãã¿ã³ã®ã¤ãã³ããç»é²ãã GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.RemoveAllListeners(); GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.AddListener(StartupHost); GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.RemoveAllListeners(); GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame); } void SetupOtherSceneButtons() { //Disconnectãã¿ã³ã«StopHostã¡ã½ãããç»é²ãã GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.RemoveAllListeners(); GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(NetworkManager.singleton.StopHost); } //********** çµäº **********// }
NetworkManager_Custom.cs
OnLevelWasLoadedã¡ã½ããã¯ãSceneããã¼ããããæã«Sceneã®levelãå¼æ°ã«å®è¡ãããã¡ã½ããã§ãã
Build Settingsã®å³å´ã«ããæ°åãlevelã§ãã
Menuã0ãMainã1ã¨ãªã£ã¦ãã
Menuã·ã¼ã³ã¸ç§»åããæã«SetupMenuSceneButtonsã¡ã½ãããå®è¡ãããRemoveAllListenersã«ãã£ã¦å ¨ã¦ã®OnClickã¤ãã³ããåé¤ãããAddListenerã«ãã£ã¦æå®ããã¤ãã³ããç»é²ããã¾ãã
Mainã·ã¼ã³ã¸ç§»åããæãåæ§ã§ãDisconnectãã¿ã³ã«ã¤ãã³ããç»é²ããã¾ãã
æå¾ã«NetworkManagerã«ã¤ãã¦ããNetworkManagerHUDã³ã³ãã¼ãã³ããéã¢ã¯ãã£ãåãã¦ããã¾ãã
ãã§ãã¯ãå¤ãã¦éã¢ã¯ãã£ãå
â¢çµæ
ããã§ã¯ã²ã¼ã ãå®è¡ãã¦ã¿ã¾ãããã
ã²ã¼ã ç»é¢(Build)ã§ãã¹ãã¨ãã¦æ¥ç¶ãã¾ãã
ã²ã¼ã ãå®è¡ããã¾ãã
ã²ã¼ã ç»é¢(éçº)ã§ã¯ã©ã¤ã¢ã³ãã¨ãã¦æ¥ç¶ãã¾ãã
ã¯ã©ã¤ã¢ã³ãã¨ãã¦ã²ã¼ã ã¸åå ã§ãã¾ãã
Disconnectãã¿ã³ãæ¼ãã¨Menuã·ã¼ã³ã¸æ»ããå度æ¥ç¶ãããã¨ãã§ãã¾ããï¼HostãDisconnectãã¿ã³ãæ¼ãã¨ãã¯ã©ã¤ã¢ã³ããè½ã¡ã¾ããï¼
ãªãã¨ãæ°ããGUIã§æ¥ç¶ãããã¨ãã§ãã¾ããã
IPã¢ãã¬ã¹ã«ã¤ãã¦ã¯LogMeIN Hamachiã¨ããVPNæ§ç¯ã½ããã使ã£ã¦å¤æ´ã§ããã¨ãã解説ãããã¦ãã¾ãã®ã§ã試ãããã¨ããæ¹ã¯èªå·±è²¬ä»»ã§ãããããé¡ãè´ãã¾ãã
ããã§ã¯ãä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ãUnity9ãUNETã§ãã«ããã¬ã¤ã¤ã¼ãªãªã³ã©ã¤ã³ã²ã¼ã éçºãUNET1ã
ãUnity9ãUNETã§ãã¬ã¤ã¤ã¼ã®åããè£éãããªããããªåããå®ç¾ãããUNET1-2ã
ãUnity9ãUNETã§ãããã¯ã¼ã¯è¶ãã«å¾ã(Rotation)ãåæããããUNET2ã
ãUnity9ãUNETã§ãªã³ã©ã¤ã³éå§æã®ãã¬ã¤ã¤ã¼çæä½ç½®ãå¤æ´ãããUNET2-2ã
ãUnity9ãUNETã®ãããã¯ã¼ã¯ãã©ãã£ãã¯ã軽æ¸ããå¹çåãããUNET3ã
ãUnity9ãUNETã®latency(é
延æé)ãæ¹åãããUNET4ã
ãUnity9ãUNETã®latency(é
延æé)ã表示ãã¦ãã¡ãã£ã¨ã ãæ¹åãããUNET4-2ã
ãUnity9ãUNETã®SyncVarã®hookã®ä½¿ç¨ä¾ã¨ãåæ代ã®åææ¹æ³ãUNET5ã
ãUnity9ãUNETã使ã£ã¦RotationãåæããããUNET6ã
ãUnity9ãUNETã§åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãããUNET7ã
ãUnity9ãUNETã§æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããï¼ãUNET8ã
ãUnity9ãUNETã§HPãç»é¢ã«è¡¨ç¤ºããPlayerã¸ãã¡ã¼ã¸ãä¸ãããUNET9ã
ãUnity9ãUNETã§HPã0以ä¸ã«ãªã£ãæãPlayerãç ´å£ããï¼ãUNET10ã
ãUnity9ãUNETã§æ»ãã Playerãçãè¿ãããï¼ãUNET11ã
ãUnity9ãUNETã§ã¾ã³ãAIãåºç¾ãããï¼ãUNET12ã
ãUnity9ãUNETã§ã¾ã³ãçææã«ã¦ãã¼ã¯ãªIDãä»ããï¼ãUNET13ã
ãUnity9ãUNETã§ã¾ã³ããæã¤ï¼ãUNET14ã
ãUnity9ãUNETã§ã¾ã³ãã«æ»æãããï¼ãUNET15ã
ãUnity9ãUNETã§ã¾ã³ãã®åããã¹ã ã¼ãºã«ã·ã³ã¯ããããï¼ãUNET16ã
ãUnity9ãUNETã§ã¾ã³ãçºçå°ç¹ãå¢ãããUNET17ã
ãUnity9ãUNETã§çºçãããã°ãåãé¤ããUNET18ã
ãUnity9ãUnity MultiPlayerã使ã£ã¦ãããã¯ã¼ã¯è¶ãã«ãããã¡ã¤ãã³ã°ï¼ãUNET19ã
ãUnity9ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼ãUNET20ã
ãUnity9ã表示ããGUI(Network Manager)ãæ©è½ãããï¼ãUNET20-2ã
ãUnity9ãUNETã§Animationãåæãããï¼ãUNET21ã