2013년 11월 28일 목요일

Texture Packer in Unity_Step4. Texture Packer Helper제어를 통한 Sprite Texture 구현


1. Step3에서 만들어놓은 Test Plane에다가 아래의 Script를 추가


Sprite.cs
using UnityEngine;
using System.Collections;

public enum SpriteType {
    Once,
    Loop,
}

public class Sprite : MonoBehaviour {
    
    public SpriteType _Type;
    public string _TextureName; // texture Name
    public int _MaxFrame; // Texture Frame Length
    public float _Dealay; // Sprite play Dealay 
    
    private TPHelper _TPH;
    private int _NowFrame; // now frame Num
    void Awake() {
        _TPH = GetComponent<TPHelper>();
    }
    
    // Use this for initialization
    void Start () {
        _NowFrame = 1;
        StartCoroutine(PlaySprite());
    }
    
    // Update is called once per frame
    void Update () {
    
    }
    
    IEnumerator PlaySprite() { //is Recursion Function
        _NowFrame++;
        yield return new WaitForSeconds(_Dealay);
        _TPH.OnTextureChange(_TextureName + _NowFrame.ToString()); 
        
        if(_NowFrame == _MaxFrame && _Type == SpriteType.Loop) _NowFrame = 0;
        if(_NowFrame == _MaxFrame && _Type == SpriteType.Once) yield return null;
        if(_NowFrame != _MaxFrame) { 
            StartCoroutine(PlaySprite()); 
        }
    }
}




2. Inspector창에서 Property값 변경 





3. Play 후 확인.

ps. 가장 최대한 이해하기 쉽게끔 작성한 코드라서 난이도 측면에서는 아주 쉬우실듯.
이런식으로 TPHelper 컴포넌트에 접근하여서 Texture 수정 , Atlas변경을 할수있으니 
입맛대로 코딩하셔서 사용하시면됩니다 ^ㅡ^

Texture Packer in Unity_Step3. Unity내에 Atlas 불러오기온 뒤 Texture Plane생성하기


pre. Custom Plane Mesh를 사용하지않고 TexturePacker 자체에서 Sprite Object를 생성해주는 기능이 있긴하지만.. 스크립트상에서 접근하여 다루기가 불편하여 이런식으로 작업을 진행하였습니다. ㅎㅎ Custom Plane? -> 링크

 1.이전 Step에서 만들어논 Atlas이미지를 Unity Asset/Resources폴더에 위치시킨다.
 (* .txt파일포함)


2.Texture Import Setting값 조정

3. .txt파일 이름 수정 Test_data -> 생성된 Atlas material 확인  


4. 게임에 사용할 Custom Plane 생성(X,Y축 사용시 Vertical로 생성)



5.생성된 Plane에 TPMesh Texture Ex 컴포넌트 추가



6.자동으로 Add되는 TPHelper 속성에 Atlas를 Test로 선택.


7.End

(texture속성을 봐꿔가면서 확인해보시길^^)


2013년 11월 25일 월요일

Texture Packer in Unity_Step2. Texture Packer를 활용한 Texture Atlas 생성하기.


 1. Texture Packer 실행

 2. Atlas를 만들 대상이 되는 Image파일들 Drag & Drop


3. TextureSettings Option 조절


Force Squared - Check
[ Atlas Texture 정사각형 이미지로 제작 ]
Algorithm - Basic 
[ Max Rect는 Full Version Only라고 되어있더군요...
근데 Max Rect mode로 진행해도 이상이 없는? ]

Trim mode - 2D texture : Trim 
                   3D texture : None

Allow Rotation -  Check 해제
[ Allow Rotation 또한 Full version only... ^^ ]
Border , Shape Padding - 1

그외에 옵션들도 궁금하시면 조금씩 수정해보면서 확인해보시면 됩니다.


4. Publish (ctrl + P)
 - 만들어진 Atlas 이미지 확인


Texture Packer in Unity_Step1. 준비물



 Unity내에서 Texture Packer를 활용하여 이미지 처리를 진행할경우 필요한 것들.

1. Texture Packer - 다운로드

2. Asset Store -> Texture packer Asset 다운로드 ( 저는 Free 버전을 사용하여 진행 )





좋은 글_ 모든 것은 지나간다.




모든 것은 지나간다. 
일출의 장엄함이 아침 내내 계속 되진 않으며
비가 영원히 내리지도 않는다.
모든 것은 지나간다.
일몰의 아름다움이 한밤중까지 이어지지도 않는다.
하지만 땅과 하늘과 천둥.
바람과 불
호수와 산과 물
이런 것들은 언제나 존재한다.
만일 그것들마저 사라진다면
인간의 꿈이 계속 될 수 있을까
인간의 환상이
당신이 살아 있는 동안
당신에게 일어나는 일들을 받아들이라.
모든 것은 지나가 버린다.

-세실 프란시스 알렉산더


2013년 11월 22일 금요일

[Texture Packer in Unity] Update 예정


Update 예정

texture packer를 활용한

Unity에서 sprite , animation 등으로 활용하는법

Unity_UCLA Mesh Creator를 이용한 2D mesh collider 만들기



1. UCLA Mesh Create Asset 다운로드.

 Asset Store 접속 -> "UCLA" 검색 -> Project에 Import



2. 빈 GameObject 생성 Create->Empty Object

3. Add Component -> Mesh Creator data





4. Mesh Creator Data Property Setting

2D용 Collider 제작시 적합하게 Property Setting[사진참조] -> "Update Mesh" 버튼 클릭

[Propertys]

Mesh Outline Texture : Mesh 생성 대상이될 Texture

Pixel Threshold : 픽셀 임계값 설정 [ 설정한 임계값 단위로 Mesh 생성 ]

Create full mesh for edge : Texture의 모서리에 해당하는부분의 Mesh 따로 생성

Auto Generate Material : Mesh Outline Texture 에 해당하는 Material 자동생성

그외에는 머 그냥 딱보셔도 이해할만한 속성들 ^^


5. End





기존의 2D mesh Generator용 Plugin들이 존재하긴 하나 UCLA툴은 무료! 이기에.. ^^
스크립트를 개발하시는 게임에 맞게끔 수정해서 쓰셔도 무방할듯 합니다.







Unity_PlayerPref 에 Class , Sturct형 Data 저장하기

 이번에 게임 제작진행중 Setting값을 PlayerPref를 활용해 저장할 방법을 궁리하던중 찾아낸방법.

// String<->Binary format 변환시 필요한 아이
using System.Runtime.Serialization.Formatters.Binary


//class property
private SettingInfo _setValue = new SettingInfo();

//PlayerPref에 저장할 Struct SettingInfo

[Serializable]
public struct SettingInfo{
    public bool Vibration;
    public bool Sound;
    public int Volume;
    public bool BGM;
}




// is Save
public void Save() {
        var b = new BinaryFormatter();
        var m = new MemoryStream();
        b.Serialize(m , _setValue);
        PlayerPrefs.SetString("Setting",Convert.ToBase64String(m.GetBuffer()))
    }


// is load
public void Load() {
        var data = PlayerPrefs.GetString("Setting");
        if(!string.IsNullOrEmpty(data)) {
            var b = new BinaryFormatter();
            var m = new MemoryStream(Convert.FromBase64String(data));
            _setValue = (SettingInfo) b.Deserialize(m);
                        
        } else {
                 // load data is empty
        }
    }

2013년 11월 21일 목요일

Unity_ Generic Singletone 사용법


*.아래글에 코드가 잘안보여서 다시올립니다 ^^;

Generic Singleton 사용법에 대해서는 수많은.. 정말 무수히 많은 방법론이 존재하지만 제가생각하기에 Unity상에서 사용하기 괜찮은(좋은방법있으면 알려주시길 ㅠㅠ) 코드이다.

Singleton.cs
using UnityEngine;
using System.Collections;

public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
    protected static T sInstance;

    public static T GetInstance
    {
        get
        {
            if (sInstance == null)
            {
                sInstance = (T)FindObjectOfType(typeof(T));
            }

            if (sInstance == null)
            {
                Create();
            }

            return sInstance;
        }
    }

    private static void Create()
    {
        if (GameObject.Find("_Singleton"))
        {
            GameObject goInst = GameObject.Find("_Singleton");
            sInstance = goInst.AddComponent<T>();
        }
        else
        {
            GameObject goInst = new GameObject("_Singleton");
            sInstance = goInst.AddComponent<T>();
        }
    }
}


how to used
public class SettingManager : Singleton<Settingmanager> {

    private void OnApplicationQuit() {
        sInstance = null;
    }
}


싱글톤의 가장 기본적인 구조이고 이를 응용하여 생산성을 높이는 방법은 끝도없이 존재한다는 ^^