Универсальный контроллер GUI интерфейса. (Js)

Лучший способ помочь другим, поделиться своими находками.

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение Левш@ 30 янв 2014, 18:51

не только объекты будут на своих местах, а и размер объектов будет соответсвующий

А какая разница ? Здесь тоже можно не менять размеров, только позиции.
_X.cor.R (Prologue)
Аватара пользователя
Левш@
Адепт
 
Сообщения: 4073
Зарегистрирован: 14 окт 2009, 16:34
Откуда: IBERIA
Skype: bars_levsha
  • Сайт

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение vegitto 12 мар 2014, 12:40

На gui бутон не работает ?
Аватара пользователя
vegitto
UNITрон
 
Сообщения: 244
Зарегистрирован: 08 окт 2013, 22:47

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение Левш@ 15 ноя 2014, 14:14

На gui бутон не работает ?

Сработает, только там другой отсчет координат, надо пригнать пересчет к нему.
_X.cor.R (Prologue)
Аватара пользователя
Левш@
Адепт
 
Сообщения: 4073
Зарегистрирован: 14 окт 2009, 16:34
Откуда: IBERIA
Skype: bars_levsha
  • Сайт

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение Boris3000 15 ноя 2014, 20:35

вот доработал: то что можно изменять- ширина и высота экрана на котором идут настройки, т есть теперь не на 800 и 600 а на любом, по мне оч удобно=)
Синтаксис:
Используется javascript
private var posX = 0.0;
private var posY = 0.0;
private var shirina = 0.0;
private var vysota = 0.0;
private var scrinWidth = 0.0;
private var scrinHeight = 0.0;
private var BalansWidth = 0.0;
private var BalansHeight = 0.0;
var ScreenW = 800;
var ScreenH = 600;
function Start () {
                posX = guiTexture.pixelInset.x;
                posY = guiTexture.pixelInset.y;
                shirina = guiTexture.pixelInset.width;
                vysota = guiTexture.pixelInset.height;
                scrinWidth = Screen.width;
                scrinHeight = Screen.height;
                BalansWidth = ScreenW / scrinWidth;
                BalansHeight = ScreenH / scrinHeight;
                guiTexture.pixelInset.x = posX / BalansWidth;
                guiTexture.pixelInset.y = posY / BalansHeight;
                guiTexture.pixelInset.width = shirina / BalansWidth;
                guiTexture.pixelInset.height = vysota / BalansHeight;
                GuiCorector();
}
function OnGUI ()  {
        if (scrinWidth != Screen.width || scrinHeight != Screen.height)
                GuiCorector ();
}
function GuiCorector ()  {
                posX = guiTexture.pixelInset.x;
                posY = guiTexture.pixelInset.y;
                shirina = guiTexture.pixelInset.width;
                vysota = guiTexture.pixelInset.height;
                BalansWidth = scrinWidth / Screen.width;
                BalansHeight = scrinHeight / Screen.height;
                guiTexture.pixelInset.x = posX / BalansWidth;
                guiTexture.pixelInset.y = posY / BalansHeight;
                guiTexture.pixelInset.width = shirina / BalansWidth;
                guiTexture.pixelInset.height = vysota / BalansHeight;
                scrinWidth = Screen.width;
                scrinHeight = Screen.height;
        if (guiTexture.gameObject.tag == "QwadGui") {
                guiTexture.pixelInset.x += (guiTexture.pixelInset.width - guiTexture.pixelInset.height) / 2;
                guiTexture.pixelInset.width = guiTexture.pixelInset.height;
        }
        if (guiTexture.gameObject.tag == "RadarGui")
                guiTexture.pixelInset.width = guiTexture.pixelInset.height;
}
_https://play.google.com/store/search?q=SLywnow - мои игры для android=)
Boris3000
UNITрон
 
Сообщения: 155
Зарегистрирован: 05 апр 2014, 21:13
Откуда: Отсюда
Skype: ------

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение MisterMaiklll 25 дек 2014, 21:38

