ãUnityéçºãuGUIã®Canvasã®ä½¿ãæ¹ãã²ããã¨ãã»ã³ã¹ã
Unity5.0.0f4 Personal(2015å¹´5æ)
Â
Â
ã²ããã¨ãã»ã³ã¹ã®æéã§ãã
ä»åã¯uGUIã®ä¸ã§ããã®åºç¤ã¨ãªãCanvasã«ã¤ãã¦è§£èª¬ãã¦ããã¾ãã
ãã®ååã®éãGUIã®æ¯æä½ã¨ãªããªãã¸ã§ã¯ãã§ãCanvasã®ä¸ã«å ¨ã¦ã®GUIã¯ä½æããã¾ãã
 uGUIã®Canvasã¾ã¨ã
â Canvasãé ç½®ãã¦ã¿ã
 ã¾ãã¯Canvasãé ç½®ãã¦ã¿ã¾ããããHierarchyãã¥ã¼ããCreate>UI>Canvasãé¸æãã¾ãã
Â
Canvasä½æ
Â
ä½æããCanvasã®åãªãã¸ã§ã¯ãã¨ãã¦æ§ã ãªGUIãä½æãããã¨ã§ãã²ã¼ã ç»é¢ã«GUIã表示ããããã¨ãã§ãã¾ãã
ã¨ãã£ã¦ããCanvasãåä½ã§ä½ããã¨ã¯ã»ã¨ãã©ããã¾ãããå ã»ã©ä½æããCanvasã¨ãä¸ç·ã«ã§ããEvent Systemãä¸æ¦åé¤ããHierarchyãã¥ã¼ããCreate>UI>Textãé¸æãã¦ä¸ããã
Â
Canvasã»Textã»EventSystemãä½æããã
Â
ãã®ããã«TextãButtonçã®GUIãä½æããã¨ãèªåçã«ä¸ç·ã«Canvasãä½æããã¾ãã
Â
Canvasã®ä¸ã«ä½æããGUIã«ã¤ãã¦ã¯ãåã¨ãã»ã³ã¹ããåç §ä¸ããã
Â
Â
ã¾ããåGUIã®å¤§ãããä½ç½®ã決å®ããRectTransformã«é¢ããã¨ãã»ã³ã¹ãããã¾ãã®ã§ãããã£ããè¦ã¦ãã£ã¦ä¸ããã
Â
Â
â¡Canvasã®åãã©ã¡ã¼ã¿ã¼è§£èª¬
ããã§ã¯Canvasãªãã¸ã§ã¯ããã¯ãªãã¯ããæã«è¦ããåãã©ã¡ã¼ã¿ã¼ã®è§£èª¬ããã¦ããã¾ããåéãå¤ãã®ã§ä»åã¯Canvasã³ã³ãã¼ãã³ãã«ã¤ãã¦ã®ã¿è§£èª¬ããCanvas Scalerã«ã¤ãã¦ã¯å¥ã¨ãã»ã³ã¹ãç¨æãããã¨æãã¾ãã
Â
Canvasãªãã¸ã§ã¯ãã®Canvasã³ã³ãã¼ãã³ã
Â
Render Modeã¯ãGUIãã©ã®ããã«æç»ãããã決ãã¾ããï¼ã¤ã®ã¢ã¼ãããé¸æãã¾ãã
Â
ï¼ã¤ã®ã¢ã¼ãããã
Â
Screen Space - Overlayã¯ãã²ã¼ã ã§ä½¿ãããä»ã®ãªãã¸ã§ã¯ãã®æç»ãçµãã£ããã¨ã«GUIãæç»ããã¾ããã¤ã¾ãGUIã絶対ã«æåé¢ã«ããã¨ããããã§ããä¸ã®ç»åã§ã¯Cubeãªãã¸ã§ã¯ãã®åã«TextGUIããã¦ãã¾ãã
Â
å¿ ãæåé¢ã«ãã
Â
ä¸ã®ç»åã§ãããå°ãTextãã¼ããã¦è¦ãã¾ãããã£ã¨ã¯ãããªã¨è¡¨ç¤ºãããã¨ããå ´åã¯ãPixel Perfectãtrueã«ããã¨è§£æ±ºãã¾ãï¼
Â
Pixel Perfect = trueã§ã¯ãããªè¡¨ç¤º
Â
æå¾ã«Sort Orderã§ãããããã¯Screen Space -Overlayè¨å®ã§ããCanvaséã®æç»é ã決ããããã®å¤ã§ãã大ããã»ããåé¢ã«è¡¨ç¤ºããã¾ãã
ããã§ããå®ã¯Canvasã¯ããã¤ã§ãä½ã£ã¦ãããã§ããããããåãRender Modeã ã¨ãã¦ãå ¨ãæ§ããªãã®ã§ãã
Â
試ãã«Canvasããµãã¤ä½ãã
Â
Â
ãããã以ä¸ã®è¨å®ã«ãã
Â
Canvas1ãScreen Space - OverlayãSort Order: 1
Â
Canvas2ãScreen Space - OverlayãSort Order: 0
Â
Gameãã¥ã¼ãè¦ã¦ã¿ãã¨ã»ã»ã»
Â
Â
Sort Orderã1ã«ããã»ããä¸ã«æç»ããã¾ãã
Â
Screen Space - Cameraã¯ãç¹å®ã®ã«ã¡ã©ã«GUIã表示ããã¾ãã
Â
Screen Space - Camera
Â
Render Cameraã«ã«ã¡ã©ãæå®ããã¨ããã®ã«ã¡ã©ã«ã®ã¿GUIã表示ããã¾ãã
試ãã«ã²ã¨ã¤Cameraãä½æãã¦ã¿ã¾ããããHierarchyããCreate>Cameraãé¸æããååãGUICameraã«ãã¦ä¸ããã
Â
GUICameraä½æ
Â
Viewport Rectã®Wã¨Hã0.5ã«å¤æ´
Â
ç»é¢å·¦ä¸ã«GUICameraã®æ åã表示ããã
Â
ãã®ç¶æ ã§Canvas1ãªãã¸ã§ã¯ãã®Render ModeãScreen Space - CameraãRender CameraãGUICameraã«è¨å®ãã¦ä¸ããã
Â
Â
ããã¨ãCanvas1ã®Textã®ã¿GUICameraã«è¡¨ç¤ºãããããã«ãªãã¾ãã
Â
Canvas1ã®ã¿GUICameraã«è¡¨ç¤ºããã
Â
Plane Distanceã¯ãã«ã¡ã©ã¨GUIã¨ã®è·é¢ãè¨å®ãã¾ããPlane Distanceãè¨å®ããçµæã«ã¡ã©ã¨GUIã®ã¨ã®éã«ãªãã¸ã§ã¯ããå ¥ãè¾¼ãã¨ãGUIã¯ãªãã¸ã§ã¯ãã®å¾ãã§è¡¨ç¤ºããã¾ãã
ä¾ãã°Cubeã®position.zã0ãGUICameraã®position.zã-10ã«è¨å®ãã¾ããããã¨ãã«ã¡ã©ã¨Cubeã¨ã®è·é¢ã¯10ã¨ãªãã¾ããããã§Plane Distanceã11ã«è¨å®ããã¨ãCubeã¨éãªã£ãGUIã¯å¾ãã«è¡¨ç¤ºããã¾ãã
Â
Plane Distance: 11ã ã¨GUIã奥
Â
ä»åº¦ã¯Plane Distanceã9ã«ãã¾ããããã¨ãGUIãåé¢ã«è¡¨ç¤ºããã¾ãã
Â
Plane Distance: 9ã ã¨GUIãåé¢
Â
Sorting Layerã¯ãRender ModeãScreen Space -Cameraå士ã®GUIã®æç»é ã決å®ãã¾ããSorting Layerã®é çªçã«ä¸ã«ããã»ããåé¢ã«è¡¨ç¤ºããã¾ãã
Orde In Layerã¯æ´ã«Sorting Layerãåãæã«æã«ãè¨å®ãã¾ããæ°ã大ããã»ããåé¢ã«è¡¨ç¤ºããã¾ãã
Â
Canvas2ã®ã»ããä¸ãªã®ã§ã
Â
Canvas2ãåé¢ã«è¡¨ç¤ºããã
Â
ã¡ãªã¿ã«Render Cameraã«ä½ãæå®ããªããã°ãScreen Point - Overlayã¨åãæ±ãã«ãªãã¾ãã
Â
World Spaceã¯ãCubeçã®ãªãã¸ã§ã¯ãã¨å ¨ãåã座æ¨ã§GUIãé ç½®ãã¾ããpositionãããããã¨ã§ãä»ã®ãªãã¸ã§ã¯ãã®å¾ãã«è¡¨ç¤ºãããã§ãã¾ãã
ããã¯ããGUIã¨ããããã¯ããªãã¸ã§ã¯ãã«ãªã£ãã¨èãã¦ã大ä¸å¤«ã§ãã
Â
ãªãã¸ã§ã¯ãã®å¾ãã¸æã£ã¦ããã°ã
Â
ä»ã®ãªãã¸ã§ã¯ãã¨åæ§ãªãã¸ã§ã¯ãã®å¾ãã¸é ãã
Â
Event Cameraã¯ãGUIã®ã¤ãã³ããåä¿¡ããã«ã¡ã©ãè¨å®ãã¦ãã¾ããä¾ãã°ããã¿ã³ã®ä¸ã«ãã¦ã¹ãæã£ã¦ãããã¯ãªãã¯ããæã«è²ãå¤ããããªã©ãã¤ãã³ãã«ãªãã¾ãã
Â
åã³GUICameraã«ç»å ´ãã¦ãããã¾ãããã
Â
å·¦ä¸ãGUICamera
Â
ããã¦æ¬¡ã«Canvasã®Render ModeãWorld Spaceã«Event Cameraã«GUICameraãè¨å®ããåãªãã¸ã§ã¯ãã¨ãã¦Buttonãã²ã¨ã¤ä½ãã¾ãã
Â
Canvasã®ä¸ã«Buttonï¼ã¤
Â
Render Mode: World SpaceãEvent Camera: GUICamera
Â
ãã®ç¶æ ã§ãã¿ã³ãç»é¢å³ä¸ã«é ç½®ãã¦ã両æ¹ã®ã«ã¡ã©ã«åãããã«ãã¦ä¸ããã
Â
ãããªæã
Â
ããã§ã¯ã²ã¼ã ãå®è¡ãã¦ä¸ããããã¿ã³ã®ã¤ãã³ããåãä»ããã®ã¯Event Cameraã«è¨å®ããGUICameraã«ç§»ã£ããã¿ã³ã®ã¿ã¨ãªã£ã¦ããã¾ãã
Â
GUICameraã®ã»ãããã¤ãã³ããåãä»ããªã
Â
é·ã ã¨æ¸ãã¦ãã¾ããããåºæ¬çã«ã¯Screen Space - Overlayã使ã£ã¦ããã°ééããªããã¨æãã¾ãã
ç»é¢ãµã¤ãºã縦横æ¯ãè¨å®ããCanvas Scalerã«ã¤ãã¦ã¯å¥éã¨ãã»ã³ã¹ãç¨æããã¦é ãã¾ãã
Â
以ä¸ãã²ããã¨ãã»ã³ã¹ã§ããã
ãããã¨ããããã¾ããã
Â