ãUnity9ãUNETã§åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãããUNET7ã
Unity5.1.1p3 Personal(2015å¹´7æ)
前回の続きã§ãã
ä»åã¯åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãã¦ããã¾ãã
æ»æã®ãããæ¤åºãªã©ã«ä½¿ãããã§ãã
UNET Part 7 - Unique Identity - YouTube
ãç®æ¨ãåãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãã
â PlayerIDãè¨å®ããã¹ã¯ãªããä½æ
ã¾ãã¯æ°ããPlayer_IDã¹ã¯ãªãããä½æããPlayerãã¬ããã«åãä»ãã¾ãã以ä¸ã½ã¼ã¹ã§ãã
using UnityEngine; using UnityEngine.Networking; using System.Collections; public class Player_ID : NetworkBehaviour { //SyncVar: [Command]ã§å¤æ´å¾ãå ¨ã¯ã©ã¤ã¢ã³ãã¸å¤æ´çµæãéä¿¡ [SyncVar] private string playerUniqueIdentity; //??? private NetworkInstanceId playerNetID; private Transform myTransform; //NetworkManagerã«ãã£ã¦Playerãçæãããæã«å®è¡ããã public override void OnStartLocalPlayer() { GetNetIdentity(); SetIdentity(); } void Awake () { //èªåã®ååãåå¾ããæã«ä½¿ã myTransform = transform; } // Update is called once per frame void Update () { //ä¾å¤ãçºçããæã«SetIdentityã¡ã½ããå®è¡ if (myTransform.name == "" || myTransform.name == "Player(Clone)") { SetIdentity(); } } [Client] void GetNetIdentity() { //NetworkIdentityã®NetIDåå¾ playerNetID = GetComponent<NetworkIdentity>().netId; //ååãä»ããã¡ã½ããå®è¡ CmdTellServerMyIdentity(MakeUniqueIdentity()); } void SetIdentity () { //èªå以å¤ã®Playerãªãã¸ã§ã¯ãã®å ´å if (!isLocalPlayer) { //ä»ä»ãã¦ããååã®ã¾ã¾ myTransform.name = playerUniqueIdentity; } else { //èªåèªä¿¡ã®å ´åãMakeUniqueIdentityã¡ã½ããã§ååãåå¾ myTransform.name = MakeUniqueIdentity(); } } string MakeUniqueIdentity () { //Player + NetIDã§ååãä»ãã string uniqueName = "Player " + playerNetID.ToString(); return uniqueName; } //Command: SyncVarå¤æ°ãå¤æ´ããå¤æ´çµæãå ¨ã¯ã©ã¤ã¢ã³ãã¸éã [Command] void CmdTellServerMyIdentity (string name) { playerUniqueIdentity = name; } }
Player_ID.cs
å é ã®OnStartLocalPlayerã¡ã½ããã¯LocalPlayerã¨ãã¦ã²ã¼ã ä¸ã«çæãããæã«å¼ã°ããã¡ã½ããã§ãGetNetIdentityã¡ã½ããã¨SetIdentityã¡ã½ãããå¼ãã§ãã¾ãã
GetNetIdentityã¡ã½ããã§ã¯ãNetworkIdentityã³ã³ãã¼ãã³ãã®NetIDãåå¾ãã¦ãã¾ããã¡ãªã¿ã«NetIDã¯ãInspectorãã¥ã¼ãDebugã¢ã¼ãã«ããã¨ç¢ºèªãããã¨ãã§ãã¾ãã
Debugãé¸æ
NetworkIdentityã«NetIDåºç¾
ç¶ãã¦MakeUniqueIdentityã¡ã½ããã«ã¦Player + NetIDã®stringåã®å¤æ°ãåå¾ããCmdTellServerMyIdentityã«ã¦playerUniqueIdentityãæ´æ°ãã¦ãã¾ãã
CmdTellServerMyIdentityã¯[Command]ã§ãããSyncVarå¤æ°ãæ´æ°ãã¦ãããããæ´æ°çµæã¯å
¨ã¯ã©ã¤ã¢ã³ãã¸éä¿¡ããã¦åæããã¾ãã
ç¶ãã¦OnStartLocalPlayerã¡ã½ããã§ï¼ã¤ç®ã®ã¡ã½ãããå¼ã³åºãã¾ããSetIdentityã¡ã½ããã§ãã
ãã®Playerãªãã¸ã§ã¯ããèªåèªèº«ã§ããå ´åã¯ãMakeUniqueIdentityã¡ã½ãããå度å¼ã³ãããã§åå¾ããååãèªåã®ååã¨ãã¾ãã
OnStartLocalPlayerã¡ã½ããããå¼ã°ããå ´åã¯å¿ ãèªåèªèº«ã§ãããUpdateã¡ã½ããã«ã¦ä½ãã®ééãã§ååãã¹ãã¼ã¹ã§ãã£ããPlayer(Clone)ã¨ããä¸å ·åããã£ããããå ´åãåã³SetIdentityã¡ã½ãããå¼ã°ãã¾ãã
ãã®å ´åã¯isLocalPlayerãfalseã§ããå¯è½æ§ãããã®ã§ãplayerUniqueIdentityããã®Playerãªãã¸ã§ã¯ãã®ååã¨ãã¦å度æå®ãã¾ãã
â¡çµæ
ããã§ã¯å®éã«ã²ã¼ã ãå®è¡ãã¦ã¿ã¾ãããã
ãã¹ãã¨ã¯ã©ã¤ã¢ã³ãããããã«ååãä»ãã
ç¡äºååãä»ãããã¨ãã§ãã¾ããã
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ã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ã