Кто переделает мой скрипт а то я нечево непонял
Синтаксис:
Используется javascript
var menuInt : int = 0;
var menu1Int : int = 0;
var menu1Select : String[] = ["Экран", "Видео", "Аудио"];
var tumbler : boolean = false;
var tumbler1 : boolean = true;
var soundFloat : float = 0.07;
var label1 : boolean = true;
var label2 : String = "Ку";
var label3 : float = 15.98;
var label4 : Vector3 = Vector3(12,5,74);
var menuAnim : float = 0;
var menuAnim1 : float = 0;
var menu1Anim10 : float = 0;
var menu1Anim11 : float = 0;
var menu1Anim20 : float = 0;
var menu1Anim21 : float = 0;
var menu1Anim30 : float = 0;
var menu1Anim31 : float = 0;
var menu1sound10 : int;
var menu1sound11 : int;
var menu1sound20 : boolean;
var menu1sound21 : boolean;
var screenBox : boolean = true;
var namber : Texture[];

var point : int = 0;
var health : int = 200;

var sound1 : AudioClip;
var sound2 : AudioClip;

var boxStyle : GUIStyle;
var buttonStyle : GUIStyle;
var button1Style : GUIStyle;
var selectionStyle : GUIStyle;
var tumblerStyle : GUIStyle;
var sliderStyle1 : GUIStyle;
var sliderStyle2 : GUIStyle;
var textStyle : GUIStyle;
var health1Style : GUIStyle;
var health2Style : GUIStyle;

function OnGUI () {
GUI.Box(Rect(Screen.width-685,5,400,50), " LEVEL/XP", buttonStyle);
menuInt = 0;
GUI.Box(Rect(Screen.width-1085,5,400,50), "NikName", buttonStyle);

GUI.Box(Rect(Screen.width-1182,60,1000,40), "Меню", buttonStyle);
GUI.Box(Rect(Screen.width-1182,105,200,490), "", boxStyle);
if (menuInt == 0) {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2-95,180,40), "Играть", button1Style)) {
audio.PlayOneShot(sound1, soundFloat); Application.LoadLevel(1); menuInt = 0;
} } else {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2-95,180,40), "Играть", buttonStyle)) {
audio.PlayOneShot(sound1, soundFloat); Application.LoadLevel(1); menuInt = 0;
} }
if (menuInt == 1) {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2-45,180,40), "Настройки", button1Style)) {
menuAnim1 = -Screen.width; audio.PlayOneShot(sound1, soundFloat); menuInt = 1;
} } else {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2-45,180,40), "Настройки", buttonStyle)) {
menuAnim1 = -Screen.width; audio.PlayOneShot(sound1, soundFloat); menuInt = 1;
} }
if (menuInt == 2) {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2+5,180,40), "Авторы", button1Style)) {
menuAnim1 = Screen.width; audio.PlayOneShot(sound1, soundFloat); menuInt = 2;
} } else {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2+5,180,40), "Авторы", buttonStyle)) {
menuAnim1 = Screen.width; audio.PlayOneShot(sound1, soundFloat); menuInt = 2;
} }
if (menuInt == 3) {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2+55,180,40), "Выход", button1Style)) {
Application.Quit(); audio.PlayOneShot(sound1, soundFloat); menuInt = 3;
} } else {
if (GUI.Button(Rect(Screen.width/2-90+menuAnim,Screen.height/2+55,180,40), "Выход", buttonStyle)) {
Application.Quit(); audio.PlayOneShot(sound1, soundFloat); menuInt = 3;
} }
GUI.Box(Rect(Screen.width/2-325+menuAnim+Screen.width,Screen.height/2-200,650,70), "Настройки", boxStyle);
menu1Int = GUI.SelectionGrid(Rect(Screen.width/2-315+menuAnim+Screen.width,Screen.height/2-180,470,40), menu1Int, menu1Select, 3, selectionStyle);
/*if (GUI.Button(Rect(Screen.width/2-315,Screen.height/2-180,150,40), "Экран")) { menu1Int = 0; }
if (GUI.Button(Rect(Screen.width/2-155,Screen.height/2-180,150,40), "Видео")) { menu1Int = 1; }
if (GUI.Button(Rect(Screen.width/2+5,Screen.height/2-180,150,40), "Аудио")) { menu1Int = 2; }*/

