Салют!
Рисую игровой интерфейс на Unity 4.6 (ибо при переходе на 5 крашится.
Собственно суть, пытаюсь залепить в нижний угол текстуру. Юзаю для этого координаты. Разумеется, при разворачивании экрана элемент остается висеть по нужным координатам, но не уходит в угол.
GUI.DrawTexture(Rect(Screen.width - dialwidth,Screen.height - dialheight,100,100), speedOMeterDial);
Вопрос: как в Unity3D закреплять текстуры в определенном месте экрана?

Принятый ответ

А как же новая система UI, которая уже решает эту проблему?
3
29
9 лет назад
3
А как же новая система UI, которая уже решает эту проблему?
Принятый ответ
0
28
9 лет назад
0
А как же новая система UI, которая уже решает эту проблему?
Лох я. Спасибо :)
0
26
9 лет назад
0
Анчоры
0
37
9 лет назад
0
canvas же
0
27
9 лет назад
Отредактирован Devion
0
На старой системе ГУИ раньше юзал вот такой скриптик:
using UnityEngine;

public class RectDir
{
    private readonly float x, y, w, h, coefX, coefY;
    private RectDir(float x, float y, float w, float h, float coefX, float coefY)
    {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        this.coefX = coefX;
        this.coefY = coefY;
    }
    public static RectDir left { get { return new RectDir(Rect.x, Rect.y + Rect.height / 2f, 0, .5f, 1, 1); } }
    public static RectDir right { get { return new RectDir(Rect.x + Rect.width, Rect.y + Rect.height / 2f, 1, .5f, -1, 1); } }
    public static RectDir top { get { return new RectDir(Rect.x + Rect.width / 2f, Rect.y, .5f, 0, 1, 1); } }
    public static RectDir bottom { get { return new RectDir(Rect.x + Rect.width / 2f, Rect.y + Rect.height, .5f, 1, 1, -1); } }
    public static RectDir middle { get { return new RectDir(Rect.x + Rect.width / 2f, Rect.y + Rect.height / 2f, .5f, .5f, 1, 1); } }
    public static RectDir leftTop { get { return new RectDir(Rect.x, Rect.y, 0, 0, 1, 1); } }
    public static RectDir rightTop { get { return new RectDir(Rect.x + Rect.width, Rect.y, 1, 0, -1, 1); } }
    public static RectDir leftBottom { get { return new RectDir(Rect.x, Rect.y + Rect.height, 0, 1, 1, -1); } }
    public static RectDir rightBottom { get { return new RectDir(Rect.x + Rect.width, Rect.y + Rect.height, 1, 1, -1, -1); } }

    public static Rect operator +(RectDir a, Rect b)
    {
        return new Rect(a.x + a.coefX * b.x, a.y + a.coefY * b.y, b.width, b.height);
    }

    public static Rect operator +(Rect a, RectDir b)
    {
        return b + a;
    }

    public static Rect operator *(RectDir a, Rect b)
    {
        return new Rect(a.x + a.coefX * b.x - b.width * a.w, a.y + a.coefY * b.y - b.height * a.h, b.width, b.height);
    }

    public static Rect operator *(Rect a, RectDir b)
    {
        return b * a;
    }
    public static void SetDefaultRect()
    {
        isSreenPosition = true;
    }
    public static void SetParentRect(Rect rect)
    {
        isSreenPosition = false;
        _parentRect = rect;
    }

    private static Rect _parentRect;
    private static Rect Rect { get { return isSreenPosition ? new Rect(0, 0, Screen.width, Screen.height) : _parentRect; } }
    public static bool isSreenPosition = true;

}
Фактически, было проще ориентировать координаты, например:
RectDir.rightBottom * new Rect(0,0,100,100) //Так выдавал ректы изменяя выравнивание (например нижний правый угол с учетом размера ректа)
RectDir.rightBottom + new Rect(0,0,100,100) //А вот так без выравнивания (то есть x/y в этой точке несмотря на ширину и высоту)
Где-то был поправленный код, но искать влом :) В любом случае это уже часть истории, оказалось не шибко интуитивно.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.