{"id":45,"date":"2017-09-05T16:55:58","date_gmt":"2017-09-05T07:55:58","guid":{"rendered":"http:\/\/uniblo.biz\/?p=45"},"modified":"2017-09-28T22:54:15","modified_gmt":"2017-09-28T13:54:15","slug":"chapter2_login_scene","status":"publish","type":"post","link":"http:\/\/uniblo.biz\/unity\/mmogame\/chapter2_login_scene","title":{"rendered":"Unity\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u4f5c\u6210\u3010Chapter2\u3011\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u4f5c\u6210"},"content":{"rendered":"

\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n

\"\"<\/a><\/p>\n

\u3053\u306e\u753b\u9762\u3067\u306f\u30c6\u30ad\u30b9\u30c8\u5165\u529b\u6b04\u306b\u81ea\u5206\u306e\u30cb\u30c3\u30af\u30cd\u30fc\u30e0\u3092\u5165\u529b\u3057\u3001Play\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u6b21\u306e\u753b\u9762\u306b\u9077\u79fb\u3059\u308b\u3068\u3044\u3046\u3088\u3046\u306a\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n

\u00a0\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306e\u4f5c\u6210<\/h2>\n

\u307e\u305a\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306b\u5fc5\u8981\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n

\u4ee5\u4e0b\u306e\u753b\u50cf\u304c\u5b8c\u6210\u5f8c\u306eHierarchy\u30d3\u30e5\u30fc\u3067\u3059\u3002<\/p>\n

\"\"<\/a><\/p>\n

\u30b2\u30fc\u30e0\u306b\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u51e6\u7406\u3092\u884c\u3046LauncherObject\u4f5c\u6210<\/h3>\n
    \n
  1. \u65b0\u3057\u3044\u30b7\u30fc\u30f3\u3092\u4f5c\u6210\u3057\u3001Launcher<\/code>\u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/li>\n
  2. Hierarchy\u30d3\u30e5\u30fc\u306bLauncherObject<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u7a7a\u306eGameObject\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n
  3. \u7a7a\u306eC#\u306e\u30b9\u30af\u30ea\u30d7\u30c8LauncherScript<\/code>\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n
  4. \u4f5c\u6210\u3057\u305fLauncherObject<\/code>\u306bLauncherScript<\/code>\u3092\u30a2\u30bf\u30c3\u30c1\u3057\u307e\u3059\u3002<\/li>\n
  5. LauncherScript<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n

    LauncherScript.cs\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n
    using UnityEngine;\r\nusing UnityEngine.UI;\r\nusing UnityEngine.SceneManagement;\r\n\r\npublic class LauncherScript : Photon.PunBehaviour\r\n{\r\n    #region Public\u5909\u6570\u5b9a\u7fa9\r\n\r\n    \/\/Public\u5909\u6570\u306e\u5b9a\u7fa9\u306f\u30b3\u30b3\u3067\r\n\r\n    #endregion\r\n\r\n    #region Private\u5909\u6570\r\n    \/\/Private\u5909\u6570\u306e\u5b9a\u7fa9\u306f\u30b3\u30b3\u3067\r\n    string _gameVersion = \"test\";   \/\/\u30b2\u30fc\u30e0\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3002\u4ed5\u69d8\u304c\u7570\u306a\u308b\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u306a\u3063\u305f\u3068\u304d\u306f\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u5909\u66f4\u3057\u306a\u3044\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3002\r\n    #endregion\r\n\r\n    #region Public Methods\r\n    \/\/\u30ed\u30b0\u30a4\u30f3\u30dc\u30bf\u30f3\u3092\u62bc\u3057\u305f\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u308b\r\n    public void Connect()   \r\n    {\r\n        if (!PhotonNetwork.connected) {                         \/\/Photon\u306b\u63a5\u7d9a\u3067\u304d\u3066\u3044\u306a\u3051\u308c\u3070\r\n            PhotonNetwork.ConnectUsingSettings(_gameVersion);   \/\/Photon\u306b\u63a5\u7d9a\u3059\u308b\r\n            Debug.Log(\"Photon\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f\u3002\");\r\n        }\r\n    }\r\n    #endregion\r\n\r\n    #region Photon\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\r\n\r\n    \/\/Auto-JoinLobby\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u3066\u3044\u308b\u3068Photon\u306b\u63a5\u7d9a\u5f8cOnJoinLobby()\u304c\u547c\u3070\u308c\u308b\u3002\r\n    public override void OnJoinedLobby()        \r\n    {\r\n        Debug.Log(\"\u30ed\u30d3\u30fc\u306b\u5165\u308a\u307e\u3057\u305f\u3002\");\r\n        \/\/Random\u3067\u90e8\u5c4b\u3092\u9078\u3073\u3001\u90e8\u5c4b\u306b\u5165\u308b\uff08\u90e8\u5c4b\u304c\u7121\u3051\u308c\u3070OnPhotonRandomJoinFailed\u304c\u547c\u3070\u308c\u308b\uff09\r\n        PhotonNetwork.JoinRandomRoom(); \r\n    }\r\n\r\n    \/\/JoinRandomRoom\u304c\u5931\u6557\u3057\u305f\u3068\u304d\u306b\u547c\u3070\u308c\u308b\r\n    public override void OnPhotonRandomJoinFailed(object[] codeAndMsg)\r\n    {\r\n        Debug.Log(\"\u30eb\u30fc\u30e0\u306e\u5165\u5ba4\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002\");\r\n        \/\/TestRoom\u3068\u3044\u3046\u540d\u524d\u306e\u90e8\u5c4b\u3092\u4f5c\u6210\u3057\u3066\u3001\u90e8\u5c4b\u306b\u5165\u308b\r\n        PhotonNetwork.CreateRoom(\"TestRoom\");\r\n    }\r\n\r\n    \/\/\u90e8\u5c4b\u306b\u5165\u3063\u305f\u6642\u306b\u547c\u3070\u308c\u308b\r\n    public override void OnJoinedRoom()\r\n    {\r\n        Debug.Log(\"\u30eb\u30fc\u30e0\u306b\u5165\u308a\u307e\u3057\u305f\u3002\");\r\n        \/\/battle\u30b7\u30fc\u30f3\u3092\u30ed\u30fc\u30c9\r\n        PhotonNetwork.LoadLevel(\"battle\");\r\n    }\r\n\r\n    #endregion\r\n}<\/pre>\n

     <\/p>\n

    \u30b2\u30fc\u30e0\u958b\u59cb\u30dc\u30bf\u30f3\u306e\uff35\uff29\u3092\u4f5c\u6210<\/h3>\n
      \n
    1. Scene Launcher<\/code>\u3092\u958b\u304d\u307e\u3059\u3002<\/li>\n
    2. Hierachy\u30d3\u30e5\u30fc\u4e0a\u3067\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3001’UI\/Button’\u3092\u4f7f\u7528\u3057\u3066\u30dc\u30bf\u30f3\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u30dc\u30bf\u30f3\u3092PlayButton<\/code>\u3068\u540d\u4ed8\u3051\u307e\u3059\u3002 \u3053\u306e\u3068\u304d\u81ea\u52d5\u7684\u306bHierachy\u30d3\u30e5\u30fc\u5185\u306bCanvas\u3068EventSystem\u306eGameObject\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/li>\n
    3. Play Button<\/code>\u306e\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308bText\u306e\u5024\u3092”Play”\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/li>\n
    4. Play Button<\/code>\u306eButton\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u306eOn Click ()<\/code>\u306e\u5c0f\u3055\u3044’+’\u3092\u30af\u30ea\u30c3\u30af\u3057\u65b0\u3057\u3044\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u8ffd\u52a0\u3059\u308b<\/li>\n
    5. Hierarchy\u304b\u3089\u4f5c\u6210\u3057\u305f\u30a8\u30f3\u30c8\u30ea\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u3001LauncherObject<\/code>\u3092\u30c9\u30e9\u30c3\u30b0\u3057\u307e\u3059<\/li>\n
    6. \u30c9\u30ed\u30c3\u30d7\u30c0\u30a6\u30f3\u30e1\u30cb\u30e5\u30fc\u304b\u3089LauncherScript.connect()<\/code>\u3092\u9078\u629e\u3057\u307e\u3059\u3002
      \n
      \"\"<\/a>
      \n\u3053\u308c\u306b\u3088\u308aLauncherScript\u3068Button\u304c\u63a5\u7d9a\u3055\u308c\u3001Play Button\u304c\u62bc\u3055\u308c\u308b\u3068\u540c\u6642\u306bLauncherScript\u306e”Connect()”\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n
    7. Ctrl+S\u3067\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n

      \u3053\u306e\u6642\u70b9\u3067\u30b2\u30fc\u30e0\u3092\u5b9f\u884c\u3057\u3066\u3001Play\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001battle\u30b7\u30fc\u30f3\u306b\u79fb\u52d5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

      \u5ff5\u306e\u305f\u3081\u52d5\u4f5c\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

      \u540d\u524d\u306e\u5165\u529b\u6b04\u306e\uff35\uff29\u3092\u4f5c\u6210<\/h3>\n
        \n
      1. Scene Launcher<\/code>\u3092\u958b\u304d\u307e\u3059\u3002<\/li>\n
      2. Unity\u306e\u30e1\u30cb\u30e5\u30fc\u306e’GameObject\/UI\/Input Field’\u3092\u4f7f\u7528\u3057\u3066\u540d\u524d\u5165\u529b\u6b04\u3092\u4f5c\u6210\u3057\u3001NameInputField<\/code>\u3068\u540d\u4ed8\u3051\u307e\u3059\u3002<\/li>\n
      3. \u4f4d\u7f6e\u3092Rect Transform\u306e\u5024\u3092\u8abf\u7bc0\u3057\u307e\u3059\u3002<\/li>\n
      4. NameInputField<\/code>\u306e\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308bPlaceholder\u306e\u5024\u3092”\u540d\u524d\u3092\u5165\u529b”\u7b49\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/li>\n
      5. \u65b0\u3057\u3044C#\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u00a0NameInputFieldScript<\/code>\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7de8\u96c6\u3057\u307e\u3059\u3002<\/li>\n
      6. NameInputField<\/code>\u3092\u9078\u629e\u3057\u3066\u3001InputField\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u306eOn Value Changed ()<\/code>\u306e\u5c0f\u3055\u3044’+’\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u65b0\u898f\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n
      7. Hierarchy\u304b\u3089\u4f5c\u6210\u3057\u305f\u30a8\u30f3\u30c8\u30ea\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u3001NameInputField<\/code>\u3092\u30c9\u30e9\u30c3\u30b0\u3057\u307e\u3059<\/li>\n
      8. \u30c9\u30ed\u30c3\u30d7\u30c0\u30a6\u30f3\u30e1\u30cb\u30e5\u30fc\u304b\u3089NameInputFieldScript.SetPlayerName<\/code>\u3092\u9078\u629e\u3057\u307e\u3059\u3002
        \n
        \"\"<\/a>
        \n\u3053\u308c\u306b\u3088\u308a\u5165\u529b\u6b04\u306e\u6587\u5b57\u5217\u304c\u5909\u66f4\u3059\u308b\u305f\u3073\u306bSetPlayerName\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n
      9. Ctrl+S\u3067\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n

        NameInputFieldScript.cs\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n
        using UnityEngine;\r\nusing UnityEngine.UI;\r\nusing System.Collections;\r\n\r\n\r\npublic class NameInputFieldScript : MonoBehaviour\r\n{\r\n    #region Private\u5909\u6570\u5b9a\u7fa9\r\n    static string playerNamePrefKey = \"PlayerName\";\r\n    #endregion\r\n\r\n    #region MonoBehaviour\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\r\n    void Start()\r\n    {\r\n        string defaultName = \"\";   \r\n        InputField _inputField = this.GetComponent<InputField>();\r\n\r\n        \/\/\u524d\u56de\u30d7\u30ec\u30a4\u958b\u59cb\u6642\u306b\u5165\u529b\u3057\u305f\u540d\u524d\u3092\u30ed\u30fc\u30c9\u3057\u3066\u8868\u793a\r\n        if (_inputField != null)\r\n        {\r\n            if (PlayerPrefs.HasKey(playerNamePrefKey))\r\n            {\r\n                defaultName = PlayerPrefs.GetString(playerNamePrefKey);\r\n                _inputField.text = defaultName;\r\n            }\r\n        }\r\n    }\r\n    #endregion\r\n\r\n    #region Public Method\r\n    \r\n    public void SetPlayerName(string value)\r\n    {\r\n        PhotonNetwork.playerName = value + \" \";     \/\/\u4eca\u56de\u30b2\u30fc\u30e0\u3067\u5229\u7528\u3059\u308b\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u540d\u524d\u3092\u8a2d\u5b9a\r\n\r\n        PlayerPrefs.SetString(playerNamePrefKey, value);    \/\/\u4eca\u56de\u306e\u540d\u524d\u3092\u30bb\u30fc\u30d6\r\n\r\n        Debug.Log(PhotonNetwork.player.NickName);   \/\/player\u306e\u540d\u524d\u306e\u78ba\u8a8d\u3002\uff08\u52d5\u4f5c\u304c\u78ba\u8a8d\u3067\u304d\u308c\u3070\u3053\u306e\u884c\u306f\u6d88\u3057\u3066\u3082\u3044\u3044\uff09\r\n    }   \r\n    #endregion\r\n}<\/pre>\n

         <\/p>\n

        \u3053\u306e\u6642\u70b9\u3067\u30b2\u30fc\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u5165\u529b\u6b04\u306e\u6587\u5b57\u5217\u3092\u5909\u66f4\u3059\u308b\u305f\u3073\u306bConsole\u306b\u540d\u524d\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n

        \u3053\u308c\u3067\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306e\u30b7\u30fc\u30f3\u306e\u5b8c\u6210\u3067\u3059\u3002<\/p>\n

        \u52d5\u4f5c\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

        Console\u306b\u300c\u30eb\u30fc\u30e0\u306b\u5165\u308a\u307e\u3057\u305f\u3002\u300d\u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u51fa\u3066\u3044\u308c\u3070\u6210\u529f\u3067\u3059\uff01\uff01<\/p>\n

        \u6b21\u56de\u4e88\u544a\uff01\uff01<\/h2>\n

         <\/p>\n

        \u6b21\u56de\u304b\u3089\u306f\u3064\u3044\u306b\u30b2\u30fc\u30e0\u30b7\u30fc\u30f3\u306b\u3064\u3044\u3066\u306e\u8b1b\u5ea7\u3068\u306a\u308a\u307e\u3059\uff01\uff01<\/p>\n

        \u304a\u697d\u3057\u307f\u306b\uff01\uff01\uff01<\/p>\n

         <\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"

        \u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 \u3053\u306e\u753b\u9762\u3067\u306f\u30c6\u30ad\u30b9\u30c8\u5165\u529b\u6b04\u306b\u81ea\u5206\u306e\u30cb\u30c3\u30af\u30cd\u30fc\u30e0\u3092\u5165\u529b\u3057\u3001Play\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u6b21\u306e\u753b\u9762\u306b\u9077\u79fb\u3059\u308b\u3068\u3044\u3046\u3088\u3046\u306a\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002 \u00a0\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306e\u4f5c\u6210 \u307e … <\/p>\n","protected":false},"author":1,"featured_media":83,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/45"}],"collection":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":24,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":474,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/45\/revisions\/474"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/media\/83"}],"wp:attachment":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}