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

카테고리

분류 전체보기 (2738)
Unity3D (817)
Programming (475)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
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
05-06 00:00

I was working on a library in Unity that was using a lot of 3D text and therefore was requiring a lot of draw calls. This got me thinking, since all the pieces of text were on the same orientation plane would there be a way instead to draw all the text to a one texture and render that instead. Another benefit of doing this would be you could then apply text at runtime to a non-flat mesh via a texture. This would allow you to do cool things like personalizing a player’s jersey with the user’s name, localizing complex in-game advertisements, etc. So I decided to look into this. What started as a few experiments turned into not so small project.

Doing research I found a way of achieving this using Render Texture. What you could do was by using either with GUI text or 3D Text place a camera to capture a single frame and render it to a texture. While not completely straightforward or easy it does work and allows quite a bit of flexibility on what you are creating. This method does come with a drawback, it needs Render Texture support. Only Unity Pro supports Render Texture, plus they are not supported on the iPhone (Unity Feature Breakdown).

Since my goal was to create a library that all Unity developers could use, this was not an acceptable solution.

My next idea was to manually draw the text to a texture using SetPixels. While the performance of writing to a texture using SetPixels is less than ideal, I only needed to do this once.
Note: The reason why this is so slow is after calling setPixel(s) you have to call Apply which send the whole texture to the GPU. The Apply method is unfortunately very slow, but is “usable” if you are not needing to call it repeatedly.

I thought developing this using this method shouldn’t be too bad as I knew when you import a font into Unity, Unity automatically creates a texture containing the font. What I didn’t anticipate was that the letters were not in a grid format, but places tightly together. With no runtime access to letter position data, this was not going to work.

Next on my list was Custom Font, a feature where you can “easily” create your own font in Unity. With Custom Font you supply your own font image laid out in a grid. Using this method I could determine where the letters were positioned. I now needed a way create a font image in a grid pattern and get all the Per Character Kerning values from a font.

In digging through the internet I came across a few mentions of something called the Unity Font Mapper. It took me a very long time but I finally tracked down a link to the app: http://loewald.com/unity/unityfontmapper.zip. This Mac application not only generates the font image in a grid pattern, but generates a file containing the Per Character Kerning information.

Once I had a Custom Font working I then discovered there is no programming access to any of its properties (I still use Custom Font as part of my final solution in hopes at some point access will be opened up to those values). This means these values now needed to be entered twice if you want to use the same font for both a Text-to-Texture font and as a regular font.

I now had all the pieces and it was just a matter of putting it all together. While the current version of this code is far from perfect and is missing features like colored text it does exactly what I wanted it to do.

To check out the demo click here.

To get the source (unitypackage) click here.

To get only the TextToTexture class (TextToTexture.cs) click here.

Source Requirements: Unity 2.6

Setup Steps

  1. Create a font image in a grid pattern and collect kerning values (either manually or using the Unity Font Mapper)
  2. Import the font image(texture) into Unity and select ‘Build Alpha From Grayscale’ and set ‘Is Readable’ to true.
  3. Add this texture to a material
  4. Within Unity create a Custom Font. If you aren’t wanting to use this font for anything but Text-to-Texture you can just setup the basics and ignore the Per Character Kerning values within the Custom Font (these take a long time to enter)
  5. Create a script that calls TextToTexture and passes all the required information (example in source: AddTextToTexture.cs)

Note: I used a Decal material in this demo so the text would appear on top of the primary texture. But you can use any material that you wish.



출처 : http://blog.almostlogical.com/2010/08/20/adding-text-to-texture-at-runtime-in-unity3d-without-using-render-texture/

반응형
Posted by blueasa
, |

Unity3d Hotkeys

Unity3D/Tips / 2013. 11. 4. 10:43

- Default HotKey와 Custom Hotkey 추가 방법.





Review_Notes_Unity3d_Hotkeys.pdf


출처 : http://www.walkerboystudio.com/Review_Notes_Unity3d_Hotkeys.pdf




[Add]


- Toggle Active GameObject in Hierarchy : Alt + Shift + A


출처 : http://www.youtube.com/watch?v=uNSZsMnhS1o




[Add]

- Expand/Collapse All in Hierarchy : Alt + L-Button



반응형
Posted by blueasa
, |


링크 : http://www.slideshare.net/MrDustinLee/ss-27739454

반응형
Posted by blueasa
, |
게임을 만들면 UICamera와 MainCamera 두 개를 보통 쓰는 데,

UI를 클릭하고 싶어서 클릭했더니 MainCamera쪽도 체크돼서 두 곳 다 실행되는 경우가 생기는데..

우연한 기회에 답을 주신 분이 있어서 적어놓는다.


NGUI 기준..

UICamera 클래스를 보면 

static public GameObject hoveredObject;

가 있다.

hover(UI 오브젝트 위에 있는 상태) 된 오브젝트가 들어가 있는 곳인가보다..


hoveredObject가 null이면 UI위에 있는 상태가 아니니, 다시 말해 터치된 곳에 UI가 없는 상태니 MainCamera쪽을 실행하면 되겠다.


if(null == UICamera.hoveredObject)

{

    // 게임쪽 클릭 처리

}




출처 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=37658&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%EC%B9%B4%EB%A9%94%EB%9D%BC&sop=and&currentId=44

반응형
Posted by blueasa
, |

제목엔 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
, |


[Active/InActive HotKey for NGUI]

Alt + Shift + A



[출처] http://www.youtube.com/watch?v=uNSZsMnhS1o



[추가1]

https://answers.unity.com/questions/566114/is-there-a-keyboard-shortcut-for-setting-an-object.html



[추가2]

Unity2018에서 해당 키가 안먹힘

원래 NGUI 부가기능인데 유니티가 좋아보였는지 내장시켰다고 함.

그래서 양쪽에서 같은 Hotkey를 셋팅했기 때문에 충돌나서 키가 안먹힌다고 함.

유니티에 내장됐기 때문에 NGUI의 Hotkey 소스를 주석처리 하자.


NGUISelectionTools.cs

에 보면 

[MenuItem("GameObject/Selection/Toggle 'Active' #&a")]

부분이 있는데

해당 MenuItem 부분만 주석처리하면 됨.


[출처] 게임코디 선후님

반응형
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
, |

IronPython

Unity3D/Plugins / 2013. 10. 6. 21:02

Link : http://ironpython.net/

반응형

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

Mobile Movie Texture  (0) 2013.12.03
원격 로그 플러그인  (0) 2013.11.20
UniPython  (0) 2013.10.06
iOS 플러그인 제작  (0) 2013.09.15
Prefactory: Free PoolManager / PoolObject System  (0) 2013.08.28
Posted by blueasa
, |

UniPython

Unity3D/Plugins / 2013. 10. 6. 20:25


Link : http://forum.unity3d.com/threads/190418-UniPython-Python-Scripting-in-Unity3D-based-games

반응형

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

Mobile Movie Texture  (0) 2013.12.03
원격 로그 플러그인  (0) 2013.11.20
IronPython  (0) 2013.10.06
iOS 플러그인 제작  (0) 2013.09.15
Prefactory: Free PoolManager / PoolObject System  (0) 2013.08.28
Posted by blueasa
, |


링크 : http://unitystudy.net/bbs/board.php?bo_table=dustin&wr_id=402&page=0&sca=&sfl=&stx=&spt=0&page=0&cwin=#c_406

반응형

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

Mobile Movie Texture  (0) 2013.12.03
원격 로그 플러그인  (0) 2013.11.20
IronPython  (0) 2013.10.06
UniPython  (0) 2013.10.06
Prefactory: Free PoolManager / PoolObject System  (0) 2013.08.28
Posted by blueasa
, |