ãUnity9ãUNETã§ãã¬ã¤ã¤ã¼ã®åããè£éãããªããããªåããå®ç¾ãããUNET1-2ã
Unity5.1.1f1 Personal(2015å¹´7æ)
前回の続きã§ãã
ååã¾ã§ã§èªãã¬ã¤ã¤ã¼ã®åãã¨ç¸æãã¬ã¤ã¤ã¼ã®åãã¨ãå¥ã
ã«åãé¢ããã¨ãã§ããããã«ãªãã¾ããã
ãããã¾ã åããã«ã¯ã«ã¯ããæããªã®ã§ãåãããããªãããã«è¡¨ç¤ºããå¦çãå ãã¦ããã¾ãã
UNET Part 1 - Setup and Movement Syncing - YouTube
ãç®æ¨ããã¬ã¤ã¤ã¼ã®åããè£éãããªã³ã©ã¤ã³ã§ãåãããªãããã«è¡¨ç¤ºãã
â ãã¬ã¼ã ã¨ãã¬ã¼ã ã®éã®åããè£å®ãã
ã«ã¯ã«ã¯ããåãã®åå ã¨ãã¦ããã¬ã¼ã ã®éã®åããè£éããã¦ããªããã¨ãããããã¾ãã
ã¾ãã¯Playerãã¬ãã¡ãã«ã¤ãã¦ããNetwork Transformã³ã³ãã¼ãã³ããRemove Componentã§åãå¤ããåããè£å®ãããPlayer_SyncPositionãã¹ã¯ãªãããæ°ãã«ä½æãã¦åãä»ãã¦ããã¾ãã以ä¸ã½ã¼ã¹ã§ãã
using UnityEngine; using System.Collections; using UnityEngine.Networking; //UNETã使ãæã«å¿ è¦ãªã©ã¤ãã©ãª //UNETã使ãæã«å¿ è¦ãªç¶æ¿ public class Player_SyncPosition : NetworkBehaviour { [SyncVar] //ãã¹ãããå ¨ã¯ã©ã¤ã¢ã³ãã¸éããã private Vector3 syncPos; //Playerã®ç¾å¨ä½ç½® [SerializeField] Transform myTransform; //Lerp: ï¼ãã¯ãã«éãè£éãã [SerializeField] float lerpRate = 15; void FixedUpdate () { TransmitPosition(); LerpPosition(); //2ç¹éãè£éãã } //ãã¸ã·ã§ã³è£éç¨ã¡ã½ãã void LerpPosition () { //è£é対象ã¯ç¸æãã¬ã¤ã¤ã¼ã®ã¿ if (!isLocalPlayer) { //Lerp(from, to, å²å) fromãtoã®ãã¯ãã«éãè£éãã myTransform.position = Vector3.Lerp(myTransform.position, syncPos, Time.deltaTime * lerpRate); } } //ã¯ã©ã¤ã¢ã³ããããã¹ãã¸ãPositionæ å ±ãéã [Command] void CmdProvidePositionToServer (Vector3 pos) { //ãµã¼ãã¼å´ãåãåãå¤ syncPos = pos; } //ã¯ã©ã¤ã¢ã³ãã®ã¿å®è¡ããã [ClientCallback] //ä½ç½®æ å ±ãéãã¡ã½ãã void TransmitPosition () { if (isLocalPlayer) { CmdProvidePositionToServer(myTransform.position); } } }
Player_SyncPosition.cs
èªåãã¯ã©ã¤ã¢ã³ãã§ããå ´åãFixedUpdateã¡ã½ããã«ã¦TransmitPositionãå¼ã³ãç¾å¨ä½ç½®ãCmdProvidePositionToServerã¡ã½ããã¸éã
CmdProvidePositionToServerã¡ã½ããã§SyncPoså¤æ°ã«ç¾å¨ä½ç½®ãä¿åãã
ä¿åãããSyncPoså¤æ°ããã¹ãããå
¨ã¯ã©ã¤ã¢ã³ãã¸éãè¿ããã
LerpPositionã¡ã½ããã«ã¦èªå以å¤ã®å
¨ãã¬ã¤ã¤ã¼ã®ç¾å¨ä½ç½®ã¨TransmitPositionéä¿¡æã®ä½ç½®ã®ä¸éå°ç¹ããç¾å¨ã®ä½ç½®æ
å ±ã«æ¸ãæãã
æ£ç´èªä¿¡ã¯ãªãã§ããããããªæãã®ãã¨ããã£ã¦ããã®ã§ã¯ãªãã§ããããã
ãã®ã¹ã¯ãªããå
容ããããåç¥ã®æ¹ãããã£ãããã¾ãããããããããã°ã³ã¡ã³ããã¦é ããã¨å©ããã¾ãã
ããã§ã¯SerializeFieldã®myTransformã«ãPlayerãã¬ãããæå®ãã¦ããã¾ãããã
ãã©ãã°ï¼ããããï¼
ãã¬ã¤ã¤ã¼ã移åããæã®ãã¬ã¼ã éãä½ç½®æ å ±ãè£éãããããã«ãªã£ãã®ã§ãããã¹ã ã¼ãºãªåãã¨ãªã£ã¦ããã¯ãã§ãã
ã¹ã ã¼ãºã«åãã¦ããã¦ã¾ã
ãã¡ããç»åã§ã¯åãããªãã§ãã®ã§ãçãããã²è©¦ãã¦ã¿ã¦ä¸ããã
ã¡ãªã¿ã«ååãã¾ããããªãã£ãNetwork Managerã«ã·ã¼ã³ãæå®ããé¨åã§ãããBuild Settingsã«ã¦ã·ã¼ã³ã追å ããã¨ã¡ããã¨æå®ã§ããããã«ãªãã¾ããã
ã·ã¼ã³ãAdd Currentããã¨
é çªã¯ãä¸ã«Menuã·ã¼ã³ãä¸ã«Mainã·ã¼ã³ãæ¥ãããã«ãã¦ä¸ããã
以ä¸ã§NetworkManagerã«ã·ã¼ã³ãæå®ã§ããããã«ãªãã¾ããã
æå®ã§ãã¾ã
ããã§ã¯ãä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ã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ã