GuiRatioFixer

From Unify Community Wiki
Revision as of 06:59, 1 December 2005 by Aarku (Talk | contribs)

Jump to: navigation, search

Author: Jonathan Czeck (aarku)

Contents

Description

This script will adjust the aspect ratio of a GUIText or GUITexture object by scaling it horizontally to fit the proportions.

It does not know how to align groups of GUI objects after it adjusts their aspect ratio.

Usage

Place this script on a GameObject with a GUIText and/or GUITexture component. Then, adjust the Native Ratio to your native aspect ratio desired. This is horizontal/vertical.

C# - GuiRatioFixer.cs

using UnityEngine;
using System.Collections;

// Use this on a guiText or guiTexture object to automatically have them
// adjust their aspect ratio when the game starts.

public class GuiRatioFixer : MonoBehaviour
{
	public float m_NativeRatio = 1.3333333333333F;
	
	void Start ()
	{
		float currentRatio = (float)Screen.width / (float)Screen.height;
		Vector3 scale = transform.localScale;
		scale.x *= m_NativeRatio / currentRatio;
		transform.localScale = scale;
	}
	
}

Boo - GuiRatioFixer.boo

import UnityEngine

# Use this on a guiText or guiTexture object to automatically have them
# adjust their aspect ratio when the game starts.

class GuiRatioFixer (MonoBehaviour):
	public m_NativeRatio = 1.3333333333333
	
	Start ():
		currentRatio = (Screen.width+0.0) / Screen.height
		scale = transform.localScale
		scale.x *= m_NativeRatio / currentRatio
		transform.localScale = scale

JavaScript - GuiRatioFixer.js

// Use this on a guiText or guiTexture object to automatically have them
// adjust their aspect ratio when the game starts.
var m_NativeRatio = 1.3333333333333;
	
currentRatio = (Screen.width+0.0) / Screen.height;
transform.localScale.x *= m_NativeRatio / currentRatio;
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox