ãUnity7ãBoardManagerãå¼ã³åºãGameManagerãä½æããã2Dãã¼ã°ã©ã¤ã¯5ã
Unity5.0.0f4 Personal(2015å¹´5æ)
ååã®ç¶ãã§ãã
ååä½æããBoardManagerã¹ã¯ãªããã®SetupSceneã¡ã½ãããããã£ã¼ã«ããããä½æã¯å§ã¾ã£ã¦ãã¾ãããã§ãã®ã§ãä»åã¯GameManagerã¹ã¯ãªãããç·¨éããSetupSceneã¡ã½ãããå¼ã³åºãã¦ããã¾ãã
Â
ãç®æ¨ãBoardManagerãå¼ã³åºãã²ã¼ã ãéå§ãã
Â
2D Roguelike 5 of 14 : Game Manager - YouTube
Â
ã課é¡ï¼ãGameManagerã¹ã¯ãªããããBoardManagerã®SetupSceneãå¼ã³åºã
ã¾ãã¯GameManagerã¹ã¯ãªãããç·¨éãã¾ããBoardManagerã«æ¯ã¹ãã¨å¤§å¤ã·ã³ãã«ã¨ãªã£ã¦ããã¾ãã以ä¸ã½ã¼ã¹ã§ãã
Â
Â
BoardManagerãGetComponentã§åå¾ããå¾InitGameã¡ã½ããã¸ç§»ããBoardManagerã®SetupSceneãå¼ã³åºãã¦ããã ãã§ããä»åã¯ãã¹ããªã®ã§levelã¯3ã¨ãã¦ããã¾ãã
Â
ã課é¡ï¼ãBoardManagerã«ãã¬ãã¡ããæå®ãã
ããã§ã¯éçºç»é¢ã¸æ»ããGameManagerãªãã¸ã§ã¯ãã¸BoardManagerã¹ã¯ãªããã¨GameManagerã¹ã¯ãªãããåãä»ãã¾ãã
Â
GameManagerãªãã¸ã§ã¯ãã«ã¹ã¯ãªãããæå®
Â
ããã§ã¯BoardManagerã¹ã¯ãªããã®åpublicå¤æ°ã«ã対象ã®ãã¬ãã¡ããæå®ãã¦ããã¾ãããããã®ã¾ã¾ã ã¨ãã¬ãã¡ããé¸æããæã«Inspectorãã¥ã¼ãGameManagerãªãã¸ã§ã¯ããããã¬ãã¡ãã«å¤ãã£ã¦ãã¾ãã®ã§ãInspectorãã¥ã¼å³ä¸ã«ããããã¯ãã¿ã³ï¼éµã®ãã¼ã¯ï¼ãæ¼ãã¾ãã
Â
éµã®ãã¼ã¯ãã¯ãªãã¯
Â
ããã§GameManagerã®Inspectorãã¥ã¼ã«åºå®ããã¾ãããããã§ã¯ã¾ãã¯Floorããæå®ãã¦ããã¾ããããã¾ã¨ãã¦ãã©ãã°ï¼ããããã§ããã¾ãã
Â
ãã©ãã°ï¼ããããï¼
Â
ä¸æ¬æå®
Â
åãè¦é ã§Wall1ã8ãWall Tilesã«ãFoodã¨SodaãFood Tilesã«ãEnemy1,2ãEnemy Tilesã«ãOuter Wall1ã3ãOuter Wall TilesãExitã¯Exitã¸ãã©ãã°ï¼ãããããã¦ä¸ããã
Â
対象ã®å ¨ãã¬ãã¡ããæå®
Â
å®äºãããGameManagerã®ããã¯ãã¿ã³ã¯è§£é¤ãã¦ããã¦ä¸ããã
Â
ã課é¡ï¼ãã«ã¡ã©ä½ç½®ã®èª¿æ´
ãã®ã¾ã¾ã²ã¼ã ãå®è¡ããã¨ç»é¢ããºã¬ã¦ãã¾ãã®ã§ãMainCameraã®ä½ç½®ã調æ´ãã¾ããPosition.xã3.5ãPosition.yã3.5ã«ããã¤ãã§ã«èæ¯è²ãé»ã«ãã¾ãã
Â
Â
ã²ã¼ã å®è¡
Â
ã課é¡ï¼ãã·ã³ã°ã«ãã³æ©è½ãä»ãã
ã·ã³ã°ã«ãã³ã¨ã¯ã対象ã®ãªãã¸ã§ã¯ãã1ã¤ã®Sceneã«å¿ ãï¼ã¤åå¨ãããã¨ãããã°ã©ã ã«ãã£ã¦ä¿è¨¼ãããã¨ã§ãã
Â
å ã»ã©ç·¨éããGameManagerã¹ã¯ãªããã«ã·ã³ã°ã«ãã³ã追è¨ãã¾ãã
Â
Â
staticå¤æ°ã¯ããã®ã²ã¼ã å ã§å¯ä¸åå¨ããã¦ãã¼ã¯ãªå¤æ°ã表ãã¾ãããªãã¸ã§ã¯ãã«å±ããã¯ã©ã¹ã«å±ãå¤æ°ãªã®ã§ãä¾ãã°ãã¬ãã¡ããå©ç¨ãã¦ããããã®ãªãã¸ã§ã¯ããä½ã£ãå ´åã§ããããããã®ãã¬ãã¡ããå¥ã ã®å¤æ°ãæã¤ã®ã§ã¯ãªãã1ã¤ã®staticå¤æ°ãå ±æãã¾ããã¾ããã·ã¼ã³ã移åããæãå¤æ°æ å ±ãä¿æããã®ã§ãä»åã®ã·ã³ã°ã«ãã³ã§ã¯instanceã¨ããååã®staticå¤æ°ã使ã£ã¦ããã¾ãã
Â
ã²ã¼ã éå§æãä½ãã®ééãã§GameManagerãåé¤ãã¦ãã¾ã£ãæãªã©GameManagerãåå¨ããªãæã®ããã«ãinstanceãnullã§ããæã¯this(GameManagerãªãã¸ã§ã¯ã)ãinstanceå¤æ°ã«æ ¼ç´ãã¾ãã
Â
ã¾ãGameManagerãªãã¸ã§ã¯ãã2ã¤ä»¥ä¸ã«ãªã£ãæãthis(ãã®ã¹ã¯ãªãããä»ãã¦ããã»ãã®GameManager)ãç ´å£ãã¾ãããããããã¨ã«ãã£ã¦ãGameManagerã¯ã²ã¼ã å ã§å¿ ã1ã¤ã«ãªããã¨ãä¿è¨¼ãã¾ãã
Â
æå¾ã«DontDestroyOnLoadã¡ã½ããã«ãã£ã¦ãã·ã¼ã³é·ç§»æã«ãã®ãªãã¸ã§ã¯ããåãç¶ããã¦ãã¾ãã
Â
ããã§ã ãããOKãªæãã§ããããã¨ï¼ã¤ã ãä»ã足ãã¾ããGameManagerãããããHierarchyä¸ã«åå¨ããªãæã«ãGameManagerãªãã¸ã§ã¯ããçæããLoaderã¹ã¯ãªãããä½æãã¾ãã
Â
Â
 ãã¡ãã®ã¹ã¯ãªããã¯MainCameraã«ã¨ãã¤ãã¦ä¸ããã
