{"id":745,"date":"2017-07-29T00:09:19","date_gmt":"2017-07-28T15:09:19","guid":{"rendered":"http:\/\/naochang.me\/?p=745"},"modified":"2017-07-31T17:51:13","modified_gmt":"2017-07-31T08:51:13","slug":"vr%e3%82%b3%e3%83%b3%e3%83%86%e3%83%b3%e3%83%84%e3%81%a7%e3%81%ae%e5%ad%97%e5%b9%95%e3%81%aa%e3%81%a9","status":"publish","type":"post","link":"https:\/\/stacstar.jp\/blog\/?p=745","title":{"rendered":"VR\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u306eUI\u8868\u793a"},"content":{"rendered":"<p>VR\u306b\u3066UI\u3092\u8868\u793a\u3059\u308b\u969b\u306b\u3001Camera\u306e\u8a2d\u5b9a\u306fOrthographic\u3067\u3044\u3044\u304b\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u3069\u3046\u3084\u3089VR\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u306f\uff08google VR\u3067\u306f?)\u30ab\u30e1\u30e9\u306e\u8a2d\u5b9a\u3092Orthographic\u3067\u306f\u306a\u304f\u3001Perspective\u306b\u8a2d\u5b9a\u3059\u308b\u3057\u304b\u306a\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\nPost Processing\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u305d\u306e\u5f71\u97ff\u304c\u51fa\u306a\u3044\u3088\u3046\u306b\u3001UI\u5c02\u7528\u306eCamera\u3092\u4f5c\u6210\u3057\u305d\u3061\u3089\u3092Perspective\u306b\u3057\u3001\u305d\u3061\u3089\u306bCanvas\u306eRenderMode\u3092WorldSpace\u306b\u8a2d\u5b9a\u3057\u3001\u305d\u306e\u30ab\u30e1\u30e9\u306e\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3057\u307e\u3057\u305f\u3002<br \/>\nPerspective\u306aCamera\u3078UI\u3092\u30b9\u30b1\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30d5\u30a3\u30c3\u30c8\u3055\u305b\u308b\u65b9\u6cd5\u306f<br \/>\n<!--more--><\/p>\n<pre class=\"brush: unitycsharp; title: ; notranslate\" title=\"\">\r\n#if !UNITY_EDITOR\r\nfloat screenW = Screen.width\/2f;\r\n#else\r\nfloat screenW = Screen.width;\r\n#endif\r\n\r\nfloat screenH = Screen.height;\r\n\r\nRectTransform rect = this.uiCanvas.GetComponent&lt;RectTransform&gt;();\r\nrect.sizeDelta = new Vector2(screenW, screenH);\r\nthis.uiCanvas.renderMode = RenderMode.WorldSpace;\r\nthis.uiCanvas.worldCamera = this.vrUICamera;\r\nthis.uiCanvas.transform.SetParent(this.vrUICamera.transform, false);\r\n\r\nfloat pos = this.vrUICamera.nearClipPlane + 0.01f;\r\nthis.uiCanvas.transform.position = this.vrUICamera.transform.position + this.vrUICamera.transform.forward * pos;\r\nfloat ratio = Mathf.Tan(this.vrUICamera.fieldOfView * Mathf.Deg2Rad * 0.5f) * pos * 2f \/ rect.sizeDelta.y; \/\/ Canvas\u3092\u30b9\u30af\u30ea\u30fc\u30f3\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u305f\u969b\u306b\u3001\u6307\u5b9a\u306e\u4f4d\u7f6e\u3067\u306e\u30ab\u30e1\u30e9\u306b\u30d5\u30a3\u30c3\u30c8\u3059\u308b\u500d\u7387\u306e\u8a08\u7b97\r\nthis.uiCanvas.transform.localScale = Vector3.one * ratio;\r\n<\/pre>\n<p>\u30b9\u30b1\u30fc\u30eb\u3067\u306f\u306a\u304f\u5965\u884c\u304d\u3092\u5408\u308f\u305b\u308b\u5834\u5408\u306f<\/p>\n<pre class=\"brush: unitycsharp; title: ; notranslate\" title=\"\">\r\n#if !UNITY_EDITOR\r\nfloat screenW = Screen.width\/2f;\r\n#else\r\nfloat screenW = Screen.width;\r\n#endif\r\n\r\nfloat screenH = Screen.height;\r\n\r\nRectTransform rect = this.uiCanvas.GetComponent&lt;RectTransform&gt;();\r\nrect.sizeDelta = new Vector2(screenW, screenH);\r\nthis.uiCanvas.renderMode = RenderMode.WorldSpace;\r\nthis.uiCanvas.worldCamera = this.vrUICamera;\r\nthis.uiCanvas.transform.SetParent(this.vrUICamera.transform, false);\r\n\r\nfloat frustumHeight = rect.sizeDelta.x \/ this.vrUICamera.aspect;\r\nfloat distance = frustumHeight * 0.5f \/ Mathf.Tan(this.vrUICamera.fieldOfView * 0.5f * Mathf.Deg2Rad); \/\/ Canvas\u306e\u30b5\u30a4\u30ba\u304c\u3074\u3063\u305f\u308a\u306b\u5965\u884c\u304d\u306e\u8a08\u7b97\r\n\r\n\/\/ \u30ab\u30e1\u30e9\u306e\u30af\u30ea\u30c3\u30d7\u8ddd\u96e2\u3092\u8abf\u6574\r\nif (distance &lt; this.vrUICamera.nearClipPlane)\r\n\tthis.vrUICamera.nearClipPlane = distance - 0.1f;\r\nelse if (distance &gt; this.vrUICamera.farClipPlane)\r\n\tthis.vrUICamera.farClipPlane = distance + 1f;\r\nthis.uiCanvas.transform.localPosition = new Vector3(0f, 0f, distance);\r\n<\/pre>\n<p>\u53c2\u8003\uff09<br \/>\n<a href=\"https:\/\/docs.unity3d.com\/jp\/540\/Manual\/FrustumSizeAtDistance.html\" target=\"_blank\">Unity | \u30ab\u30e1\u30e9\u304b\u3089\u306e\u8ddd\u96e2\u3067\u6c42\u3081\u308b\u9310\u53f0\u306e\u30b5\u30a4\u30ba<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>VR\u306b\u3066UI\u3092\u8868\u793a\u3059\u308b\u969b\u306b\u3001Camera\u306e\u8a2d\u5b9a\u306fOrthographic\u3067\u3044\u3044\u304b\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u3069\u3046\u3084\u3089VR\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u306f\uff08google VR\u3067\u306f?)\u30ab\u30e1\u30e9\u306e\u8a2d\u5b9a\u3092Orthographic\u3067\u306f\u306a\u304f\u3001Perspectiv [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,12],"tags":[],"class_list":["post-745","post","type-post","status-publish","format-standard","hentry","category-unity","category-xrvr"],"_links":{"self":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=745"}],"version-history":[{"count":8,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/745\/revisions"}],"predecessor-version":[{"id":765,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/745\/revisions\/765"}],"wp:attachment":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}