[Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã
2012/8/24 è¿½è¨ : 以ä¸、ããããã®æ¹ã¯ [Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã(ãã®2) ã®æ¹ãããããã§ã。
NGUI ã§è¤æ°è§£å度対å¿ã®ããã«、ç»é¢ãµã¤ãºã«åããã¦æ¡å¤§ç¸®å°ããã¹ã¯ãªãã。
Panel ã«è¿½å ãã¦、ã¤ã³ã¹ãã¯ã¿ã§ Base Object ã«ç»é¢ãµã¤ãºã®åºæºã¨ãªã GameObject (ä¾ãã°ããã©ã«ã 1280*720 ã§ä½ã£ã¦ãããªã、ãã®ãµã¤ãºã® GameObject) ããã©ãã°&ããããããã°ä½¿ãã¾ã。
èµ·åä¸ã«ç»é¢ãµã¤ãºã®å¤æ´ããªããªã、Update() ã§ãªã Start() ã§ãã£ã¦ãã¾ã£ãã»ããããã§ã。
Aspect Fit = true ã ã¨ç°ãªãã¢ã¹ãã¯ãæ¯ã®ãã£ã¹ãã¬ã¤ã§ä¸ä¸ãå·¦å³ãä½ãã¾ã。ãã®é¨åã®å¡ãã¤ã¶ãè²ãå¤æ´ãããå ´åã¯、Camera ã® Clear Flags ã Solid Color ã«ã㦠Background ã§è²ãé¸æããã° OK ã§ã。
ãªã、localScale ã® setter ã®å é¨å®è£ (INTERNAL_set_localScale()) ã«ãã£ã¦ã¯、ããããã㨠21 è¡ç®ã
ã¨æ¸ããã»ããå¹çãããããããã¾ããã、å°ããªããã¸ã§ã¯ãã§è©¦ããç¯å²ã§ã¯éãã¯è¦ããã¾ããã§ãã。
ã¾ã、ããã¾ã§æ¡å¤§ç¸®å°ã§ãã®ã§、çµµãã¤ã¶ãããç²ããªã£ãããã¦ãã¾ãã¾ã。ããã¯ããããããã HD ç¨ç»åãç¨æãããªã©ãã¦å¥é対å¦ããå¿ è¦ãããããããã¾ãã。
ç»é¢ãå¼ã伸ã°ããã«、UIAnchor + UIStretch ã§å¯¾å¿ããå ´åã®èª¬æ㯠NGUI å ¬å¼ã®ããã¥ã¡ã³ã ( NGUI Example: UIAnchor » Tasharen Entertainment ) ã«ããã¾ã。
åè:
Unity Script Reference - Transform
2012/8/24 è¿½è¨ : [Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã(ãã®2) ãæ¸ãã¾ãã。
NGUI ã§è¤æ°è§£å度対å¿ã®ããã«、ç»é¢ãµã¤ãºã«åããã¦æ¡å¤§ç¸®å°ããã¹ã¯ãªãã。
Panel ã«è¿½å ãã¦、ã¤ã³ã¹ãã¯ã¿ã§ Base Object ã«ç»é¢ãµã¤ãºã®åºæºã¨ãªã GameObject (ä¾ãã°ããã©ã«ã 1280*720 ã§ä½ã£ã¦ãããªã、ãã®ãµã¤ãºã® GameObject) ããã©ãã°&ããããããã°ä½¿ãã¾ã。
using UnityEngine; using System.Collections; public class ScreenScaler : MonoBehaviour { public GameObject baseObject; public bool aspectFit = true; void Update(){ Vector3 ratio = new Vector3( Screen.width / baseObject.transform.localScale.x, Screen.height / baseObject.transform.localScale.y, 1.0f ); if(aspectFit){ if(ratio.x > ratio.y){ ratio.x = ratio.y; } else if(ratio.y > ratio.x){ ratio.y = ratio.x; } } transform.localScale = ratio; } }
èµ·åä¸ã«ç»é¢ãµã¤ãºã®å¤æ´ããªããªã、Update() ã§ãªã Start() ã§ãã£ã¦ãã¾ã£ãã»ããããã§ã。
Aspect Fit = true ã ã¨ç°ãªãã¢ã¹ãã¯ãæ¯ã®ãã£ã¹ãã¬ã¤ã§ä¸ä¸ãå·¦å³ãä½ãã¾ã。ãã®é¨åã®å¡ãã¤ã¶ãè²ãå¤æ´ãããå ´åã¯、Camera ã® Clear Flags ã Solid Color ã«ã㦠Background ã§è²ãé¸æããã° OK ã§ã。
ãªã、localScale ã® setter ã®å é¨å®è£ (INTERNAL_set_localScale()) ã«ãã£ã¦ã¯、ããããã㨠21 è¡ç®ã
if(transform.localScale != ratio){ transform.localScale = ratio; }
ã¨æ¸ããã»ããå¹çãããããããã¾ããã、å°ããªããã¸ã§ã¯ãã§è©¦ããç¯å²ã§ã¯éãã¯è¦ããã¾ããã§ãã。
ã¾ã、ããã¾ã§æ¡å¤§ç¸®å°ã§ãã®ã§、çµµãã¤ã¶ãããç²ããªã£ãããã¦ãã¾ãã¾ã。ããã¯ããããããã HD ç¨ç»åãç¨æãããªã©ãã¦å¥é対å¦ããå¿ è¦ãããããããã¾ãã。
ç»é¢ãå¼ã伸ã°ããã«、UIAnchor + UIStretch ã§å¯¾å¿ããå ´åã®èª¬æ㯠NGUI å ¬å¼ã®ããã¥ã¡ã³ã ( NGUI Example: UIAnchor » Tasharen Entertainment ) ã«ããã¾ã。
åè:
Unity Script Reference - Transform
2012/8/24 è¿½è¨ : [Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã(ãã®2) ãæ¸ãã¾ãã。
ã³ã¡ã³ã
ã³ã¡ã³ããæ稿