ãUnity9ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼ãUNET20ã
Unity5.1.1p3 Personal(2015å¹´7æ)
前回の続きã§ãã
ä»ã®ã¾ã¾ã ã¨GUIãããã©ã«ãã®ãã®ãªã®ã§ã¡ãã£ã¨ãã£ãæªãã§ãããå¿ è¦ãªãæ©è½ããããã表示ããã¦ãã¦åããã«ããã§ãã
ã§ãã®ã§ãå¿ è¦ãªæ©è½ã®ã¿ã表示ãããããã«æ¹åãã¦ããã¾ãã
UNET Part 20 - UI & Custom Net Manager - YouTube
ãç®æ¨ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼
â ã¹ã¯ãªããä½æ
ã¾ãã¯NetworkManager_Customã¨ããååã®ã¹ã¯ãªãããä½æããMenuã·ã¼ã³ã«ããNetworkManagerãªãã¸ã§ã¯ãã«åãä»ãã¾ãã
using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; using System.Collections; //NetworkManagerã¯ã©ã¹ãç¶æ¿ãã(NetworkBehaviourã§ã¯ãªãã®ã§æ³¨æ) public class NetworkManager_Custom : NetworkManager { //ButtonStartHostãã¿ã³ãæ¼ããæã«å®è¡ //IPãã¼ããè¨å®ãããã¹ãã¨ãã¦æ¥ç¶ public void StartupHost() { SetPort(); NetworkManager.singleton.StartHost(); } //ButtonJoinGameãã¿ã³ãæ¼ããæã«å®è¡ //IPã¢ãã¬ã¹ã¨ãã¼ããè¨å®ããã¯ã©ã¤ã¢ã³ãã¨ãã¦æ¥ç¶ public void JoinGame() { SetIPAddress(); SetPort(); NetworkManager.singleton.StartClient(); } void SetIPAddress() { //Input Fieldã«è¨å ¥ãããIPã¢ãã¬ã¹ãåå¾ããæ¥ç¶ãã string ipAddress = GameObject.Find("InputFieldIPAddress").transform.FindChild("Text").GetComponent<Text>().text; NetworkManager.singleton.networkAddress = ipAddress; } //ãã¼ãã®è¨å® void SetPort () { NetworkManager.singleton.networkPort = 7777; } }
NetworkManager_Custom.cs
ããããä½ã£ã¦ããButtonStartHostãã¿ã³ã¨ButtonJoinGameãã¿ã³ãæ¼ããæã«å®è¡ããã¾ãã
å
ã«é²ã¿ã¾ãã
â¡NetworkManagerã³ã³ãã¼ãã³ãã®è¨å®
ç¶ãã¦NetworkManagerã³ã³ãã¼ãã³ããRemove Componentã«ã¦åãé¤ãã¾ãã
åãé¤ãã¨è¨ã£ã¦ããå ã»ã©ä½æããã¹ã¯ãªããã§Network Managerãç¶æ¿ãã¦ããã®ã§å®éã«ã¯NetworkManagerã¯çãã¦ãã¾ãã
NetworkManagerã¯ã¡ããã¨ç¶æ¿ããã¦ãã
ç¶ãã¦NetworkManagerã®è¨å®ãè¡ãã¾ãã
Offline Sceneã«MenuãOnline Sceneã«MainãPlayer Prefabã«PlayerãPlayer Spawn Methodã«Round RobinãRegistered Spawnable Prefabsã«ZombieãAdvanced Configurationã«ãã§ãã¯ãå
¥ããChannel #0ã«UnreliableãChannel #1ã«Reliable SequencedãPing Timeoutã900ã«å¤æ´ãã¾ãã
â¢Menuã·ã¼ã³ã®GUIä½æ
ç¶ãã¦GUIãä½æãã¦ããã¾ããHierarchyãã¥ã¼ããCreate > UI > Panelãé¸æãã¾ãã
ç¶ãã¦Canvasã®Canvas Scalerã®è¨å®ããã¾ãã
UI Scale ModeãScale With Screen Sizeã«ãXã1920ãYã1080ã«ãMatchã0.5ã«å¤æ´ãã¾ãã
Canvas Scalerè¨å®
Canvas Scalerã«ã¤ãã¦ã¯ä»¥ä¸ã®è¨äºã§ã解説ãã¦ãã¾ãã
ç¶ãã¦Panelã®Rect Transformãå¤æ´ãã¦ããã¾ãã
Anchor Presetsãcenter middleã«å¤æ´ããWidthã600ãHeightã500ã«å¤æ´ãã¾ãã
ãããªæã
ç¶ãã¦Panelã«ãåãªãã¸ã§ã¯ããèªåçã«ã¬ã¤ã¢ã¦ããã¦ãããGrid Layout Groupã³ã³ãã¼ãã³ããä»ãã¾ãã
Add ComponentããLayout > Grid Layout Groupãé¸æãã以ä¸ã®ããã«è¨å®ãã¦ä¸ããã
ç¶ãã¦Panelã®åãªãã¸ã§ã¯ãã¨ãã¦Buttonã2ã¤ãInput Fieldã1ã¤ä½æãã¾ãã
1ã¤ç®ã®Buttonã®ååã¯ãButtonStartHostãã2ã¤ç®ã®Buttonã®ååã¯ãButtonJoinGameããInput Fieldã¯ãInputFieldIPAddressãã«å¤æ´ãã¾ãã
次ã«Buttonã®åãªãã¸ã§ã¯ãã§ããTextã®Inspectorãã¥ã¼ã®Best Fitã¨ãInput Fieldã®åãªãã¸ã§ã¯ãã§ããPlaceholderã¨Textã®Inspectorãã¥ã¼ã®Best Fitããã§ãã¯ãã¦ä¸ããã
ButtonStartHostã®Textã«ãStart HostããButtonJoinGameã®Textã«ãJoin GameããInputFieldIPAddressã®Textã«ãlocalhostãã¨å ¥åãã¾ãã
â£Mainã·ã¼ã³ã®GUIä½æ
ç¶ãã¦Mainã·ã¼ã³ã®GUIãä½æãã¦ããã¾ãã
ã¾ãã¯Canvas Scalerã§ãããMenuã·ã¼ã³ã¨å
¨ãåãã§ãã
Latency Textã¯Rect Transformã®Heightã50ã«å¤æ´ãã¾ãã
Health TextãHeightã50ã«å¤æ´ãã¾ãã
Respawn Buttonã¯Widthã300ãHeightã60ã«å¤æ´ããTextãBest Fitã«å¤ãã¾ãã
ç¶ãã¦Panelãæ°è¦ä½æããAnchor Presetsãtop rightãWidthã500ãHeightã150ãPivotãX,Yå ±ã«1ã«å¤æ´ãã¾ãã
ç¶ãã¦Panelã®åãªãã¸ã§ã¯ãã«Buttonãä½æããååããButtonDisconnectãã«ãã¾ãã
Anchor Presetsã¯middle centerãWidthã¯300ãHeightã¯60ãTextã¯ãDisconnectãã¨ããBest Fitã«ãã§ãã¯ãå
¥ãã¾ãã
ãããªæã
ã¡ãã£ã¨é·ããªã£ã¦ããã®ã§ãä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ã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ã