[펌] 유니티3D Conditional Attribute 사용

|

출처 : http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_Lecture&page=1&sn1=&divpage=1&sn=on&ss=on&sc=on&keyword=%C0%AF%B4%CF%C6%BC&select_arrange=last_comment&desc=desc&no=315



·미리보기 | 소스복사·
  1. using ConditionalAttribute = System.Diagnostics.ConditionalAttribute;  
·미리보기 | 소스복사·
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. using ConditionalAttribute = System.Diagnostics.ConditionalAttribute;  
  5.   
  6. public class NewBehaviourScript : MonoBehaviour {  
  7.   
  8.     // Use this for initialization  
  9.     void Start () {  
  10.       
  11.     }  
  12.       
  13.     // Update is called once per frame  
  14.     void Update () {  
  15.         call0 ();  
  16.         call1 ();  
  17.         call2 ();     
  18.     }  
  19.       
  20.     void call0()  
  21.     {  
  22.         Debug.Log("call0");  
  23.     }     
  24.       
  25.     [Conditional("CON1")]  
  26.     void call1()  
  27.     {  
  28.         Debug.Log("call1");  
  29.     }  
  30.       
  31.     [Conditional("CON2")]  
  32.     void call2()  
  33.     {  
  34.         Debug.Log("call2");  
  35.     }     
  36. }  


Trackback 0 And Comment 0

[펌] 유니티 엔진 - 텍스트 파일을 이용하여 에셋 번들 한꺼번에 생성 하기

|

출처 : http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_Lecture&page=1&sn1=&divpage=1&sn=on&ss=on&sc=on&keyword=%C0%AF%B4%CF%C6%BC&select_arrange=last_comment&desc=desc&no=309


에셋 번들을 만들어야 하는데 파일 하나하나 찍어서 만들기가 너무 귀찮았습니다.

플랫폼마다 똑같은 노가다를 반복 해야 한다고 생각하니 눈앞이 캄캄하더군요.
그래서 텍스트 파일에 리스트를 쭉 적어놓고 읽어와서 일괄 생성하게 만들었습니다.


아래와 같이 파일의 경로를 쭉 적어줍니다.
patch_list.txt 로 저장을 하고 위치는 Resources폴더 아래에 둡니다.


Resources/Sound/main.ogg
Resources/Sound/fire.wav
Resources/character/human.prefab
Resources/character/lion.prefab
Resources/ui/shop.prefab
.
.
.
[Resources/patch_list.txt의 내용]



소스코드는 Assets/Editor 밑에 xxx.cs 로 넣어놓습니다. 파일 이름은 아무거나 넣어도 됩니다.
·미리보기 | 소스복사·
  1. [MenuItem("Assets/Generate All from file(Windows)")]    // 메뉴가 들어갈 위치입니다. Assets메뉴 하위.
  2. static void GenerateAll()  
  3. {  
  4.     // 빌드 타겟은 적절하게 맞춰주면 되겠죠.  
  5.     ExportAll(BuildTarget.StandaloneWindows);  
  6. }  
  7.   
  8.   
  9.   
  10.   
  11.   
  12. static void ExportAll(BuildTarget target)    
  13. {    
  14.     // 리스트를 읽어와서 줄 단위로 분리 해 줍니다.  
  15.     TextAsset filelist_obj = Resources.Load("patch_list"typeof(TextAsset)) as TextAsset;    
  16.     string[] filelist = filelist_obj.text.Split('\n');    
  17.     
  18.   
  19.     foreach (string original_path in filelist)    
  20.     {  
  21.         // *중요함! 개행 문자를 제거 해 줍니다.  
  22.         string path = original_path.Trim('\n');    
  23.         path = path.Trim('\r');    
  24.     
  25.         if (path.Length <= 0)    
  26.         {    
  27.             continue;    
  28.         }    
  29.   
  30.         // 확장자, 경로 다 빼고 파일 이름만 쏙 빼옵니다.    
  31.         int last_split_pos = path.LastIndexOf('/') + 1;    
  32.         int extend_length = path.Length - path.LastIndexOf('.');    
  33.         string filename = path.Substring(last_split_pos, (path.Length - last_split_pos) - extend_length);    
  34.   
  35.         // 번들 파일이 생성될 경로 입니다.
  36.         // 프로젝트 상위 폴더에 "patch/(플랫폼명)" 형태의 폴더를 미리 만들어 놓아야 합니다.
  37.         // 예)
  38.         // d:/project/patch/Android    <- 번들 파일이 생성될 폴더
  39.         // d:/project/gamecodi  <- 프로젝트 폴더
  40.         // d:/project/gamecodi/Assets
  41.         string output_path = string.Format("../patch/{0}/{1}.unity3d", target.ToString(), filename);    
  42.   
  43.         // 리스트에 기입된 경로에서 오브젝트를 로드합니다.  
  44.         string included_path = "Assets/" + path;    
  45.         UnityEngine.Object obj = Resources.LoadAssetAtPath(included_path, typeof(UnityEngine.Object));    
  46.         if (obj == null)    
  47.         {    
  48.             Debug.LogError("Cannot find the resource. " + included_path);    
  49.             continue;    
  50.         }    
  51.   
  52.         // 생성!  
  53.         BuildPipeline.BuildAssetBundle(obj, null, output_path,    
  54.             BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,    
  55.             target);    
  56.     
  57.         Debug.Log("completed... : " + included_path);    
  58.     }    
  59. }    
파일 경로를 읽어온 뒤 개행 문자를 제거 해 주는것이 굉장히 중요합니다.
이것을 빼먹고 했더니 리소스 로딩이 실패나서 한참 고생했습니다.ㅠ_ㅠ

이렇게 만들어 놓고 플랫폼만 바꿔서 클릭 한번만 하면 되겠습니다.
끝~


Trackback 0 And Comment 0

[펌] 유니티엔진 - 유니티 스키닝 설정.

|

출처 : http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_Lecture&page=1&sn1=&divpage=1&sn=on&ss=on&sc=on&keyword=%C0%AF%B4%CF%C6%BC&select_arrange=last_comment&desc=desc&no=311



안녕하세요.


오늘 새로 추가되는 세트옷 덕분에 유니티 스키닝에 대해 알게 되었네요 -ㅅ-;

다들 fbx 를 임포트 해서 prefab으로 만들어서 모델 데이터를 쓰고 계실겁니다.

프리팹을 열면 Skinned Mesh Renderer 이 있는데. 거기 속성중에.

Quality 라는 속성이 있습니다. 기본은  Auto 로 잡혀 있고요.

이 속성이 스키닝 본 개수를 설정 할 수 있습니다. 

기본 Auto로 잡을경우 2개. 1bone, 2bone, 4bone 선택이 가능합니다. (유니티 3.5.6기준)

유니티는 스키닝 계산을 cpu 에서 처리 하니깐, 모바일에서 써도 크게 문제는 되지 않을거 같네요 (정확한 프로파일링을 아직 못해봤네요..)

다른 사람들은 저처럼 삽질 하지 마세요 ㅠ.ㅠ


Trackback 0 And Comment 0