7월, 2019의 게시물 표시

Unity - 메타 파일

출처 :  https://stackoverflow.com/questions/42462989/what-is-a-meta-file-and-why-does-unity-create-them-for-all-of-my-assets Well, meta fields are used to describe or specify a file, in version control too, but in unity meta files store the import settings of the files you have in your project. Your script or folder have a meta file which tells Unity how to prepare the asset in the project. If you delete a meta file Unity reimports the asset and creates the default meta file for that file type  일반적으로 메타 파일이라고 하면, 특정 파일에 대한 정보를 저장하는 곳이다. 유니티의 또 한가지 역할을 더 한다.  Assets 폴더 안에 게임에 필요한 자료가 들어오면, 유니티는 그 자료를 게임에 바로 적용할 수 있는 내부 형식으로 변환하여 Library 폴더 안에 저장한다. 이때 Assets 폴더의 자료가 변환되어 Library 폴더의 어느 위치에 있는지 알려줘야 겠지?? 유니티의 meta 파일에서는 그 역할을 추가로 하고 있다.

Unity - 메모리 관리 주의사항

이미지
출처 :  https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity4-1.html C# 환경에서는 프로그래머가 의도하지 않은 메모리 할당이 존재할 수 있다. 대표적인 예를 들면  - boxing           :  값 타입의 변수를 오브젝트 타입으로 변환하는 과정에서 발생. 오브젝트 타입으로 변형되면 자료형에 구애받지 않고 편하게 사용할 수 있는 장점이 있지만, 이 과정에서 불필요한 메모리가 할당된다.           : C# 환경에서는 박싱이 일어날 수 있는 경우에 대해서 따로 경고 메세지를 띄우지 않는데 가비지 컬렉터가 어느정도의 메모리 오버헤드는 잘 관리할 것이라 가정하기 때문. 하지만 유니티 환경에서는 경우에 따라 문제가 커질 수 있으므로 박싱을 피하는게 좋다.  - dictionary의 키 값으로 enum을 활용했을 때           : enum 값을 비교하기 위해 Compare 메소드를 사용-> 이 과정에서 박싱 유발  - foreach 문 사용           : 마찬가지로 박싱 유발  - 배열 형식으로 되어있는 Unity API에 접근할 때           : for(int i = 0; i < mesh.vertices.Length; i++) { float x, y, z; x = mesh.vertices[i].x; y = mesh.vertices[i].y; z = mesh.vertices[i].z; // ... DoSomething(x, y, z); }  위 경우에는...

Unity - 라이브러리 폴더

출처 :  https://docs.unity3d.com/Manual/BehindtheScenes.html svn 같은 버전 관리 프로그램에는 유니티 라이브러리 폴더를 업로드하지 말라고들 한다. 유니티 사이트 설명에 의하면 3. The source asset is processed Unity reads and processes any files that you add to the Assets folder, converting the contents of the file to internal game-ready versions of the data. The actual asset files remain unmodified, and the processed and converted versions of the data are stored in the project’s  Library  folder. Using internal formats for assets allows Unity to have game-ready versions of your assets ready to use at runtime in the editor, while keeping your unmodified source files in the the assets folder so that you can quickly edit them and have the changes automatically picked up by the editor. For example, the Photoshop file format is convenient to work with and can be saved directly into your Assets folder, but hardware such as mobile devices and PC graphics cards can’t accept that format directly to render as textures. Al...

Unity - 비교 연산자

https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/ 읽어두면 좋은 내용. C++ 백엔드 시스템에서 C# 을 동시에 사용하는 유니티 특징상, GameObject 처럼 c# wrapper 객체가 c++ 객체를 참조하고 있는 경우가 존재한다.  따라서 1 if ( myGameObject == null ) { }  위 코드의 == 연산자는 생각보다 복잡한 의미를 가진다.  c#의 wrapper 객체는 c#의 생명주기를 따르며 gc가 관리하게 되지만, wrapper 객체가 참조하는 c++객체는 c++의 생명주기를 따른다. -> c++ 객체가 파괴되어도 gc가 미처 수거하지 못한 c# 객체는 null값을 참조하며 존재할 수 있다.  이 경우, == 연산자로 널값과 비교를 하면 true를 반환한다고 한다. c# 객체는 사실 진짜 null이 아닌데 말이다. == 연산자로 null 비교를 하면 요런 특징이 있는데 - 비직관적 - UnityEngine.Objects 를 서로 비교하거나 null과 비교하는 것은 생각보다 비용이 비쌈 - thread safe 보장하지 않음 - ?? 연산자와는 모순된게 작동한다. 다만 ?? 쪽은 순수하게 C# null 값을 체크  결론적으로는  if(myObject.destroyed) {} // myObject가 파괴된 object를 가리키는지 확인 와 같은 == 연산자를 대체할 방법도 있으니 충분히 고려해 볼것.

Unity - 씬 로드와 정적 변수

출처 :  https://answers.unity.com/questions/1169580/static-variable-reset-at-loadlevel.html 정적 변수들은 기본적으로 UnityEngine.Object 으로부터 상속받는다. UnityEngine.Object는 씬에 포함되어 있으니 managed unity type 이라고 볼 수 있겠다. 이러한 특성상의 이유로 정적 변수들은 씬이 파괴될때 리셋된다. (새로운 씬이 로드될 때 현재 씬이 파괴되므로 보통 이 시기에 같이 소멸된다.) Yes, static variables are outside of the scene, but not GameObjects and Components, they belong to the scene and are destroyed when you load a new scene. So your static variable still exists but the object it references doesn't. 정확히 정적 변수들은 프로그램이 실행되는 내내 존재하므로, 정적 변수자체는 씬의 외부에 존재한다고 볼 수 있다. 하지만 정적 변수들을 포함하는 오브젝트나 컴포넌트는 씬에게 참조된 상태이기 때문에 씬 전환시에 내부 오브젝트들은 전부 파괴되지만 정적 변수들은 남아있게 된다.  - DontDestoryOnLoad 로 선언된 게임오브젝트나 컴포넌트들은 조금 다른데 씬이 전환되더라도 소멸되지 않고 남아있는다. * 이 부분은 유니티의 백엔드를 담당하는 c++과 연관이 있는 것 같은데 자세히는 모르겠다.