Created
August 21, 2013 05:59
-
-
Save tsubaki/6290796 to your computer and use it in GitHub Desktop.
解像度によってGUITextureの大きさを変更するサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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