if (GUI.Button(Rect(Screen.width/2+165+menuAnim+Screen.width,Screen.height/2-180,150,40), "Назад", buttonStyle)) {
menuAnim1 = 0; audio.PlayOneShot(sound2, soundFloat);
}

GUI.Box(Rect(Screen.width/2-325+menuAnim+Screen.width,Screen.height/2-100+menu1Anim10,650,300), "Экран", boxStyle);
screenBox = GUI.Toggle(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-60+menu1Anim10,180,20),screenBox, "Полный экран", tumblerStyle);
if (GUI.Button(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-30+menu1Anim10,180,30),"800x600",buttonStyle)) {
Screen.SetResolution(800,600,screenBox); menuAnim1 = -800; audio.PlayOneShot(sound1, soundFloat); }
if (GUI.Button(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2+10+menu1Anim10,180,30),"1024x920",buttonStyle)) {
Screen.SetResolution(1024,920,screenBox); menuAnim1 = -1024; audio.PlayOneShot(sound1, soundFloat); }
if (GUI.Button(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2+50+menu1Anim10,180,30),"1366x768",buttonStyle)) {
Screen.SetResolution(1366,768,screenBox); menuAnim1 = -1366; audio.PlayOneShot(sound1, soundFloat); }

GUI.Box(Rect(Screen.width/2-325+menuAnim+Screen.width,Screen.height/2-100+menu1Anim20,650,300), "Видео", boxStyle);
tumbler = GUI.Toggle(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-60+menu1Anim20,180,20),tumbler, "Тень", tumblerStyle);
tumbler1 = GUI.Toggle(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-30+menu1Anim20,180,20),tumbler1, "Субтитры", tumblerStyle);

GUI.Box(Rect(Screen.width/2-325+menuAnim+Screen.width,Screen.height/2-100+menu1Anim30,650,300), "Аудио", boxStyle);
GUI.Label(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-60+menu1Anim30,180,20), "Громкость звуков", textStyle);
soundFloat = GUI.HorizontalSlider(Rect(Screen.width/2-90+menuAnim+Screen.width,Screen.height/2-40+menu1Anim30,180,20),soundFloat,0.0,1.0, sliderStyle1, sliderStyle2);

GUI.Box(Rect(20+menuAnim-Screen.width,20,Screen.width-40,Screen.height-100), "Авторы", boxStyle);
GUI.Label(Rect(40+menuAnim-Screen.width,60,Screen.width-80,20), "Здесь должен быть текст "+label1+" "+label2+" "+label3+" "+label4, textStyle);
if (GUI.Button(Rect(Screen.width/2-90+menuAnim-Screen.width,Screen.height-60,180,40), "Назад", buttonStyle)) {
menuAnim1 = 0; audio.PlayOneShot(sound2, soundFloat);
}

//GUI.Label(Rect(20+menuAnim-Screen.width*2,20,200,20), ""+point);
GUI.DrawTexture(Rect(20+menuAnim-Screen.width*2,20,30,45), namber[point/1000%10]);
GUI.DrawTexture(Rect(50+menuAnim-Screen.width*2,20,30,45), namber[point/100%10]);
GUI.DrawTexture(Rect(80+menuAnim-Screen.width*2,20,30,45), namber[point/10%10]);
GUI.DrawTexture(Rect(110+menuAnim-Screen.width*2,20,30,45), namber[point%10]);
//GUI.Label(Rect(20+menuAnim-Screen.width*2,Screen.height-40,200,20), ""+health);
GUI.Box(Rect(20+menuAnim-Screen.width*2,Screen.height-60,40+200,40),"",health2Style);
GUI.Box(Rect(25+menuAnim-Screen.width*2,Screen.height-55,30+health,30),"",health1Style);
}

function Update () {
menuAnim += (menuAnim1-menuAnim)/4;
menu1Anim10 += (menu1Anim11-menu1Anim10)/4;
menu1Anim20 += (menu1Anim21-menu1Anim20)/4;
menu1Anim30 += (menu1Anim31-menu1Anim30)/4;
if (menu1Int == 0) { menu1Anim11 = 0; menu1Anim21 = Screen.height*2; menu1Anim31 = Screen.height*2; }
if (menu1Int == 1) { menu1Anim11 = Screen.height*2; menu1Anim21 = 0; menu1Anim31 = Screen.height*2; }
if (menu1Int == 2) { menu1Anim11 = Screen.height*2; menu1Anim21 = Screen.height*2; menu1Anim31 = 0; }
menu1sound11 = menu1sound10; menu1sound10 = menu1Int;
if (menu1sound11 != menu1sound10) { audio.PlayOneShot(sound2, soundFloat); }
menu1sound21 = menu1sound20; menu1sound20 = tumbler;
if (menu1sound21 != menu1sound20) { audio.PlayOneShot(sound2, soundFloat); }
if (menuAnim1 == -Screen.width) {
if (Input.GetKeyDown(KeyCode.LeftArrow)&&menu1Int>0) { menu1Int--; }
if (Input.GetKeyDown(KeyCode.RightArrow)&&menu1Int<2) { menu1Int++; }
if (Input.GetKeyDown(KeyCode.Escape)) { menuAnim1 = 0; }
}
if (menuAnim1 == Screen.width) {  
if (Input.GetKeyDown(KeyCode.Escape)) { menuAnim1 = 0; }
}
if (menuAnim1 == 0) {
if (Input.GetKeyDown(KeyCode.UpArrow)&&menuInt>0) { menuInt--; }
if (Input.GetKeyDown(KeyCode.DownArrow)&&menuInt<3) { menuInt++; }
if (Input.GetKeyDown(KeyCode.Return)) {
if (menuInt == 0) { audio.PlayOneShot(sound1, soundFloat); Application.LoadLevel(1); }
if (menuInt == 1) { menuAnim1 = -Screen.width; audio.PlayOneShot(sound1, soundFloat); }
if (menuInt == 2) { menuAnim1 = Screen.width; audio.PlayOneShot(sound1, soundFloat); }
if (menuInt == 3) { Application.Quit(); audio.PlayOneShot(sound1, soundFloat); }
}
if (Input.GetKeyDown(KeyCode.Z)) { menuAnim1 = Screen.width*2; }
}
if (menuAnim1 == Screen.width*2) {
if (Input.GetKeyDown(KeyCode.Escape)) { menuAnim1 = 0; }
if (Input.GetKeyDown(KeyCode.Q)) { point++; }
if (Input.GetKeyDown(KeyCode.W)) { point += 10; }
if (Input.GetKeyDown(KeyCode.E)) { point += 100; }
if (Input.GetKeyDown(KeyCode.A)) { health -= 50; }
if (Input.GetKeyDown(KeyCode.S)) { health = 200; }
if (health < 200) { health++; }
if (health < 0) { health = 0; }
}
}
MisterMaiklll
UNец
 
Сообщения: 6
Зарегистрирован: 05 мар 2014, 02:40

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение SERG__ZV 21 янв 2015, 19:19

А то что окно растянулось Это что нормально? А что если в игре у меня должны будут быть квадратные ячейки? После такой модификации они будут прямоугольными...
Моя первая игра. Cсылка на видео и архив с игрой _ttp://www.youtube.com/watch?v=e8lNG-ID70E
Аватара пользователя
SERG__ZV
UNIверсал
 
Сообщения: 452
Зарегистрирован: 04 ноя 2011, 14:37

Re: Универсальный контроллер GUI интерфейса. (Js)

Сообщение Левш@ 23 апр 2015, 15:12

А что если в игре у меня должны будут быть квадратные ячейки? После такой модификации они будут прямоугольными...

Я не понимаю... читать что ли не умеете ?
Там же описано про тег QwadGui. :-?

т есть теперь не на 800 и 600 а на любом, по мне оч удобно

Бред... ;)
Вы не верно поняли логику, настраивать можно в любом разрешении, только его надо указать.
800 х 600 это мои конкретные настройки на тот момент, я их и скопипастил, они вообще никакого отношения к делу не имеют.
_X.cor.R (Prologue)
Аватара пользователя
Левш@
Адепт
 
Сообщения: 4073
Зарегистрирован: 14 окт 2009, 16:34
Откуда: IBERIA
Skype: bars_levsha
  • Сайт

Пред.

Вернуться в Исходники (Копилка)

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1