{"id":785,"date":"2016-01-24T10:27:41","date_gmt":"2016-01-24T01:27:41","guid":{"rendered":"http:\/\/nantoka.filmm.info\/blog\/?p=785"},"modified":"2016-01-25T23:01:31","modified_gmt":"2016-01-25T14:01:31","slug":"unity%e3%81%a7photon%e3%83%8d%e3%83%83%e3%83%88%e3%83%af%e3%83%bc%e3%82%af%e3%81%9d%e3%81%ae%ef%bc%92","status":"publish","type":"post","link":"https:\/\/nantoka.filmm.info\/blog\/?p=785","title":{"rendered":"Unity\u3067Photon\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u305d\u306e\uff12"},"content":{"rendered":"<p>Unity\u3067\u4f5c\u6210\u4e2d\u306e\u30a4\u30d9\u30f3\u30c8\u7528\u30a2\u30d7\u30ea\u306e\u4f5c\u6210\u30e1\u30e2\u3067\u3059<\/p>\n<p>\u73fe\u5728\u4f5c\u6210\u4e2d\u306e\u30a2\u30d7\u30ea\u3067\u3059\u304c\uff0c\u540c\u671f\u306a\u3069\u306e\u95a2\u4fc2\u304b\u3089\uff08\u305f\u3076\u3093\uff09\u5168\u54e1\u304c\u540c\u3058\u90e8\u5c4b\u306b\u5165\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3059\uff0e<\/p>\n<p>\u305d\u3053\u3067\u3044\u308d\u3044\u308d\u9762\u5012\u304c\u767a\u751f\u3057\u307e\u3059\uff08\u4ee5\u4e0b\uff0cphoton\u306e\u30ec\u30d9\u30eb\u5225\u30de\u30c3\u30c1\u30e1\u30a4\u30af\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306a\u3069\u304b\u3089\u6d41\u7528\u3057\u3066\u3044\u307e\u3059\uff09<\/p>\n<p>\uff08\uff11\uff09photon\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u63a5\u7d9a\u76f4\u5f8c\u306b\u306froom list\u3092\u53d6\u5f97\u3057\u3066\u3082\u30bc\u30ed\u304c\u8fd4\u308b\u3063\u307d\u3044\uff0e\u4e0d\u78ba\u5b9f\u3060\u3051\u3069\u5bfe\u6297\u7b56\u306f<\/p>\n<pre class=\"lang:default decode:true \">\tvoid OnReceivedRoomListUpdate()<\/pre>\n<p>\u3067\uff0c\u30ea\u30b9\u30c8\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u3066\u304b\u3089\uff0c\u30eb\u30fc\u30e0\u30ea\u30b9\u30c8\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\uff0e<\/p>\n<p>\uff08\uff12\uff09<span style=\"font-family: IPAexGothic;\"> <span style=\"color: #3364a4;\">PhotonNetwork<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #333333;\">CreateRoom()\u306f\u3069\u3046\u3082\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u3084\u3059\u3044\uff0e\u306e\u3067\uff0c\u78ba\u5b9f\u306b\u305d\u306e\u540d\u524d\u306e\u30eb\u30fc\u30e0\u304c<strong>\u7121\u3044<\/strong>\u3053\u3068\u3092\u78ba\u8a8d\u3057\u306a\u304f\u3066\u306f\u3044\u3051\u306a\u3044\uff08\u305d\u3053\u3067\u4e0a\u8a18\u306e\u30eb\u30fc\u30e0\u30ea\u30b9\u30c8\u3092\u4f7f\u3046\u3051\u3069\uff0c\u30bf\u30a4\u30df\u30f3\u30b0\u304c\uff0c\uff0c\uff0c<\/span><\/span><\/p>\n<p>\uff08\uff13\uff09\u305d\u3053\u3067\u304a\u304a\u307e\u304b\u306a\u6d41\u308c\u3068\u3057\u3066\u306f\uff0cPhoton\u306b\u63a5\u7d9a\u3057\u3066\uff0c\u30ed\u30d3\u30fc\u306b\u5165\u3063\u305f\u3089\uff0c\u305d\u306e\u307e\u307e\u306b\u3057\u3066\u304a\u3044\u3066\u30ea\u30b9\u30c8\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3092\u5f85\u3064\uff0e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u306a\u3044\u6642\u306e\u305f\u3081\u306b\uff0c5\u79d2\u304f\u3089\u3044\u5f85\u3064\u95a2\u6570\u3092\u5165\u308c\u308b\u304b\u601d\u6848\u4e2d\uff08\u672a\u5b9f\u88c5\uff09\uff0e\u30ea\u30b9\u30c8\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u305f\u3089\uff0c\u540c\u540d\u306e\u30eb\u30fc\u30e0\u540d\u304c\u306a\u3044\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3066\uff0c\u3042\u308c\u3070\u305d\u3053\u306b\u5165\u5ba4\uff0c\u306a\u3051\u308c\u3070\u4f5c\u6210\u3092\u3059\u308b\uff0e<\/p>\n<p>\u3053\u3053\u307e\u3067\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\uff0e<\/p>\n<pre class=\"lang:default decode:true \" title=\"photonsystem.cs\">using UnityEngine;\r\nusing System.Collections;\r\nusing Hashtable = ExitGames.Client.Photon.Hashtable; \/\/need for generate hashtable\r\n\r\npublic class photonsystem : Photon.MonoBehaviour {\r\n\tpublic string objectName;\r\n\tprivate bool connectFailed = false;\r\n\r\n\t\/\/set player name\r\n\tprivate string playerName = \"GuestAAA\";\t\r\n\t\/\/set room name\r\n\tprivate string roomName = \"liub2\";\/\/liub\u3068\u3044\u3046\u5c02\u7528\u306e\u30eb\u30fc\u30e0\u540d\u3092\u4f5c\u6210\r\n\r\n\r\n\r\n\tvoid OnJoinedLobby() {\r\n\t\t\tDebug.Log(\"\u30ed\u30d3\u30fc\u306b\u5165\u5ba4\");\r\n\t\t\t\/\/\u30e9\u30f3\u30c0\u30e0\u306b\u30eb\u30fc\u30e0\u3078\u53c2\u52a0\r\n\r\n\t\t\/\/thi wrok\r\n\t\t\/\/PhotonNetwork.JoinRandomRoom();\/\/ join to random room tempolary\r\n\t\t\/\/until here\/\/\r\n\r\n\t\t}\r\n\r\n\r\n\r\n\tvoid OnReceivedRoomListUpdate()\r\n\t{\r\n\t\tCreateRoom ();\r\n\t}\r\n\r\n\r\n\t\/\/\/\/\/test 24th January\r\n\r\n\tpublic void CreateRoom (){\r\n\t\tRoomOptions roomOptions = new RoomOptions ();\r\n\t\troomOptions.isVisible = true;\r\n\t\troomOptions.isOpen = true;\r\n\t\troomOptions.maxPlayers = 50;\/\/test 50 max players\r\n\t\troomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable (){{\"CustomProperties\", \"111\"},{\"r\", \"0.2\"}};\r\n\t\troomOptions.customRoomPropertiesForLobby = new string[] {\"CustomProperties\"};\r\n\r\n\t\tif (PhotonNetwork.GetRoomList ().Length == 0) {\r\n\t\t\tPhotonNetwork.CreateRoom (roomName, roomOptions, null);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tforeach (RoomInfo roomInfo in PhotonNetwork.GetRoomList()) {\r\n\t\t\tif (roomInfo.name != roomName) {\r\n\t\t\t\tPhotonNetwork.CreateRoom (roomName, roomOptions, null);\r\n\t\t\t} else {\r\n\t\t\t\t\/\/isRoomEnabled = true;\r\n\t\t\t\tPhotonNetwork.JoinRoom(roomName);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t\/\/\/ \u90e8\u5c4b\u306b\u5165\u308b\u3068\u304d\u547c\u3070\u308c\u307e\u3059\u3002\r\n\t\t\/\/\/ \u3053\u308c\u306f\u53c2\u52a0\u3059\u308b\u969b\u3060\u3051\u3067\u306a\u304f\u4f5c\u6210\u3059\u308b\u969b\u3082\u542b\u307f\u307e\u3059\u3002\r\n\t\tvoid OnJoinedRoom() {\r\n\t\tDebug.Log(\"\u90e8\u5c4b\u306b\u5165\u5ba4\" + PhotonNetwork.room.name);\r\n\r\n\t\t\/\/\u30b2\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\u3059\u308b\u6642\u7528\r\n\t\t\/\/GameObject cube = PhotonNetwork.Instantiate(objectName, Vector3.zero, Quaternion.identity, 0);\r\n\r\n\t\t\/\/make cube\r\n\t\t\/\/GameObject player = PhotonNetwork.Instantiate(\"testobj\", this.transform.position, this.transform.rotation, 0);\r\n\t\t}\r\n\r\n\t\t\/\/\/ JoinRandom()\u306e\u5165\u5ba4\u304c\u5931\u6557\u3057\u305f\u5834\u5408\u306b\u5f8c\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002\r\n\t\tvoid OnPhotonRandomJoinFailed() {\r\n\t\t\/\/void OnPhotonJoinFailed() {\r\n\t\t\tDebug.Log(\"\u90e8\u5c4b\u5165\u5ba4\u5931\u6557\");\r\n\t\t\t\/\/\u540d\u524d\u306e\u306a\u3044\u30eb\u30fc\u30e0\u3092\u4f5c\u6210\r\n\t\t\/\/\tPhotonNetwork.CreateRoom(null);\r\n\r\n\t\t\/\/\/\/\/\u4ee5\u4e0b\u306f\u30c6\u30b9\u30c8\u7528\u3048\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u3044\u307e\u3059 \r\n\t\t\/\/create custom property\r\n\t\/\/\tRoomOptions myOptions = new RoomOptions ();\/\/ require use custom property\r\n\t\/\/\tmyOptions.isVisible = true;\r\n\t\/\/\tmyOptions.isOpen = true;\r\n\t\/\/\tmyOptions.maxPlayers = 50;\r\n\t\/\/\tmyOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable (){{\"CustomProperties\", \"111\"},{\"r\", \"0.2\"}};\r\n\t\/\/\tmyOptions.customRoomPropertiesForLobby = new string[] {\"CustomProperties\"};\r\n\r\n\t\t\/\/ \u30eb\u30fc\u30e0\u306e\u4f5c\u6210\r\n\t\/\/\tPhotonNetwork.JoinOrCreateRoom(roomName, myOptions, null);\r\n\r\n\r\n\t\t}\r\n\r\n\r\n\t\tvoid Awake() {\r\n\t\t\t\/\/\u30de\u30b9\u30bf\u30fc\u30b5\u30fc\u30d0\u30fc\u3078\u63a5\u7d9a\r\n\t\t\tPhotonNetwork.ConnectUsingSettings(\"v0.1\");\r\n\r\n\r\n\t\tif (PhotonNetwork.playerName==null)\r\n\t\t{\r\n\t\t\t\/\/\u30e9\u30f3\u30c0\u30e0\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u540d\u524d\u3092\u751f\u6210\r\n\t\t\tthis.playerName = \"Guest\" + UnityEngine.Random.Range(1, 9999);\r\n\t\t\t\/\/Photon\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u3092\u767b\u9332\r\n\t\t\tPhotonNetwork.playerName = this.playerName; \r\n\t\t}else{\r\n\t\t\t\/\/Photon\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u3092\u767b\u9332\r\n\t\t\tthis.playerName = PhotonNetwork.playerName;\r\n\t\t}\r\n\r\n\t\t}\r\n\r\n\r\n\t\/\/\u90e8\u5c4b\u4f5c\u6210\u306b\u6210\u529f\u3057\u305f\u3068\u304d\u306b\u30b3\u30fc\u30eb\r\n\tpublic void OnCreatedRoom(){\r\n\t\tDebug.Log(\"OnCreatedRoom\");\r\n\t}\r\n\t\/\/\u63a5\u7d9a\u304c\u5207\u65ad\u3055\u308c\u305f\u3068\u304d\u306b\u30b3\u30fc\u30eb\r\n\tpublic void OnDisconnectedFromPhoton(){\r\n\t\tDebug.Log(\"Disconnected from Photon.\");\r\n\t}\r\n\t\/\/\u63a5\u7d9a\u5931\u6557\u6642\u306b\u30b3\u30fc\u30eb\r\n\tpublic void OnFailedToConnectToPhoton(object parameters){\r\n\t\tthis.connectFailed = true;\r\n\t\tDebug.Log(\"OnFailedToConnectToPhoton. StatusCode: \" + parameters + \" ServerAddress: \" + PhotonNetwork.networkingPeer.ServerAddress);\r\n\t}\r\n\r\n\t}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity\u3067\u4f5c\u6210\u4e2d\u306e\u30a4\u30d9\u30f3\u30c8\u7528\u30a2\u30d7\u30ea\u306e\u4f5c\u6210\u30e1\u30e2\u3067\u3059 \u73fe\u5728\u4f5c\u6210\u4e2d\u306e\u30a2\u30d7\u30ea\u3067\u3059\u304c\uff0c\u540c\u671f\u306a\u3069\u306e\u95a2\u4fc2\u304b\u3089\uff08\u305f\u3076\u3093\uff09\u5168\u54e1\u304c\u540c\u3058\u90e8\u5c4b\u306b\u5165\u308b\u3053\u3068\u304c\u5fc5\u8981\u3067\u3059\uff0e \u305d\u3053\u3067\u3044\u308d\u3044\u308d\u9762\u5012\u304c\u767a\u751f\u3057\u307e\u3059\uff08\u4ee5\u4e0b\uff0cphoton\u306e\u30ec\u30d9\u30eb\u5225\u30de\u30c3\u30c1\u30e1\u30a4\u30af\u306e\u30b9 &hellip; <a href=\"https:\/\/nantoka.filmm.info\/blog\/?p=785\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Unity\u3067Photon\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u305d\u306e\uff12<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,26,2],"tags":[],"class_list":["post-785","post","type-post","status-publish","format-standard","hentry","category-c","category-photon","category-unity"],"_links":{"self":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=785"}],"version-history":[{"count":2,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":787,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions\/787"}],"wp:attachment":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}