[Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã(NGUI2.3.0対å¿ç)
以å [Unity]NGUIã§ç»é¢ãµã¤ãºã«åããã(ãã®2) ã§æ¸ããã¹ã¯ãªããã、NGUI 2.3.0 ã®å¤æ´ã¨ã®å
¼ãåãã§æ£ããåããªããªã£ã¦ããã®ã§、ä»æ´ã§ãã対å¿çã§ã。
UIRoot.automatic ã obsolete æ±ãã«ãªã、代ããã« scalingStyle ã¨ãããã©ã¡ã¼ã¿ã«å¤æ´ã«ãªã£ãããã§ã。
横ãã¯ã¿åºãªãããã«ç»é¢ã®å¹ ã«åãããæ©è½ã¯ç¾å¨ã§ããªãããã§ãã。
ã¨ããããã§、æ°è¡ããå¤ãã£ã¦ãã¾ããã 2.3.0 対å¿çã§ã。
2013/5/4 20:23 è¿½è¨ : ã¹ã¯ãªããã«ä½è¨ãªè¡ããã£ãã®ãä¿®æ£ãã¾ãã。
UIRoot.automatic ã obsolete æ±ãã«ãªã、代ããã« scalingStyle ã¨ãããã©ã¡ã¼ã¿ã«å¤æ´ã«ãªã£ãããã§ã。
- PixelPerfect : æ¡å¤§ç¸®å°ããªã(automatic = true ç¸å½)
- FixedSize : ç»é¢ã®é«ãã«åããã(automatic = false ç¸å½)
- FixedSizeOnMobile : iOS, Android ã®ã¨ã㯠FixedSize、ãã以å¤ã§ã¯ PixedPerfect
横ãã¯ã¿åºãªãããã«ç»é¢ã®å¹ ã«åãããæ©è½ã¯ç¾å¨ã§ããªãããã§ãã。
ã¨ããããã§、æ°è¡ããå¤ãã£ã¦ãã¾ããã 2.3.0 対å¿çã§ã。
using UnityEngine; [ExecuteInEditMode] public class UIRootScale : MonoBehaviour { public int manualWidth = 1280; public int manualHeight = 720; UIRoot uiRoot_; public float ratio { get { if(!uiRoot_){ return 1.0F; } return (float)Screen.height / uiRoot_.manualHeight; } } void Awake() { uiRoot_ = GetComponent<UIRoot>(); } void Update() { if(!uiRoot_ || manualWidth <= 0 || manualHeight <= 0){ return; } int h = manualHeight; float r = (float)(Screen.height * manualWidth) / (Screen.width * manualHeight); // (Screen.height / manualHeight) / (Screen.width / manualWidth) if(r > 1.0F){ h = (int)(h * r); } // to pretend target height is more high, because screen width is too smaller to show all UI //if(uiRoot_.automatic){ uiRoot_.automatic = false; } // for before NGUI 2.3.0 if(uiRoot_.scalingStyle != UIRoot.Scaling.FixedSize){ uiRoot_.scalingStyle = UIRoot.Scaling.FixedSize; } // for NGUI 2.3.0 or later if(uiRoot_.manualHeight != h){ uiRoot_.manualHeight = h; } if(uiRoot_.minimumHeight > 1){ uiRoot_.minimumHeight = 1; } // only for NGUI 2.2.2 to 2.2.4 if(uiRoot_.maximumHeight < System.Int32.MaxValue){ uiRoot_.maximumHeight = System.Int32.MaxValue; } // only for NGUI 2.2.2 to 2.2.4 } }
2013/5/4 20:23 è¿½è¨ : ã¹ã¯ãªããã«ä½è¨ãªè¡ããã£ãã®ãä¿®æ£ãã¾ãã。
[ExecuteInEditMode]
è¿ä¿¡åé¤ãä»ããããã®ã¯çç±ãããã®ã§ãããã?
ã¾ã、Updateããã«1度ã ãã§ã大ä¸å¤«ã¨æãã¾ã。
ã©ã¡ãã Unity ã¨ãã£ã¿ã® Game View ã®åçãªãµã¤ãºå¤æ´ã«å¯¾å¿ããããã§ã。
åé¤ãæ°ä»ãã®éã、ãªãªã¼ã¹æã«ã¯ä¸åº¦ã ãå®è¡ã«ããæ¹ãããã¨æãã¾ã。