Unity NGUI2.3.4で画面アスペクト比を固定する

ウダサンコウボウ:Unity]NGUIで画面サイズに合わせる(NGUI2.2.2対応版)
リンク先は2.2.2対応とのことでしたが、そのままで2.3.4で動きました

NGUI2.3.4では、縦方向基準での調整しか実装されてないのでiPhone5のような縦長の端末だと縦方向に合わせようとする→左右がカットされるという問題が起きてしまいます。
下記のスレッドを読む限り「NGUIに新たなオプションつけたら混乱を招くかもね。補助スクリプト使おうぜ」というニュアンスのようなので、今後のバージョンでも追加されないはず

http://www.tasharen.com/forum/index.php?topic=1933.15

スレッドにも同じコードが投稿されてましたけど


using UnityEngine;
using System.Collections;
 
[ExecuteInEditMode]
public class NGUIUtilScalableUIRoot : MonoBehaviour
{
 public int manualWidth = 640;
 public int manualHeight = 960;
  
 UIRoot uiRoot_;
  
 void Awake()
 {
  uiRoot_ = GetComponent();
 }
  
 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){ 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; }
  if(uiRoot_.manualHeight != h){ uiRoot_.manualHeight = h; }
 }
}

このコードをUI Root(2D)あたりに張り付ければOK

リンク先では、カメラの外側も見えてしまうから黒いパネルで隠そうぜ!って感じですが、
背景となる適当な画像を画面サイズの外側の分もデザインして、はみ出る状態で設置することで解決してみた