Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created August 21, 2013 05:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/6290796 to your computer and use it in GitHub Desktop.
Save tsubaki/6290796 to your computer and use it in GitHub Desktop.
解像度によってGUITextureの大きさを変更するサンプル
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[RequireComponent(typeof(GUITexture))]
public class NotPixelperfectGUITexture : MonoBehaviour
{
[SerializeField]
Vector2 screenSize = new Vector2 (800, 1280);
[SerializeField]
Rect pixelInset ;
void Start ()
{
if (pixelInset.Equals (new Rect (0, 0, 0, 0))) {
pixelInset = guiTexture.pixelInset;
}
}
void Update ()
{
float x = Screen.width / screenSize.x;
float y = Screen.height / screenSize.y;
guiTexture.pixelInset = new Rect (pixelInset.x * x, pixelInset.y * y, pixelInset.width * x, pixelInset.height * y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment