Unity GUI 공부하기
GUI 에 관련하여 동영상을 보면서 숙지 하였습니다.
본 자료는 용량이 좀 크네용;;; 어디서 얻은 자료인가 하면...
http://www.unity-tutorials.com/
이곳입니다.... 유료라서 모든 강좌를 습득하기는 어렵지만.. 간단한 개인정보를 입력하면,
무료강좌 2개를 제공해 주네요..
2년이 지난 시점에서 한번 더 보니까.. 그리 중요한 내용을 정리해 놓은 것이 아니라는 것을 알게 되었습니다.
1. 스크립트 기초
기본적으로 카메라 화면 이동을 스크립트로 구현하여, 키보드를 이용해 움직이는 예제 입니다.
var moveSpeed : float = 10;
function Update(){
if(Input.GetKey(KeyCode.UpArrow)){
transform.Translate(Vector3(0,moveSpeed * Time.deltaTime, 0));
}else {
if(Input.GetKey(KeyCode.DownArrow)){
transform.Translate(Vector3(0, -moveSpeed * Time.deltaTime, 0));
}
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Translate(Vector3(moveSpeed*Time.deltaTime,0,0));
}else{
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Translate(Vector3(-moveSpeed * Time.deltaTime, 0 ,0));
}
}
}
function Start()
{
while(true)
{
Debug.Log(transform.position.ToString());
yield;
}
}
2. GUI 관련
var mainMenu : boolean = false;
var options : boolean = false;
var backTexture : Texture;
var menuStyle : GUIStyle;
var silderTextStyle : GUIStyle;
var soundVolume : float = 0;
var musicVolume : float = 0;
var voiceVolume : float = 0;
function Start(){
soundVolume = PlayerPrefs.GetFloat("sound", 0);
musicVolume = PlayerPrefs.GetFloat("music", 0);
voiceVolume = PlayerPrefs.GetFloat("voice", 0);
}
function OnGUI()
{
if(mainMenu || options){
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), backTexture);
if(mainMenu){
GUI.Button(Rect(Screen.width *.4 , Screen.height * .05 , Screen.width * .2 , Screen.height * .1), "Main Menu" , menuStyle);
if(GUI.Button(Rect(Screen.width * .4 , Screen.height * .4 , Screen.width *.2 , Screen.height * .1),"Play Game")){
mainMenu = false;
// gameManager.Play();
}
if(GUI.Button(Rect(Screen.width * .4 , Screen.height * .5 , Screen.width *.2 , Screen.height * .1),"Options")){
mainMenu = false;
options = true;
}
}else if(options){
GUI.Button(Rect(Screen.width *.4 , Screen.height * .05 , Screen.width * .2 , Screen.height * .1), "Options" , menuStyle);
if(GUI.Button(Rect(Screen.width * .4 , Screen.height * .8 , Screen.width *.2 , Screen.height * .1),"Back")){
mainMenu = true;
options = false;
PlayerPrefs.SetFloat("sound", soundVolume);
PlayerPrefs.SetFloat("music", musicVolume);
PlayerPrefs.SetFloat("voice", voiceVolume);
}
GUI.Window(0,Rect(Screen.width * .3 , Screen.height * .3 , Screen.width * .4 , Screen.height * .4), OptionsWindow, "");
}
}
}
function OptionsWindow(WindowID : int)
{
soundVolume = GUI.HorizontalSlider(Rect(Screen.width * .05 , Screen.height * .05 , Screen.width * .3 , Screen.height * .05 ) , soundVolume, 0 ,1);
GUI.Label(Rect(Screen.width * .05 , Screen.height * .015 , Screen.width * .3 , Screen.height * .04 ) , "Sound Volume" ,silderTextStyle);
musicVolume = GUI.HorizontalSlider(Rect(Screen.width * .05 , Screen.height * .15 , Screen.width * .3 , Screen.height * .05 ) , musicVolume, 0 ,1);
GUI.Label(Rect(Screen.width * .05 , Screen.height * .115 , Screen.width * .3 , Screen.height * .04 ) , "Music Volume" ,silderTextStyle);
voiceVolume = GUI.HorizontalSlider(Rect(Screen.width * .05 , Screen.height * .25 , Screen.width * .3 , Screen.height * .05 ) , voiceVolume, 0 ,1);
GUI.Label(Rect(Screen.width * .05 , Screen.height * .215 , Screen.width * .3 , Screen.height * .04 ) , "Voice Volume" ,silderTextStyle);
}
수정을 해 놓고 있지만, 상용 GUI 제품들을 씁니다.
저같은 경우도 NGUI를 사용했습니다.
EZ GUI : http://www.anbsoft.com/middleware/ezgui/
QUAD UI : http://blog.equals-equals.com/quadui/
(Quad UI)베타 버전 다운로드시 해당 패키지는 영문폴더에 저장후에 Import 해야 한다고 하는데.. 이건 2년전 이야기고, 그냥..
NGUI 를 쓰세요.. 아직까진 대세인듯.