블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Script (91)
Extensions (14)
Effect (3)
NGUI (77)
UGUI (8)
Physics (2)
Shader (36)
Math (1)
Design Pattern (2)
Xml (1)
Tips (200)
Link (22)
World (1)
AssetBundle (25)
Mecanim (2)
Plugins (68)
Trouble Shooting (68)
Encrypt (7)
LightMap (4)
Shadow (4)
Editor (8)
Crash Report (3)
Utility (9)
UnityVS (2)
Facebook SDK (2)
iTween (3)
Font (10)
Ad (14)
Photon (2)
IAP (1)
Google (8)
Android (45)
iOS (41)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-28 00:02

제목엔 2.7로 적었지만, 이번에 NGUI 2.6.4에서 3.0으로 업그레이드 하면서 수정해줘야 될 사항들 간단 정리..

아는데까지만 정리하는 거라 빠지는것도 있음.

새로 알게 되면 추가해야 될 듯..



[UICheckBox]

- UICheckBox -> UIToggle

- UICheckBox.isChecked -> UICheckBox.value

- Checkbox State == UIToggle.current.value

- 더이상 root(GameObject)를 설정안함 -> Group ID(Index)를 직접 셋팅하는 방식으로 변경. 


[UIButtonSound]

- UIButtonSound -> UIPlaySound


[UISprite]

- UISprite 통합(Filled/Sliced/Tiled 등은 내부 메뉴로 바꼈다)

   = UIFilledSprite -> UISprite

   = UISlicededSprite -> UISprite

   = UITiledSprite -> UISprite

- UISprite의 Scale 값이 텍스쳐 크기였던 것이 기본 Scale 1로 바뀌고, Dimensions가 생겨서 여기서 크기를 지정한다. 


[UILabel]

- UILabel의 Scale 값이 폰트 크기였던 것이 기본 Scale 1로 바뀌고, Dimensions가 생겨서 여기서 크기를 보여주지만, 폰트는 Dimensions 조절이 불가능..

- 넓이(width) 제한은 Dimensions의 width 값으로 조절.
- 라인제한은 UILabel-Max Lines 로 조절(0은 무제한,자동조절)
- Label 크기 조절은 Overflow : ShrinkContent 로 바꾼 후, Dimensions를 조절(Scene View에서 Label의 외곽 파란 동그라미를 잡아서 조절해도 됨)
- Label 크기 조절은 Overflow 종류에 따른 사용법을 좀 더 알아봐야 할 듯..
- 우선 Label 크기 조절은 Overflow : Resize Freely 로 선택한 후, Transform-Scale 조절로..

[UIPanel]

- UIPanel에 depth가 생겼다. Panel의 depth끼리 대분류가 되고, Widget의 depth가 소분류로 나뉜다.

  결과적으로 패널 단위로 분리가 되고, 한 패널 안에서만 위젯들의 depth를 관리해주면 되게 되어서 depth 관리가 편해졌다.(Good)

- Panel끼리는 동등한 위치이기 때문에, Tree Node 상 하위에 있는 Panel이라도 모두 맞게 셋팅해 줘야 된다.

- depth 관리가 되기 때문에 이제 Label을 보이기 위해 넣었던 Panel은 빼도 된다(-z값도 빼도 될듯하다. Collider사용을 위해서 넣었다면 유지..)


[Atlas]

- Atlas를 NGUI에서 통합관리 하게 바꼈다. 결과적으로 아틀라스가 다름으로 인해서 생기는 depth 관리문제가 사라졌다.(Font Atlas 포함)(Good)


[Common]

- checkbox.onStateChange += OnCheckboxState -> EventDelegate.Add(checkbox.onStateChange, OnCheckboxState);

- 여러 번 실행되는 곳에서도 한 번만 등록하려면..

  = checkbox.onStateChange += OnCheckboxState -> EventDelegate.Add(checkbox.onStateChange, OnCheckboxState, true);

- checkbox.onStateChange = OnCheckboxState -> EventDelegate.Set(checkbox.onStateChange, OnCheckboxState);

- checkbox.onStateChange -= OnCheckboxState -> EventDelegate.Remove(checkbox.onStateChange, OnCheckboxState);

- 'Make Pixel Perfect' 버튼 -> Widget Component의 'Correct' 버튼으로 대체.

- widget의 크기를 transform.scale로 표현하던 것을 widget.width/widget.height로 대체.

- Prefab도 새로 체크해줘야 함.

- Widget들이 바뀌면서 Atlas도 새로 저장해줘야 된다. Widget 정리하면서 저장할 때 Atlas 저장할지 물으면 저장하고 업데이트 시키자.


[참조]

http://www.tasharen.com/forum/index.php?topic=11.msg27296#msg27296


3.0.0 has been released. Upgrade-centric video:
http://www.youtube.com/watch?v=uNSZsMnhS1o&list=UUQGZdUwzE8gmvgjomZSNFJg

Beginner / overview video:
http://www.youtube.com/watch?v=OT0hTxjjkY4&list=UUQGZdUwzE8gmvgjomZSNFJg

Scroll view example (because it was requested):
http://www.youtube.com/watch?v=OiA4o8KqBFI&list=UUQGZdUwzE8gmvgjomZSNFJg

반응형
Posted by blueasa
, |
Unity3D와 NGUI로 게임을 개발하면서 가끔 게임 로직상으로 NGUI를 활성/비활성 등을 해야 될 때..

제대로 셋팅이 적용되지 않는 경우를 가끔 보게 된다.
(분명 비활성화 시켰는데 활성상태 그대로라던지..사라져야 할 UI 이미지가 그대로 남아있다던지..)

어디서 봤는지 기억은 가물가물하지만..

NGUI Update가 Unity에 비해 한 프레임(one frame)이 늦다고 한다.

그래서 뭔가를 셋팅(Set) 할 때, 한 프레임을 늦게 적용해줘야 제대로 적용된다.

아래는 그 방식의 간단한 한 예이다.


[Ex]

GameObject m_goSPrite;    // 스프라이트의 게임오브젝트

void Start()
{
StartCoRoutine(InActivateUI());    // 스프라이트 게임오브젝트 비활성화 코루틴으로 실행
}

IEnumerator InActivateUI()
{
     yield return null;        // 한 프레임 넘기기 위해..

    m_goSPrite.SetActive(false);
}


반응형
Posted by blueasa
, |


링크 : http://myevan.cpascal.net/articles/2013/unity_ngui_pixel_perfect.html

반응형
Posted by blueasa
, |

[참조 글 및 참조파일]

Link :http://forum.unity3d.com/threads/165254-Unity-4-dynamic-font-support-for-NGUI 

File : 

NGUI_277c_DynamicFonts_and_Readme.zip


※ 파일명과 readme에는 NGUI 2.7.7이라고 돼 있지만 정황상 NGUI 2.2.7을 오표기 한 것 같다.


[NGUI 2.3.4 대응되는 수정 파일]

File : 

NGUI 2.3.4_DynamicFont_Source.zip



[사용기]

※ 현재 사용하려니 NGUI 2.3.4 버전이다. 위의 파일과 UIFont.cs가 좀 달라서 직접 수정해야 했다.


1) NGUI 2.3.4 버전에 맞춘다.


2) 위의 파일(NGUI 2.3.4_DynamicFont_Source.zip)을 받아서 풀어보면, UIFont.cs, UIFontInspector.cs 두 파일이 있다.

    각각 해당위치에 덮어씌우자.

   (주의: 덮어씌우면 기존 폰트 프리팹의 UIFont 스크립트가 missing이 될 수 있다. 바뀐 UIFont를 다시 넣어주면 정상 작동한다.)


3) 원하는 TTF 폰트 파일을 프로젝트에 올린다.(테스트용으로 Windows\Fonts\에 있는 '맑은고딕'을 사용했음.)

    올리면 아래와같이 자동으로 다이나믹 폰트로 생성되면서 Material과 텍스쳐가 생성된다.

    인스펙터 창에서는 폰트 사이즈 등을 조절할 수 있다.



3) Empty GameObject를 하나 생성한다.



4) 이름을 원하는대로 바꾼다.(임의로 MyDynamicFont로 바꿈)



5) UIFont 스크립트를 추가한다.



6) Font Type을 Dynamic으로 바꾸고,

    6-1) Font : 원하는 폰트(임의로 MALGUN 넣음)를 넣는다.

    6-2) Material : MALGUN 아래 있는 Material(스샷에서는 Font Material)을 드래그해서 넣는다.

          ※ 위 참조 데이터의 readme에서는 Material을 새로 만드는 데, 폰트 아래 있는걸 사용해도 별 차이가 없어서 그냥 쓰는걸로 설명함.. 왜 새로 만드는 지 모르겠음. 차후 문제가 생긴다면 수정해야 될 듯.

    6-3) Size : 3)에서 본 Size(스샷에서는 16)를 넣어준다.(이 부분은 좀 더 확인을 해 봐야겠다)

          ※ 여기서의 사이즈는 폰트 사이즈와 매칭이 돼야 Height가 제대로 맞는 것 같다. 폰트 사이즈를 키우려면 3)의 사이즈부터 수정 후 다시 매칭 시키자.