Â
MainCameraã«Loaderã¹ã¯ãªãããä»ãã
Â
ããã¦GameManagerããã¬ãã¡ãåããå ã®GameManagerãªãã¸ã§ã¯ãã¯åé¤ããLoaderã¹ã¯ãªããã®publicå¤æ°ã§ããgameManagerå¤æ°ã«GameManagerãã¬ãã¡ããæå®ãã¦ä¸ããã
Â
ãã©ãã°ï¼ããããï¼
Â
ãã®ç¶æ ã§ã²ã¼ã ãéå§ããã¨ã»ã»ã»
Â
Â
BoardManagerããã£ããã¨å®è¡ããã¦ãã¾ãã
Â
Â
Hierarchyä¸ã«ããã£ããã¨GameManagerãçæããã¦ãã¾ãã
Â
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
Â
ãUnityéçº7ãã¢ãã¡ã¼ã·ã§ã³ãä½ãããï¼ã2Dãã¼ã°ã©ã¤ã¯2ã
ãUnityéçº7ãFloorãã¢ã¤ãã ãä½æãããï¼ã2Dãã¼ã°ã©ã¤ã¯3ã
ãUnityéçº7ãBoardManagerãå¼ã³åºãGameManagerãä½æããã2Dãã¼ã°ã©ã¤ã¯5ã
ãUnityéçº7ãç ´å£å¯è½ãªå£(Wall)ãä½æãããï¼ããã¼ã°ã©ã¤ã¯7ã
ãUnityéçº7ããã¬ã¤ã¤ã¼ã®ã¢ãã¡ã¼ã¿ã¼ãè¨å®ãããï¼ããã¼ã°ã©ã¤ã¯8ã
ãUnityéçº7ããã¬ã¤ã¤ã¼ç¨ã®ã¹ã¯ãªãããè¨å®ãããï¼ããã¼ã°ã©ã¤ã¯9ã
ãUnityéçº7ãBGMã¨å¹æé³ãä»ããã2Dãã¼ã°ã©ã¤ã¯13ã
ãUnityéçº7ãã¿ããããã«ã«å¯¾å¿ããããï¼ã2Dãã¼ã°ã©ã¤ã¯14(Fin)ã
Â