{"id":791,"date":"2016-01-25T23:00:59","date_gmt":"2016-01-25T14:00:59","guid":{"rendered":"http:\/\/nantoka.filmm.info\/blog\/?p=791"},"modified":"2016-01-25T23:00:59","modified_gmt":"2016-01-25T14:00:59","slug":"photon%e3%80%80%e7%89%b9%e5%ae%9a%e5%90%8d%e3%81%ae%e3%83%ab%e3%83%bc%e3%83%a0%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b%e3%81%8b%e3%81%9d%e3%81%93%e3%81%ab%e5%85%a5%e5%ae%a4%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/nantoka.filmm.info\/blog\/?p=791","title":{"rendered":"photon\u3000\u7279\u5b9a\u540d\u306e\u30eb\u30fc\u30e0\u3092\u4f5c\u6210\u3059\u308b\u304b\u305d\u3053\u306b\u5165\u5ba4\u3059\u308b"},"content":{"rendered":"<p>\u3069\u3046\u3057\u3066\u3082\u540c\u3058\u30eb\u30fc\u30e0\u306b\u5165\u308a\uff0ccustomRoomProperties\u3092\u53d6\u5f97\u3057\u3066\uff0c\u540c\u3058\u30eb\u30fc\u30e0\u306b\u5165\u5ba4\u3057\u3066\u3044\u308b\u4eba\u5168\u54e1\u306b\u540c\u3058\u8a2d\u5b9a\u3092\u4e0e\u3048\u305f\u304b\u3063\u305f\u306e\u3067\uff0e<\/p>\n<p>\uff08\uff11\uff09\u307e\u305a\u30eb\u30fc\u30e0\u4f5c\u6210\u306e\u30b9\u30af\u30ea\u30d7\u30c8<\/p>\n<p>\u3053\u308c\u306f\u7a7a\u306e\u30b2\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5f53\u3066\u308b<\/p>\n<pre class=\"lang:default decode:true \" title=\"photonsystem.cs\">using UnityEngine;\r\nusing System.Collections;\r\nusing Hashtable = ExitGames.Client.Photon.Hashtable; \/\/require for generate hashtable\r\n\r\npublic class photonsystem : Photon.MonoBehaviour {\r\n\tpublic string objectName;\/\/use for photon instantiate\r\n\tprivate bool connectFailed = false; \/\/use for network status check\r\n\r\n\t\/\/set player name\r\n\tprivate string playerName = \"GuestAAA\";\/\/a player name\r\n\t\/\/set room name\r\n\tprivate string roomName = \"liub2\";\/\/liub2\u3068\u3044\u3046\u5c02\u7528\u306e\u30eb\u30fc\u30e0\u540d\u3092\u4f5c\u6210\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\t\t}\r\n\r\n\r\n\t\/\/call when room list upadate \"must use\"\r\n\tvoid OnReceivedRoomListUpdate(){\r\n\t\tCreateRoom ();\r\n\t}\r\n\r\n\r\n\t\/\/\/\/\/create room with custom room options\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\", \"blue\"}};\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\/\/room name matched\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\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<p>\uff08\uff12\uff09\u305d\u306e\u30ab\u30b9\u30bf\u30e0\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u547c\u3073\u51fa\u3059\u30b9\u30af\u30ea\u30d7\u30c8<\/p>\n<p>\u3053\u308c\u3092\u30e9\u30a4\u30c8\u306b\u30a2\u30b5\u30a4\u30f3\u3057\u3066\u3044\u307e\u3059<\/p>\n<pre class=\"lang:c# decode:true \" title=\"cpLight\">using UnityEngine;\r\nusing System.Collections;\r\nusing Hashtable = ExitGames.Client.Photon.Hashtable;\r\nusing UnityEngine.UI;\r\n\r\npublic class cpLight : MonoBehaviour {\r\n\tpublic Light lightObj2;\r\n\tprivate string cpstring = \"red\";\r\n\r\n\t\/\/ Use this for initialization\r\n\tvoid Start () {\r\n\t\tlightObj2 = GetComponent&lt;Light&gt;();\r\n\t}\r\n\t\r\n\t\/\/ Update is called once per frame\r\n\tvoid Update () {\r\n\r\n\t\r\n\t}\r\n\r\n\r\n\t\/\/cp changed is here\r\n\tvoid OnPhotonCustomRoomPropertiesChanged(){\r\n\t\r\n\t\tif (PhotonNetwork.inRoom) {\/\/ \u30eb\u30fc\u30e0\u306e\u72b6\u614b\u3092\u53d6\u5f97\r\n\t\t\tRoom room = PhotonNetwork.room;\r\n\t\t\tif (room == null) {\r\n\t\t\t\treturn;\r\n\t\t\t} else {\r\n\t\t\t\tHashtable cp = room.customProperties;\r\n\t\t\t\t\/\/cpstring = (string)cp [\"r\"];\r\n\t\t\t\tcpstring = (string)cp [\"r\"];\r\n\t\t\t\t\/\/Debug.Log (cp [\"r\"]);\r\n\t\t\t\tif (cpstring == \"blue\") {\r\n\t\t\t\t\tlightObj2.color = Color.blue;\r\n\t\t\t\t\t\/\/GetComponent&lt;Light&gt;.color = Color.blue;\r\n\t\t\t\t}\r\n\t\t\t\tif (cpstring == \"red\") {\r\n\t\t\t\t\tlightObj2.color = Color.red;\r\n\t\t\t\t\t\/\/GetComponent&lt;Light&gt;.color = Color.blue;\r\n\t\t\t\t}\r\n\t\t\t\tif (cpstring == \"green\") {\r\n\t\t\t\t\tlightObj2.color = Color.green;\r\n\t\t\t\t\t\/\/GetComponent&lt;Light&gt;.color = Color.blue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t}\r\n\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\uff08\uff13\uff09\u30c6\u30b9\u30c8\u7528\u306b\u30dc\u30bf\u30f3\u3092\u4f5c\u6210\u3057\uff0c\u305d\u306e\u30dc\u30bf\u30f3\u306b\u3042\u3066\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059<\/p>\n<pre class=\"lang:default decode:true \" title=\"lightColor.cs\">using UnityEngine;\r\nusing System.Collections;\r\nusing Hashtable = ExitGames.Client.Photon.Hashtable;\r\n\r\npublic class lightColor : Photon.MonoBehaviour {\r\n\r\n\tpublic Light lightObj;\r\n\r\n\t\/\/ Use this for initialization\r\n\tvoid Start () {\r\n\t\r\n\t}\r\n\t\r\n\t\/\/ Update is called once per frame\r\n\tvoid Update () {\r\n\r\n\r\n\t\/\/\tif (!photonView.isMine) {\r\n\t\t\t\/\/transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);\r\n\t\t\t\/\/transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);\r\n\r\n\r\n\t\/\/\t}\r\n\t\r\n\t}\r\n\r\n\tpublic void colorRed(){\r\n\t\t\/\/lightObj.color = Color.red;\r\n\tExitGames.Client.Photon.Hashtable h = new ExitGames.Client.Photon.Hashtable() { { \"r\", \"red\" } };\r\n\tPhotonNetwork.room.SetCustomProperties(h);\r\n\r\n\t}\r\n\r\n\r\n\tpublic void colorGreen(){\r\n\t\/\/\tlightObj.color = Color.green;\r\n\t\tExitGames.Client.Photon.Hashtable h = new ExitGames.Client.Photon.Hashtable() { { \"r\", \"green\" } };\r\n\t\tPhotonNetwork.room.SetCustomProperties(h);\r\n\t}\r\n\r\n\tpublic void colorBlue(){\r\n\r\n\t\tExitGames.Client.Photon.Hashtable h = new ExitGames.Client.Photon.Hashtable() { { \"r\", \"blue\" } };\r\n\t\tPhotonNetwork.room.SetCustomProperties(h);\r\n\t\/\/\tlightObj.color = Color.blue;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>\u3053\u308c\u3067\uff0c\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068<\/p>\n<p><a href=\"http:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2.jpg\" rel=\"attachment wp-att-792\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-792\" src=\"http:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2-250x300.jpg\" alt=\"photon2\" width=\"250\" height=\"300\" srcset=\"https:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2-250x300.jpg 250w, https:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2-768x922.jpg 768w, https:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2-853x1024.jpg 853w, https:\/\/nantoka.filmm.info\/blog\/wp-content\/uploads\/2016\/01\/photon2.jpg 1128w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>\u3053\u306e\u30a2\u30d7\u30ea\u306e\u753b\u9762\u306f\u5168\u3066\u540c\u3058\u8272\u306b\u306a\u308a\u307e\u3059\uff0e\u30bf\u30a4\u30e0\u30e9\u30b0\u306f1\u79d2\u4ee5\u5185\u304f\u3089\u3044\u3067\u3059<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3057\u3066\u3082\u540c\u3058\u30eb\u30fc\u30e0\u306b\u5165\u308a\uff0ccustomRoomProperties\u3092\u53d6\u5f97\u3057\u3066\uff0c\u540c\u3058\u30eb\u30fc\u30e0\u306b\u5165\u5ba4\u3057\u3066\u3044\u308b\u4eba\u5168\u54e1\u306b\u540c\u3058\u8a2d\u5b9a\u3092\u4e0e\u3048\u305f\u304b\u3063\u305f\u306e\u3067\uff0e \uff08\uff11\uff09\u307e\u305a\u30eb\u30fc\u30e0\u4f5c\u6210\u306e\u30b9\u30af\u30ea\u30d7\u30c8 \u3053\u308c\u306f\u7a7a\u306e\u30b2\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5f53\u3066\u308b usi &hellip; <a href=\"https:\/\/nantoka.filmm.info\/blog\/?p=791\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">photon\u3000\u7279\u5b9a\u540d\u306e\u30eb\u30fc\u30e0\u3092\u4f5c\u6210\u3059\u308b\u304b\u305d\u3053\u306b\u5165\u5ba4\u3059\u308b<\/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-791","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\/791","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=791"}],"version-history":[{"count":1,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/791\/revisions"}],"predecessor-version":[{"id":793,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/791\/revisions\/793"}],"wp:attachment":[{"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nantoka.filmm.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}