7) 만든 MyDynamicFont를 Prefab으로 만들자.(폰트 만들기는 완료)



8) 'NGUI-Create a Widget'을 눌러서 Widget Tool을 열고, Font 란에 7)에서 만든 MyDynamicFont Prefab을 넣는다.



9) Label을 하나 만든다.(Add To)

    제대로 MyDynamicFont를 써서 'New Label'이 뜬 걸 볼 수 있다.



10) 테스트로 한글/영어/한자/숫자/특수문자 등을 맘대로 넣어봤다. 잘된다.



11) 추가로.. 이제껏 쓴 글이 텍스쳐에 찍혀있는 걸 볼 수 있다.

     글자수가 늘어나서 텍스쳐를 다 채울정도가 되면 텍스쳐 사이즈가 자동으로 늘어난다.




P.s. Dynamic Font가 BM Font보다 Draw Call이 높다고 들었는데..

       잠시 테스트 해봐서는 폰트 하나당 Draw Call이 1이다(BMF랑 같음).

       어떤 경우에 늘어나는 지 모르겠다.(아시는 분 가르쳐 주세요..=_=;)

반응형
Posted by blueasa
, |

링크 : http://hompy.info/664



CoverFlowScroll.unitypackage



요즘 제작중인 RPG 게임 GUI 에서 영웅 생성을 위해 캐릭터를 선택하는 UI 를 커버플로우(Cover Flow)로 구성하게 되어 NGUI 를 조금 응용해서 심플하게 구성해봤습니다. 아래 동영상과 유니티 데모를 보시면 대략 어떤 것인지 아실 수 있을 것이며 혹시나 구현 방법에 대해 관심 있는 분들은 첨부 파일을 받아서 패키지 임포트로 유니티에서 가져가 내용을 살펴 보시면 되겠습니다. NGUI 외에도 트위닝 모션을 위해 HOTween 플러그인을 사용하는 코드가 있으나 수정해서 쓰셔도 되겠습니다. 그리고 데모에 보이는 캐릭터 디자인 소스는 에셋 스토어에서 구입한 것이네요. NGUI 플러그인에 이런 기능도 포함되면 좋을 것 같은데 안된다면 아쉽지만 저처럼 이렇게 구현해야 되겠지요.^^ 여러분은 지금 어떤 기능들을 추가해보고 있나요?

[유니티 데모 링크] http://www.hompydesign.com/tmp/coverflow/

[패키지 첨부파일]  CoverFlowScroll.unitypackage

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Plugins;

public class HeroTable : MonoBehaviour {
   UISprite[] heros;

   Transform mTrans;
   bool mIsDragging = false;
   Vector3 mPosition, mLocalPosition;
   Vector3 mDragStartPosition;
   Vector3 mDragPosition;
   Vector3 mStartPosition;
   
   public float cellWidth = 160f;
   public float downScale = 0.4f;
   public int cellTotal = 6;
   public int seq = 3;
   
   public UILabel titleLabel;
   
   // Use this for initialization
   void Start () {
       StartCoroutine( DelayStart(1f) );
   }
   void Awake(){
       mTrans = transform;
       mPosition = mTrans.position;
       mLocalPosition = mTrans.localPosition;
   }
   
   IEnumerator DelayStart(float delayTime) {
       yield return new WaitForSeconds(delayTime);
       heros = gameObject.GetComponentsInChildren<UISprite>();
       SetPosition(false);
   }
   
   void SetSequence(bool isRight){
       Vector3 dist = mLocalPosition - mTrans.localPosition;
       float distX = Mathf.Round(dist.x/cellWidth);
       seq = (int)distX;
       if (seq >= cellTotal) seq = cellTotal - 1;
       if (seq <= 0) seq = 0;
   }
   
   void SetPosition(bool isMotion){
       Vector3 pos = mLocalPosition;
       pos -= new Vector3(seq * cellWidth, 0f0f);
       if (isMotion) {
           TweenParms parms = new TweenParms();
           parms.Prop("localPosition", pos);
           parms.Ease(EaseType.Linear);
           HOTween.To(mTrans, 0.1f, parms);
           HOTween.Play();
       else {
           mTrans.localPosition = pos;
       }
       titleLabel.text = heros[seq].spriteName;
   }

   void Drop () {
       Vector3 dist = mDragPosition - mDragStartPosition;
       if (dist.x>0f) SetSequence(true);
       else SetSequence(false);
       SetPosition(true);
   }

   void OnDrag (Vector2 delta) {
       Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
       float dist = 0f;
       Vector3 currentPos = ray.GetPoint(dist);

       if (UICamera.currentTouchID == -|| UICamera.currentTouchID == 0) {
           if (!mIsDragging) {
               mIsDragging = true;
               mDragPosition = currentPos;
           else {
               Vector3 pos = mStartPosition - (mDragStartPosition - currentPos);
               Vector3 cpos = new Vector3(pos.x, mTrans.position.y, mTrans.position.z);
               mTrans.position = cpos;
           }
       }
   }

   void OnPress (bool isPressed) {
       mIsDragging = false;
       Collider col = collider;
       if (col != null) {
           Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
           float dist = 0f;
           mDragStartPosition = ray.GetPoint(dist);
           mStartPosition = mTrans.position;
           col.enabled = !isPressed;
       }
       if (!isPressed) Drop();
   }
}

using UnityEngine;
using System.Collections;

public class HeroItem : MonoBehaviour {
   Transform mTrans, mParent;
   Vector3 scale;
   float cellWidth;
   float downScale;
   HeroTable hTable;

   void Start () {
       mTrans = transform;
       scale = mTrans.localScale;
       mParent = mTrans.parent;
       hTable = mParent.GetComponent<HeroTable>();
       cellWidth = hTable.cellWidth;
       downScale = hTable.downScale;
   }
   
   void Update () {
       Vector3 pos = mTrans.localPosition + mParent.localPosition;
       float dist = Mathf.Clamp(Mathf.Abs(pos.x), 0f, cellWidth);
       mTrans.localScale = ((cellWidth - dist*downScale) / cellWidth) * scale;
   }
}

반응형
Posted by blueasa
, |



참조 : http://www.tasharen.com/?page_id=197


동영상 링크 : http://www.youtube.com/watch?v=XAeRXckXMMw


반응형
Posted by blueasa
, |

1) NGUI의 Panel에 UIStretch 추가

    (조절이 필요한 곳에 모두 넣는다. 패널이 여러개면 여러 패널에 모두 순서대로 진행)


2) Ui Camera에 NGUI 카메라 추가(Drag & Drop)


3) Style : Both(카메라에 맞춰서 스케일이 조절돼버림. 스케일 수정 안됨)


4) 스케일이 직접 조절이 안되므로 Relative Size를 조절함


5) Relative Size 조절(결과적으로 패널의 스케일 값이 1이 나오게 Relative Size 값을 넣는다.)

   X = 패널의 1 / Scale.X

   Y = 패널의 1 / Scale.Y


[문제점]

- 해상도에 맞게 늘어나긴 하지만 UI 크기가 늘어나거나 줄어드는 문제가 있음.


[참조 글]

뀨니 2012.12.28 09:23:58 댓글달기
저도 같은문제로 게시판 뒤지다가 어떤분것 보고 도움을 받았는데요 NGUI쓰신다면 NGUI에 있는 스크립트를 사용하시면 됩니다.UIStretch스크립트를사용해서 해상도에따라 셋팅값에 따라 해상도에 맞춰 비율적으로 강제적으로 늘릴 수 있습니다. 예를 들자면UIStretch를 패널에 추가하시고, UI Camera에 NGUI카메라를 넣으시고, Style을 Both로 맞추시면 카메라에 맞춰 늘어나게 되는데요, 여기서 크기를 Relative Size로 셋팅해주시면 됩니다. 
저같은 경우는 엄청나게 커져버려서 X = 0.00085 Y = 0.00125 뭐이런식으로 맞췄 습니다.


참조글 링크 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=23789&page=0&sca=UNITY&sfl=wr_subject%7C%7Cwr_content&stx=UIStretch&spt=0&page=0&currentId=44#c_23991

반응형
Posted by blueasa
, |

NGUI의 이벤트 함수를 SendMessage로 호출하려고 함수 원형을 찾아보고 올려놓음.


UICamera sends out the following events to colliders:
  • OnHover (isOver) is sent when the mouse hovers over a collider or moves away.
  • OnPress (isDown) is sent when a mouse button gets pressed on the collider.
  • OnSelect (selected) is sent when a mouse button is first pressed on a game object. Repeated presses on the same object won't result in a new OnSelect.
  • OnClick () is sent with the same conditions as OnSelect, with the added check to see if the mouse has not moved much. UICamera.currentTouchID tells you which button was clicked.
  • OnDoubleClick () is sent when the click happens twice within a fourth of a second. UICamera.currentTouchID tells you which button was clicked.
  • OnDragStart () is sent to a game object under the touch just before the OnDrag() notifications begin.
  • OnDrag (delta) is sent to an object that's being dragged.
  • OnDragOver (draggedObject) is sent to a game object when another object is dragged over its area.
  • OnDragOut (draggedObject) is sent to a game object when another object is dragged out of its area.
  • OnDragEnd () is sent to a dragged object when the drag event finishes.
  • OnInput (text) is sent when typing (after selecting a collider by clicking on it).
  • OnTooltip (show) is sent when the mouse hovers over a collider for some time without moving.
  • OnScroll (float delta) is sent out when the mouse scroll wheel is moved.
  • OnKey (KeyCode key) is sent when keyboard or controller input is used.

To tap into them in your own custom scripts, simply create a script with the appropriate function, such as:
  1. void OnPress (bool isPressed)
  2. {
  3.     if (isPressed) Debug.Log("I was pressed on!");
  4.     else Debug.Log("I was unpressed");
  5. }

Pro-Tip #2

You can subscribe to events from any script using delegates: UICamera.onClick, UICamera.onHover, etc. These delegates will be called just before the actual notification gets sent to the proper object. You can use this functionality to listen in for events on a script regardless of whether they would be going to that script's game object or not.

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_camera.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.



출처 : http://www.tasharen.com/forum/index.php?topic=6711.0

반응형
Posted by blueasa
, |

NGUI Virtual Joystick

Unity3D/NGUI / 2012. 12. 5. 15:23


nguijoystick.unitypackage



NGUI에서 제공하는(맞나? 홈페이지에서 찾아도 못찾겠는데..) 조이스틱이 있어서 구해서 올려놓음..


버전이 달라져서 그런지 좀 바꿔야 될 부분이 있다..


1. 우선 Import 하고나면 UIJoystick.cs가 별도의 Plugin 폴더에 빠져 있다.

    이걸 NGUI-Scripts-UI 폴더로 옮겨주자.


2. UIJoystick.cs 스크립트에도 에러가 4개 난다.

    파일을 열어서 아래 두가지를 수정해주자.

    1) Tweener -> UITweener

    2) UICamera.lastCamera -> UICamera.currentCamera


3. 예제의 조이스틱 컨트롤은 Layer가 Default가 아니라서 Culling Mask 때문에 조이스틱이 제대로 작동 안할 수 도 있다.

    다른 Layer로 바꾸던지 Default로 바꾸자.(이것때문에 조작 안된다고 삽질을..)


위 까지만 수정하면 우선 돌아간다.


참조 : http://www.tasharen.com/forum/index.php?topic=55.0

반응형
Posted by blueasa
, |

스크롤/드래그 이벤트를 받는 방법

  • NGUI에서는 BoxCollider를 붙인 오브젝트만  UICamera의 마우스 이벤트를 받는다
    • BoxCollider 뿐만 아니라  Collider면 다 될 것 같긴 하지만 확인해보진 않았다
  • 따라서 BoxCollider와 UIDragPanelContents를 붙인 오브젝트에 UIForwardEvents 스크립트를 붙인다
  • UIForwardEvents의 OnDrag를 true로 설정하고, UIForwardEvents의 target을 UIDragPanelContents 오브젝트로 지정한다
  • UIDragPanelContents 오브젝트에 UIEventListener 스크립트를 붙이고 이벤트를 받거나, 직접 OnDrag() 를 구현한다
  • OnScroll은 위 과정을 참고하여 알아서 구현한다




반응형

'Unity3D > NGUI' 카테고리의 다른 글

NGUI: Events(Event Functions)  (2) 2012.12.07
NGUI Virtual Joystick  (1) 2012.12.05
유니티 NGUI 에서 라벨에 한글(폰트) 적용하기  (2) 2012.11.05
NGUI - Sticky Floating Text  (0) 2012.10.28
NGUI: HUD Text  (0) 2012.10.26
Posted by blueasa
, |