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;
    }
}


์‹ฑ๊ธ€ํ†ค์˜ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๊ตฌ์กฐ์ด๊ณ  ์ด๋ฅผ ์‘์šฉํ•˜์—ฌ ์ƒ์‚ฐ์„ฑ์„ ๋†’์ด๋Š” ๋ฐฉ๋ฒ•์€ ๋๋„์—†์ด ์กด์žฌํ•œ๋‹ค๋Š” ^^