Skip to content

Instantly share code, notes, and snippets.

@nutti
Last active August 29, 2015 14:11
Show Gist options
  • Save nutti/d6cc2dea5370dd28d86a to your computer and use it in GitHub Desktop.
Save nutti/d6cc2dea5370dd28d86a to your computer and use it in GitHub Desktop.
[Unity] 複数の端末の解像度に対応させる2 - GUITexutreの表示を解像度と非依存にする ref: http://qiita.com/nutti/items/f4e0d4241480345a2b10
#pragma strict
var aspectRatioCtrl : Fixed_Aspect_Ratio = null; // 解像度固定スクリプト
var x : float = 0.0f; // 表示位置(X座標)
var y : float = 0.0f; // 表示位置(Y座標)
var width : float = 1.0f; // 横幅
var height : float = 1.0f; // 縦幅
function Update()
{
var texture : GUITexture;
texture = GetComponent(GUITexture);
// GUITextureと同じGameObjectに本コンポーネントが存在している必要がある
if (!texture) { return; }
// 解像度固定スクリプトにより制御された解像度
if (aspectRatioCtrl) {
var rect : Rect;
rect = aspectRatioCtrl.camRect;
texture.pixelInset.x = (x * rect.width) * Screen.width;
texture.pixelInset.y = (y * rect.height) * Screen.height;
texture.pixelInset.width = width * rect.width * Screen.width;
texture.pixelInset.height = height * rect.height * Screen.height;
}
// デフォルトの解像度
else{
texture.pixelInset.x = x * Screen.width;
texture.pixelInset.y = y * Screen.height;
texture.pixelInset.width = width * Screen.width;
texture.pixelInset.height = height * Screen.height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment