Показать сообщение отдельно
Старый 17.07.2012, 09:30   #9
pax
Unity/C# кодер
 
Аватар для pax
 
Регистрация: 03.10.2005
Адрес: Россия, Рязань
Сообщений: 7,568
Написано 3,006 полезных сообщений
(для 5,323 пользователей)
Ответ: Вопрос по созданию игрового интерфейса

Как тот так (AlignGUITexture.cs):

using UnityEngine;

[
RequireComponent(typeof(GUITexture))]
public class 
AlignGUITexture : MonoBehaviour
{
    public 
Alignment alignment;

    public 
enum Alignment
    
{
        
None,
        
LeftUp,
        
LeftDown,
        
RightUp,
        
RightDown
    
}

    public 
float offsetX;
    public 
float offsetY;
    public 
float width;
    public 
float height;
    public 
int defaultScreenHeight = 768;
    public 
bool correctSize = true;

    
void Reset()
    {
        if(
guiTexture)
        {
            
width = guiTexture.pixelInset.width;
            
height = guiTexture.pixelInset.height;
        }
    }

    
void Start()
    {
        
float x = offsetX;
        
float y = offsetY;
        
float w = width;
        
float h = height;

        if (
correctSize)
        {
            var 
scale = (float)Screen.height/defaultScreenHeight;
            
x *= scale;
            
y *= scale;
            
w *= scale; 
            
h *= scale;
        }

        switch (
alignment)
        {
            case 
Alignment.None:

                break;
            case 
Alignment.LeftUp:
                
transform.position = new Vector3(0, 1, transform.position.z);
                
guiTexture.pixelInset = new Rect(x, -h - y, w, h);
                break;
            case 
Alignment.LeftDown:
                
transform.position = new Vector3(0, 0, transform.position.z);
                
guiTexture.pixelInset = new Rect(x, y, w, h);
                break;
            case 
Alignment.RightUp:
                
transform.position = new Vector3(1, 1, transform.position.z);
                
guiTexture.pixelInset = new Rect(-x - w, -h - y, w, h);
                break;
            case 
Alignment.RightDown:
                
transform.position = new Vector3(1, 0, transform.position.z);
                
guiTexture.pixelInset = new Rect(-x - w, y, w, h);
                break;
        }
    }
} 
__________________
Blitz3d to Unity Wiki
(Offline)
 
Ответить с цитированием
Сообщение было полезно следующим пользователям:
Radnk (17.07.2012)